Tickets: Zeit-Spalte (Bloecke, 3 parallel, 200 Zeilen), Ticket-Suche per woid oder ID, Anfrage-Zaehler
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9fec381056
commit
0b53fc825a
6 files changed
+201
No files matched your search
@@ -0,0 +1,27 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { loadModule } from './load.mjs'
|
||||
|
||||
const { lookupWorkorder } = await loadModule('src/lib/workorderLookup.js')
|
||||
const fake = ({ byWoid = null, byId, byIdError } = {}) => {
|
||||
const calls = []
|
||||
return { calls, findByWoid: async (w) => { calls.push(['woid', w]); return byWoid }, getById: async (id) => { calls.push(['id', id]); if (byIdError) throw byIdError; return byId } }
|
||||
}
|
||||
test('erst woid, dann $id', async () => {
|
||||
let d = fake({ byWoid: { $id: 'a', woid: '5' } })
|
||||
assert.deepEqual(await lookupWorkorder(' 5 ', d), { status: 'ok', ticket: { $id: 'a', woid: '5' } })
|
||||
assert.deepEqual(d.calls, [['woid', '5']])
|
||||
d = fake({ byId: { $id: 'abc' } })
|
||||
assert.deepEqual(await lookupWorkorder('abc', d), { status: 'ok', ticket: { $id: 'abc' } })
|
||||
assert.deepEqual(d.calls, [['woid', 'abc'], ['id', 'abc']])
|
||||
})
|
||||
test('400 und 404 sind nicht gefunden, leeres ref ohne Abfrage', async () => {
|
||||
for (const code of [400, 404]) assert.deepEqual(await lookupWorkorder('x', fake({ byIdError: { code } })), { status: 'notfound' })
|
||||
const d = fake()
|
||||
for (const empty of ['', ' ', null, undefined]) assert.deepEqual(await lookupWorkorder(empty, d), { status: 'notfound' })
|
||||
assert.deepEqual(d.calls, [])
|
||||
})
|
||||
test('andere Fehler werden weitergereicht', async () => {
|
||||
await assert.rejects(lookupWorkorder('x', fake({ byIdError: { code: 500, message: 'boom' } })))
|
||||
await assert.rejects(lookupWorkorder('x', { findByWoid: async () => { throw new Error('netz') }, getById: async () => ({}) }), /netz/)
|
||||
})
|
||||
Reference in new issue
Block a user