Friendly app-level validation for a RANGE with end-before-start (#678) #706
@@ -256,6 +256,63 @@ class DocumentServiceTest {
|
||||
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 ───────────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user