test(search): add sender name FTS coverage and combined filter test
Some checks failed
CI / Unit & Component Tests (push) Failing after 3s
CI / Backend Unit Tests (push) Failing after 2s
CI / Unit & Component Tests (pull_request) Failing after 1s
CI / Backend Unit Tests (pull_request) Failing after 0s

- should_find_document_by_sender_name — symmetric with existing receiver test
- fts_combined_with_status_filter_excludes_non_matching_status — verifies
  hasIds(rankedIds).and(hasStatus(...)) two-phase search works together

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-04-15 11:03:37 +02:00
parent 5affe21b79
commit 13955a5459

View File

@@ -16,12 +16,16 @@ import org.springframework.boot.data.jpa.test.autoconfigure.DataJpaTest;
import org.springframework.boot.jdbc.test.autoconfigure.AutoConfigureTestDatabase;
import org.springframework.context.annotation.Import;
import org.springframework.data.jpa.domain.Specification;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatNoException;
import static org.raddatz.familienarchiv.repository.DocumentSpecifications.hasIds;
import static org.raddatz.familienarchiv.repository.DocumentSpecifications.hasStatus;
@DataJpaTest
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@@ -193,6 +197,24 @@ class DocumentFtsTest {
assertThat(ids).contains(doc.getId());
}
@Test
void should_find_document_by_sender_name() {
Person sender = personRepository.saveAndFlush(
Person.builder().firstName("Walter").lastName("Raddatz").build());
Document doc = documentRepository.saveAndFlush(Document.builder()
.title("Brief")
.originalFilename("brief.pdf")
.status(DocumentStatus.UPLOADED)
.sender(sender)
.build());
em.flush();
em.clear();
List<UUID> ids = documentRepository.findRankedIdsByFts("Raddatz");
assertThat(ids).contains(doc.getId());
}
// ─── Weight D: tag names ───────────────────────────────────────────────────
@Test
@@ -212,6 +234,29 @@ class DocumentFtsTest {
assertThat(ids).hasSize(1);
}
// ─── Combined FTS + Specification filter ──────────────────────────────────
@Test
void fts_combined_with_status_filter_excludes_non_matching_status() {
documentRepository.saveAndFlush(document("Grundbuch")); // UPLOADED
documentRepository.saveAndFlush(Document.builder()
.title("Grundbuch")
.originalFilename("grundbuch_ph.pdf")
.status(DocumentStatus.PLACEHOLDER)
.build());
em.flush();
em.clear();
List<UUID> rankedIds = documentRepository.findRankedIdsByFts("Grundbuch");
Specification<Document> spec = Specification.where(hasIds(rankedIds))
.and(hasStatus(DocumentStatus.UPLOADED));
List<Document> result = documentRepository.findAll(spec);
assertThat(result).hasSize(1);
assertThat(result.get(0).getStatus()).isEqualTo(DocumentStatus.UPLOADED);
}
// ─── Helpers ───────────────────────────────────────────────────────────────
private Document document(String title) {