Skip to content

Commit f8038c5

Browse files
committed
PTBAS-741: Implement test on duplicate entry bug
1 parent 1f7505f commit f8038c5

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/test/java/de/doubleslash/keeptime/controller/HeimatControllerTest.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,4 +535,45 @@ void shouldReturnErrorsWhenErrorsOccurred() {
535535
}
536536
// shouldOnlyUpdateHeimatWhenSomethingHasChanged (not needed - user should decide)
537537

538+
@Test
539+
void shouldNotCreateDuplicateHeimatEntryWhenMultipleProjectsMappedAndSomeHaveWork() {
540+
// ARRANGE
541+
// project 1 has work, project 2 does not
542+
final Work work1 = new Work(now.minusMinutes(10), now, workProject1, "Notes 1");
543+
workItems.add(work1);
544+
545+
externalMappings.add(project1To1Mapping);
546+
externalMappings.add(project2To1Mapping);
547+
548+
// The mapped Heimat task has already been booked in Heimat
549+
final HeimatTime existingTime = new HeimatTime(project1To1Mapping.getExternalTaskId(), now.toLocalDate(), null,
550+
null, 15, "Heimat note", 99);
551+
when(mockedHeimatAPI.getMyTimes(now.toLocalDate())).thenReturn(Arrays.asList(existingTime));
552+
553+
// ACT
554+
final List<HeimatController.Mapping> tableRows = heimatController.getTableRows(now.toLocalDate(), workItems);
555+
556+
// ASSERT
557+
// There should be exactly one row for this Heimat task
558+
assertThat(tableRows.size(), Matchers.is(1));
559+
final HeimatController.Mapping mapping = tableRows.get(0);
560+
561+
// The mapping should combine both projects in .projects()
562+
assertThat(mapping.projects(), Matchers.containsInAnyOrder(workProject1, workProject2));
563+
564+
// The mapping should show KeepTime time for workProject1, and 0 for workProject2 (which is included in .projects() but has no time)
565+
assertThat(mapping.keeptimeSeconds(), Matchers.is(10 * 60L));
566+
assertThat(mapping.keeptimeNotes(), Matchers.is("Notes 1"));
567+
568+
// There should be Heimat time and notes as well
569+
assertThat(mapping.heimatNotes(), Matchers.is("Heimat note"));
570+
assertThat(mapping.heimatSeconds(), Matchers.is(15 * 60L));
571+
572+
String syncMessage = mapping.syncMessage().getChildren().stream()
573+
.filter(n -> n instanceof Text)
574+
.map(n -> ((Text) n).getText())
575+
.collect(Collectors.joining());
576+
assertThat(syncMessage, Matchers.not(Matchers.containsString("Present in HEIMAT but not KeepTime")));
577+
assertThat(syncMessage, Matchers.containsString(project1To1Mapping.getExternalTaskName()));
578+
}
538579
}

0 commit comments

Comments
 (0)