test(bulk-upload): add unit tests for storeDocumentWithBatchMetadata
Some checks failed
CI / Unit & Component Tests (push) Failing after 1m10s
CI / OCR Service Tests (push) Successful in 32s
CI / Backend Unit Tests (push) Failing after 2m57s
CI / Unit & Component Tests (pull_request) Failing after 1m9s
CI / OCR Service Tests (pull_request) Successful in 39s
CI / Backend Unit Tests (pull_request) Failing after 3m3s
Some checks failed
CI / Unit & Component Tests (push) Failing after 1m10s
CI / OCR Service Tests (push) Successful in 32s
CI / Backend Unit Tests (push) Failing after 2m57s
CI / Unit & Component Tests (pull_request) Failing after 1m9s
CI / OCR Service Tests (pull_request) Successful in 39s
CI / Backend Unit Tests (pull_request) Failing after 3m3s
Covers four behaviours of applyBatchMetadata that had no coverage: title applied by list index, sender resolved via PersonService, tags applied via updateDocumentTags, and title left unchanged when the fileIndex exceeds the titles list length. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1814,6 +1814,85 @@ class DocumentServiceTest {
|
|||||||
verify(auditService).logAfterCommit(eq(AuditKind.FILE_UPLOADED), isNull(), eq(id), isNull());
|
verify(auditService).logAfterCommit(eq(AuditKind.FILE_UPLOADED), isNull(), eq(id), isNull());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ─── storeDocumentWithBatchMetadata ──────────────────────────────────────
|
||||||
|
|
||||||
|
private MockMultipartFile pdfFile(String name) {
|
||||||
|
return new MockMultipartFile("file", name, "application/pdf", new byte[]{1});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void stubStoreDocument(String filename) throws Exception {
|
||||||
|
when(documentRepository.findFirstByOriginalFilename(filename)).thenReturn(Optional.empty());
|
||||||
|
when(fileService.uploadFile(any(), any())).thenReturn(new FileService.UploadResult("key", "hash"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void storeDocumentWithBatchMetadata_appliesTitleByIndex() throws Exception {
|
||||||
|
stubStoreDocument("scan01.pdf");
|
||||||
|
when(documentRepository.save(any())).thenAnswer(inv -> inv.getArgument(0));
|
||||||
|
|
||||||
|
org.raddatz.familienarchiv.dto.DocumentBatchMetadataDTO meta = new org.raddatz.familienarchiv.dto.DocumentBatchMetadataDTO();
|
||||||
|
meta.setTitles(List.of("Erster Brief", "Zweiter Brief"));
|
||||||
|
|
||||||
|
DocumentService.StoreResult result = documentService.storeDocumentWithBatchMetadata(pdfFile("scan01.pdf"), meta, 0, null);
|
||||||
|
|
||||||
|
assertThat(result.document().getTitle()).isEqualTo("Erster Brief");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void storeDocumentWithBatchMetadata_resolvesSenderViaPersonService() throws Exception {
|
||||||
|
UUID senderId = UUID.randomUUID();
|
||||||
|
stubStoreDocument("scan02.pdf");
|
||||||
|
when(documentRepository.save(any())).thenAnswer(inv -> inv.getArgument(0));
|
||||||
|
Person sender = Person.builder().id(senderId).firstName("Anna").build();
|
||||||
|
when(personService.getById(senderId)).thenReturn(sender);
|
||||||
|
|
||||||
|
org.raddatz.familienarchiv.dto.DocumentBatchMetadataDTO meta = new org.raddatz.familienarchiv.dto.DocumentBatchMetadataDTO();
|
||||||
|
meta.setSenderId(senderId);
|
||||||
|
|
||||||
|
DocumentService.StoreResult result = documentService.storeDocumentWithBatchMetadata(pdfFile("scan02.pdf"), meta, 0, null);
|
||||||
|
|
||||||
|
assertThat(result.document().getSender()).isEqualTo(sender);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void storeDocumentWithBatchMetadata_appliesTagsViaUpdateDocumentTags() throws Exception {
|
||||||
|
UUID docId = UUID.randomUUID();
|
||||||
|
when(documentRepository.findFirstByOriginalFilename("scan03.pdf")).thenReturn(Optional.empty());
|
||||||
|
when(fileService.uploadFile(any(), any())).thenReturn(new FileService.UploadResult("key", "hash"));
|
||||||
|
when(documentRepository.save(any())).thenAnswer(inv -> {
|
||||||
|
Document d = inv.getArgument(0);
|
||||||
|
if (d.getId() == null) d.setId(docId);
|
||||||
|
return d;
|
||||||
|
});
|
||||||
|
when(documentRepository.findById(docId)).thenAnswer(inv -> {
|
||||||
|
Document d = new Document();
|
||||||
|
d.setId(docId);
|
||||||
|
return Optional.of(d);
|
||||||
|
});
|
||||||
|
Tag tag = Tag.builder().id(UUID.randomUUID()).name("Familie").build();
|
||||||
|
when(tagService.findOrCreate("Familie")).thenReturn(tag);
|
||||||
|
|
||||||
|
org.raddatz.familienarchiv.dto.DocumentBatchMetadataDTO meta = new org.raddatz.familienarchiv.dto.DocumentBatchMetadataDTO();
|
||||||
|
meta.setTagNames(List.of("Familie"));
|
||||||
|
|
||||||
|
documentService.storeDocumentWithBatchMetadata(pdfFile("scan03.pdf"), meta, 0, null);
|
||||||
|
|
||||||
|
verify(tagService).findOrCreate("Familie");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void storeDocumentWithBatchMetadata_leavesTitle_whenIndexExceedsTitlesList() throws Exception {
|
||||||
|
stubStoreDocument("scan04.pdf");
|
||||||
|
when(documentRepository.save(any())).thenAnswer(inv -> inv.getArgument(0));
|
||||||
|
|
||||||
|
org.raddatz.familienarchiv.dto.DocumentBatchMetadataDTO meta = new org.raddatz.familienarchiv.dto.DocumentBatchMetadataDTO();
|
||||||
|
meta.setTitles(List.of("Only One Title"));
|
||||||
|
|
||||||
|
DocumentService.StoreResult result = documentService.storeDocumentWithBatchMetadata(pdfFile("scan04.pdf"), meta, 5, null);
|
||||||
|
|
||||||
|
assertThat(result.document().getTitle()).isEqualTo("scan04");
|
||||||
|
}
|
||||||
|
|
||||||
// ─── validateBatch ───────────────────────────────────────────────────────
|
// ─── validateBatch ───────────────────────────────────────────────────────
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user