fix(document): fix test regressions from DocumentListItem migration
All checks were successful
CI / Unit & Component Tests (pull_request) Successful in 3m32s
CI / OCR Service Tests (pull_request) Successful in 20s
CI / Backend Unit Tests (pull_request) Successful in 3m46s
CI / fail2ban Regex (pull_request) Successful in 42s
CI / Semgrep Security Scan (pull_request) Successful in 19s
CI / Compose Bucket Idempotency (pull_request) Successful in 1m0s

- Use documentService.getDocumentById() in detail_stillReturnsTrainingLabels
  so the Document.full entity graph eager-loads trainingLabels
- Flatten makeItem() factory in DocumentList.svelte.test.ts (nested
  document: {} overrides broke item.id / item.documentDate access)
- Remove { document: {} } wrapper from DocumentMultiSelect.svelte.spec.ts
  mock responses — component now reads body.items directly as flat items
- Flatten single nested item in page.svelte.test.ts document list test

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-05-22 19:14:44 +02:00
parent 6583226d79
commit 627fc44d99
4 changed files with 67 additions and 38 deletions

View File

@@ -90,8 +90,8 @@ class DocumentListItemIntegrationTest {
.trainingLabels(new HashSet<>(Set.of(TrainingLabel.KURRENT_RECOGNITION))) .trainingLabels(new HashSet<>(Set.of(TrainingLabel.KURRENT_RECOGNITION)))
.build()); .build());
// Document.full entity graph (used by findById) must still load trainingLabels // Document.full entity graph (used by getDocumentById) must still load trainingLabels
Document loaded = documentRepository.findById(saved.getId()).orElseThrow(); Document loaded = documentService.getDocumentById(saved.getId());
assertThat(loaded.getTrainingLabels()).containsExactly(TrainingLabel.KURRENT_RECOGNITION); assertThat(loaded.getTrainingLabels()).containsExactly(TrainingLabel.KURRENT_RECOGNITION);
} }

View File

@@ -22,7 +22,7 @@ function mockSearchResponse(items: ReturnType<typeof docFactory>[]) {
'fetch', 'fetch',
vi.fn().mockResolvedValue({ vi.fn().mockResolvedValue({
ok: true, ok: true,
json: vi.fn().mockResolvedValue({ items: items.map((document) => ({ document })) }) json: vi.fn().mockResolvedValue({ items })
}) })
); );
} }
@@ -91,10 +91,7 @@ describe('DocumentMultiSelect — search and select', () => {
const fetchMock = vi.fn().mockResolvedValue({ const fetchMock = vi.fn().mockResolvedValue({
ok: true, ok: true,
json: vi.fn().mockResolvedValue({ json: vi.fn().mockResolvedValue({
items: [ items: [docFactory('d1', 'Already attached'), docFactory('d2', 'Not attached')]
{ document: docFactory('d1', 'Already attached') },
{ document: docFactory('d2', 'Not attached') }
]
}) })
}); });
vi.stubGlobal('fetch', fetchMock); vi.stubGlobal('fetch', fetchMock);

View File

@@ -20,29 +20,46 @@ const { default: DocumentList } = await import('./DocumentList.svelte');
afterEach(cleanup); afterEach(cleanup);
const sender = { id: 's1', displayName: 'Anna Schmidt' }; const sender = {
const receiver = { id: 'r1', displayName: 'Bert Meier' }; id: 's1',
lastName: 'Schmidt',
displayName: 'Anna Schmidt',
personType: 'PERSON' as const,
familyMember: false
};
const receiver = {
id: 'r1',
lastName: 'Meier',
displayName: 'Bert Meier',
personType: 'PERSON' as const,
familyMember: false
};
const emptyMatchData = {
titleOffsets: [],
senderMatched: false,
matchedReceiverIds: [],
matchedTagIds: [],
snippetOffsets: [],
summaryOffsets: []
};
const makeItem = (overrides: Record<string, unknown> = {}) => ({ const makeItem = (overrides: Record<string, unknown> = {}) => ({
document: { id: 'd1',
id: 'd1', title: 'Brief 1923',
title: 'Brief 1923', originalFilename: 'b.pdf',
originalFilename: 'b.pdf', documentDate: '1923-04-15',
documentDate: '1923-04-15', sender,
sender, receivers: [receiver],
receivers: [receiver], tags: [],
tags: [], summary: undefined,
thumbnailUrl: null, archiveBox: undefined,
contentType: 'application/pdf', archiveFolder: undefined,
summary: null, location: undefined,
archiveBox: null, matchData: emptyMatchData,
archiveFolder: null,
location: null,
...overrides
},
matchData: null,
completionPercentage: 0, completionPercentage: 0,
contributors: [] contributors: [],
...overrides
}); });
describe('DocumentList', () => { describe('DocumentList', () => {
@@ -87,8 +104,26 @@ describe('DocumentList', () => {
render(DocumentList, { render(DocumentList, {
props: { props: {
items: [ items: [
makeItem({ id: 'd1', sender: { id: 's1', displayName: 'Anna Schmidt' } }), makeItem({
makeItem({ id: 'd2', sender: { id: 's2', displayName: 'Bert Meier' } }) id: 'd1',
sender: {
id: 's1',
lastName: 'Schmidt',
displayName: 'Anna Schmidt',
personType: 'PERSON',
familyMember: false
}
}),
makeItem({
id: 'd2',
sender: {
id: 's2',
lastName: 'Meier',
displayName: 'Bert Meier',
personType: 'PERSON',
familyMember: false
}
})
], ],
canWrite: false, canWrite: false,
sort: 'SENDER' as const sort: 'SENDER' as const

View File

@@ -140,15 +140,12 @@ describe('documents/+ page', () => {
data: baseData({ data: baseData({
items: [ items: [
{ {
document: { id: 'd1',
id: 'd1', title: 'Brief 1899',
title: 'Brief 1899', documentDate: '1899-04-14',
status: 'TRANSCRIBED', originalFilename: 'b1.pdf',
documentDate: '1899-04-14', receivers: [],
summary: '', tags: [],
originalFilename: 'b1.pdf',
receivers: []
},
matchData: { matchData: {
titleOffsets: [], titleOffsets: [],
senderMatched: false, senderMatched: false,