diff --git a/backend/src/test/java/org/raddatz/familienarchiv/document/DocumentRepositoryTest.java b/backend/src/test/java/org/raddatz/familienarchiv/document/DocumentRepositoryTest.java index a805925b..05a69895 100644 --- a/backend/src/test/java/org/raddatz/familienarchiv/document/DocumentRepositoryTest.java +++ b/backend/src/test/java/org/raddatz/familienarchiv/document/DocumentRepositoryTest.java @@ -38,7 +38,10 @@ import java.util.Optional; import java.util.Set; import java.util.UUID; +import org.springframework.dao.DataIntegrityViolationException; + import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; @DataJpaTest @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) @@ -635,6 +638,25 @@ class DocumentRepositoryTest { assertThat(found.getMetaDatePrecision()).isEqualTo(DatePrecision.RANGE); } + @Test + void save_rejectsRange_whenEndBeforeStart_atDbLevel() { + // The app guard normally intercepts this, so the DB CHECK never fires in practice. + // Persisting directly proves chk_meta_date_end_after_start actually rejects end < start + // (H2 would not) — if the app guard ever regresses, a bad row still can't reach the table, + // and this is exactly the violation the GlobalExceptionHandler backstop turns into a 400. + Document doc = Document.builder() + .title("Verdrehte Spanne") + .originalFilename("verdreht.pdf") + .status(DocumentStatus.UPLOADED) + .documentDate(LocalDate.of(1917, 1, 11)) + .metaDatePrecision(DatePrecision.RANGE) + .metaDateEnd(LocalDate.of(1917, 1, 10)) + .build(); + + assertThatThrownBy(() -> documentRepository.saveAndFlush(doc)) + .isInstanceOf(DataIntegrityViolationException.class); + } + // ─── seeding helpers ───────────────────────────────────────────────────── private Document uploaded(String title) { diff --git a/backend/src/test/java/org/raddatz/familienarchiv/document/DocumentServiceTest.java b/backend/src/test/java/org/raddatz/familienarchiv/document/DocumentServiceTest.java index 4c11bd30..0ed058a8 100644 --- a/backend/src/test/java/org/raddatz/familienarchiv/document/DocumentServiceTest.java +++ b/backend/src/test/java/org/raddatz/familienarchiv/document/DocumentServiceTest.java @@ -283,6 +283,7 @@ class DocumentServiceTest { documentService.updateDocument(id, rangeDto(LocalDate.of(1917, 1, 10), LocalDate.of(1917, 1, 11)), null, null); + assertThat(doc.getMetaDateEnd()).isEqualTo(LocalDate.of(1917, 1, 11)); verify(documentRepository, atLeastOnce()).save(any()); }