test(document): lock in accepted RANGE cases — equal/after/open/null-start (#678)
Cover AC2 (end == start), AC3 (open-ended, end null) and AC4 (null start + end set, which must not reject or NPE), plus end-after-start. Guards the guard against future over-rejection that would diverge from the DB CHECK. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -256,6 +256,63 @@ class DocumentServiceTest {
|
|||||||
verify(documentRepository, never()).save(any());
|
verify(documentRepository, never()).save(any());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void updateDocument_acceptsRange_whenEndEqualsStart() throws Exception {
|
||||||
|
// AC2: the DB CHECK is end >= start, so equal dates are valid.
|
||||||
|
UUID id = UUID.randomUUID();
|
||||||
|
Document doc = docForRangeUpdate(id);
|
||||||
|
when(documentRepository.findById(id)).thenReturn(Optional.of(doc));
|
||||||
|
when(documentRepository.save(any())).thenReturn(doc);
|
||||||
|
|
||||||
|
LocalDate same = LocalDate.of(1917, 1, 10);
|
||||||
|
documentService.updateDocument(id, rangeDto(same, same), null, null);
|
||||||
|
|
||||||
|
assertThat(doc.getMetaDateEnd()).isEqualTo(same);
|
||||||
|
verify(documentRepository, atLeastOnce()).save(any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void updateDocument_acceptsRange_whenEndAfterStart() throws Exception {
|
||||||
|
UUID id = UUID.randomUUID();
|
||||||
|
Document doc = docForRangeUpdate(id);
|
||||||
|
when(documentRepository.findById(id)).thenReturn(Optional.of(doc));
|
||||||
|
when(documentRepository.save(any())).thenReturn(doc);
|
||||||
|
|
||||||
|
documentService.updateDocument(id,
|
||||||
|
rangeDto(LocalDate.of(1917, 1, 10), LocalDate.of(1917, 1, 11)), null, null);
|
||||||
|
|
||||||
|
verify(documentRepository, atLeastOnce()).save(any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void updateDocument_acceptsRange_whenEndIsNull_openEnded() throws Exception {
|
||||||
|
// AC3: an open-ended range (no end) is valid.
|
||||||
|
UUID id = UUID.randomUUID();
|
||||||
|
Document doc = docForRangeUpdate(id);
|
||||||
|
when(documentRepository.findById(id)).thenReturn(Optional.of(doc));
|
||||||
|
when(documentRepository.save(any())).thenReturn(doc);
|
||||||
|
|
||||||
|
documentService.updateDocument(id,
|
||||||
|
rangeDto(LocalDate.of(1917, 1, 10), null), null, null);
|
||||||
|
|
||||||
|
verify(documentRepository, atLeastOnce()).save(any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void updateDocument_acceptsRange_whenStartNullAndEndSet() throws Exception {
|
||||||
|
// AC4: mirrors the DB "meta_date IS NULL" escape — must NOT reject (and must not NPE).
|
||||||
|
UUID id = UUID.randomUUID();
|
||||||
|
Document doc = docForRangeUpdate(id);
|
||||||
|
when(documentRepository.findById(id)).thenReturn(Optional.of(doc));
|
||||||
|
when(documentRepository.save(any())).thenReturn(doc);
|
||||||
|
|
||||||
|
documentService.updateDocument(id,
|
||||||
|
rangeDto(null, LocalDate.of(1917, 1, 11)), null, null);
|
||||||
|
|
||||||
|
assertThat(doc.getMetaDateEnd()).isEqualTo(LocalDate.of(1917, 1, 11));
|
||||||
|
verify(documentRepository, atLeastOnce()).save(any());
|
||||||
|
}
|
||||||
|
|
||||||
// ─── deleteTagCascading ───────────────────────────────────────────────────
|
// ─── deleteTagCascading ───────────────────────────────────────────────────
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user