feat(document): replace DocumentSearchItem with flat DocumentListItem DTO (#647) #660

Merged
marcel merged 5 commits from feat/issue-647-document-list-dto into main 2026-05-23 19:35:44 +02:00
4 changed files with 67 additions and 38 deletions
Showing only changes of commit 627fc44d99 - Show all commits

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,11 +20,31 @@ 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',
@@ -32,17 +52,14 @@ const makeItem = (overrides: Record<string, unknown> = {}) => ({
sender, sender,
receivers: [receiver], receivers: [receiver],
tags: [], tags: [],
thumbnailUrl: null, summary: undefined,
contentType: 'application/pdf', archiveBox: undefined,
summary: null, archiveFolder: undefined,
archiveBox: null, location: undefined,
archiveFolder: null, matchData: emptyMatchData,
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',
status: 'TRANSCRIBED',
documentDate: '1899-04-14', documentDate: '1899-04-14',
summary: '',
originalFilename: 'b1.pdf', originalFilename: 'b1.pdf',
receivers: [] receivers: [],
}, tags: [],
matchData: { matchData: {
titleOffsets: [], titleOffsets: [],
senderMatched: false, senderMatched: false,