|
|
@@ -38,6 +38,73 @@ class ReSubmitApprovalServiceTest {
|
|
|
|
|
|
private static final String DEFAULT_MANAGER_ID = "634735129";
|
|
|
|
|
|
+ @Test
|
|
|
+ void shouldIgnoreHistoricalChangesWhenCollectingNormalHours() {
|
|
|
+ for (String category : new String[]{"billable", "nonBillable", "other"}) {
|
|
|
+ assertEquals(Collections.singletonList(8d), collectNormalHours(category, 8, 0, -24, 0));
|
|
|
+ assertEquals(Collections.singletonList(8d), collectNormalHours(category, 8, 0, 24, 0));
|
|
|
+ assertEquals(Collections.singletonList(8d), collectNormalHours(category, 8, 0, 0, 0));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void shouldNotResubmitApprovedOrEmptyHoursBecauseOfNegativeChanges() {
|
|
|
+ for (String category : new String[]{"billable", "nonBillable", "other"}) {
|
|
|
+ assertTrue(collectNormalHours(category, 8, 8, -24, 8).isEmpty());
|
|
|
+ assertTrue(collectNormalHours(category, 0, 0, -24, 0).isEmpty());
|
|
|
+ assertTrue(collectNormalHours(category, 4, 8, -24, 8).isEmpty());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void shouldCompareCompletedCoverageWithNormalApprovedHoursOnly() {
|
|
|
+ for (String category : new String[]{"billable", "nonBillable", "other"}) {
|
|
|
+ assertEquals(Collections.singletonList(8d), collectNormalHours(category, 16, 8, -24, 8));
|
|
|
+ assertTrue(collectNormalHours(category, 8, 0, 24, 8).isEmpty());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Double> collectNormalHours(String category, double submitted, double approved,
|
|
|
+ double change, double completedHours) {
|
|
|
+ String[] fields = "billable".equals(category)
|
|
|
+ ? new String[]{"tableField_mmczo634", "textField_mmacxew3", "numberField_mmczo636",
|
|
|
+ "numberField_mmczo637", "numberField_mmd80zae", "billableRows"}
|
|
|
+ : "nonBillable".equals(category)
|
|
|
+ ? new String[]{"tableField_mmczo63h", "textField_mmczo639", "numberField_mmczo63c",
|
|
|
+ "numberField_mmczo63d", "numberField_mmeakgi9", "nonBillableRows"}
|
|
|
+ : new String[]{"tableField_mmeakgid", "selectField_mmeakgie", "numberField_mmeakgij",
|
|
|
+ "numberField_mmeakgii", "numberField_mmeakgim", "otherRows"};
|
|
|
+ Map<String, Object> row = new HashMap<>();
|
|
|
+ row.put(fields[1], "P1");
|
|
|
+ row.put(fields[2], submitted);
|
|
|
+ row.put(fields[3], approved);
|
|
|
+ row.put(fields[4], change);
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
+ data.put("textField_mmbffvdb", "20260915");
|
|
|
+ data.put("dateField_mmbffvd8", 1789401600000L);
|
|
|
+ data.put(fields[0], Collections.singletonList(row));
|
|
|
+ ReSubmitApprovalService.ApprovalCoverage coverage = new ReSubmitApprovalService.ApprovalCoverage();
|
|
|
+ coverage.completedAgreeHours.put(ReSubmitApprovalService.approvalKey(
|
|
|
+ category, "user-1", "20260915",
|
|
|
+ ReSubmitApprovalService.approvalDetailKey("P1", "")), completedHours);
|
|
|
+ Map<String, String> managers = new HashMap<>();
|
|
|
+ managers.put("", "pm-active");
|
|
|
+ Object result = ReflectionTestUtils.invokeMethod(new ReSubmitApprovalService(),
|
|
|
+ "collectApprovalData", "user-1", "202609",
|
|
|
+ Collections.singletonList(Collections.singletonMap("formData", data)), coverage, managers);
|
|
|
+ List<?> rows;
|
|
|
+ if ("other".equals(category)) {
|
|
|
+ rows = (List<?>) ReflectionTestUtils.getField(result, fields[5]);
|
|
|
+ } else {
|
|
|
+ Map<?, ?> groups = (Map<?, ?>) ReflectionTestUtils.getField(result, "managerGroups");
|
|
|
+ if (groups.isEmpty()) return Collections.emptyList();
|
|
|
+ rows = (List<?>) ReflectionTestUtils.getField(groups.values().iterator().next(), fields[5]);
|
|
|
+ }
|
|
|
+ List<Double> hours = new ArrayList<>();
|
|
|
+ for (Object detail : rows) hours.add((Double) ReflectionTestUtils.getField(detail, "hours"));
|
|
|
+ return hours;
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
void shouldTreatBlankHistoricalOpinionAsCompletedApprovalCoverage() {
|
|
|
assertTrue(ReSubmitApprovalService.isCompletedApprovedRow("COMPLETED", "agree", ""));
|