feat(documents): file scanner inbox documents with folder and type
All checks were successful
Build and Release FEDEO / verify (push) Successful in 1m0s
Build and Release FEDEO / build-and-release (push) Successful in 5m56s

This commit is contained in:
2026-09-29 16:48:15 +02:00
parent 2192fa5bb4
commit 052a3a8446
9 changed files with 400 additions and 14 deletions

View File

@@ -90,3 +90,103 @@ test('unmounting cancels polling and ignores in-flight responses', async () => {
assert.equal(ui.run('documents.value.length'), 0)
assert.equal(ui.timers.size, 0)
})
const filingOptions = {
folders: [
{ id: 'parent', name: 'Buchhaltung', parent: null, standardFiletype: null, standardFiletypeIsOptional: true },
{ id: 'folder', name: 'Rechnungen', parent: 'parent', standardFiletype: 'invoice', standardFiletypeIsOptional: false },
],
types: [{ id: 'invoice', name: 'Rechnung' }, { id: 'other', name: 'Sonstiges' }],
}
test('filing shows folder paths, requires a type and honours mandatory folder defaults', async t => {
const ui = setup(async () => filingOptions)
t.after(ui.close)
await ui.run('openFiling({ id: "scan", name: "scan.pdf" })')
assert.equal(ui.run('canFile.value'), false)
assert.equal(ui.run('folderOptions.value.find(folder => folder.id === "folder").name'), 'Buchhaltung / Rechnungen')
ui.run('filingFolder.value = "folder"')
await settle()
assert.equal(ui.run('filingType.value'), 'invoice')
assert.equal(ui.run('fixedType.value'), true)
assert.equal(ui.run('canFile.value'), true)
ui.run('filingType.value = "other"')
assert.equal(ui.run('canFile.value'), false)
ui.run('filingFolder.value = "root"')
await settle()
assert.equal(ui.run('fixedType.value'), false)
assert.equal(ui.run('canFile.value'), true)
})
test('successful filing sends folder and type, removes the entry and returns from an empty last page', async t => {
const pendingSave = deferred()
const requests = []
const ui = setup((url, options) => {
requests.push({ url, options })
if (url.endsWith('/filing-options')) return Promise.resolve(filingOptions)
if (url.endsWith('/file')) return pendingSave.promise
return Promise.resolve({ documents: [{ id: 'remaining' }], total: 50 })
})
t.after(ui.close)
ui.run('documents.value = [{ id: "scan", name: "scan.pdf" }]; total.value = 51; page.value = 2')
await ui.run('openFiling(documents.value[0])')
ui.run('filingType.value = "invoice"')
const saving = ui.run('fileDocument()')
await ui.run('fileDocument()')
assert.equal(requests.filter(item => item.url.endsWith('/file')).length, 1)
assert.equal(ui.run('documents.value.length'), 1, 'keeps the original until saving succeeds')
pendingSave.resolve({ id: 'scan' })
await saving
const post = requests.find(item => item.url.endsWith('/file'))
assert.equal(post.url, '/api/document-inbox/scan/file')
assert.equal(post.options.body.folder, null)
assert.equal(post.options.body.type, 'invoice')
assert.equal(ui.run('filingOpen.value'), false)
assert.equal(ui.run('page.value'), 1)
assert.equal(requests.at(-1).options.query.offset, 0)
assert.equal(ui.run('documents.value[0].id'), 'remaining')
})
test('filing failure preserves the document and selected values for retry', async t => {
const ui = setup(async url => {
if (url.endsWith('/file')) throw { data: { message: 'Ordner nicht verfügbar' } }
return filingOptions
})
t.after(ui.close)
ui.run('documents.value = [{ id: "scan", name: "scan.pdf" }]; total.value = 1')
await ui.run('openFiling(documents.value[0])')
ui.run('filingFolder.value = "folder"')
await settle()
await ui.run('fileDocument()')
assert.equal(ui.run('filingError.value'), 'Ordner nicht verfügbar')
assert.equal(ui.run('filingOpen.value'), true)
assert.equal(ui.run('filingType.value'), 'invoice')
assert.equal(ui.run('documents.value[0].id'), 'scan')
assert.equal(ui.run('canFile.value'), true)
})
test('tenant switching discards pending folder options and filing responses', async t => {
for (const stage of ['options', 'save']) {
const pending = deferred()
const ui = setup(url => {
if (url.endsWith('/filing-options')) return stage === 'options' ? pending.promise : Promise.resolve(filingOptions)
if (url.endsWith('/file')) return pending.promise
return Promise.resolve({ documents: [{ id: 'tenant-2' }], total: 1 })
})
t.after(ui.close)
let operation = ui.run('openFiling({ id: "scan", name: "scan.pdf" })')
if (stage === 'save') {
await operation
ui.run('filingType.value = "invoice"')
operation = ui.run('fileDocument()')
}
ui.auth.activeTenant = '2'
await settle()
pending.resolve(stage === 'options' ? filingOptions : { id: 'scan' })
await operation
assert.equal(ui.run('filingOpen.value'), false)
assert.equal(ui.run('filingFolders.value.length'), 0)
assert.equal(ui.run('filingTypes.value.length'), 0)
assert.equal(ui.run('documents.value[0].id'), 'tenant-2')
}
})