r30-board.test.ts
TypeScript · 36 рядків
1// R-30.12: прототип борду-карти (scripts/r30/board.ts) — валідний і проходить сценарій TSD-07 на одному борді.
2import test, { after, before } from 'node:test'
3import assert from 'node:assert/strict'
4import { board, load, models, scenario } from '../scripts/r30/board.ts'
5import { stageHandoffs } from '../shared/stages.ts'
6import { validateWorkflow } from '../server/validation.ts'
7import { demoModels } from '../server/demo.ts'
8import { testServer } from './helpers.ts'
9
10test('the R30 board has no validation errors and shows hand-offs between its stages', () => {
11 const { issues } = validateWorkflow(board(), [...demoModels(), ...models()], [])
12 assert.deepEqual(issues.filter((i) => i.severity !== 'warning').map((i) => i.message), [])
13 assert.deepEqual(stageHandoffs(board()).map((h) => `${h.from || '—'}→${h.to}:${h.label}`).sort(),
14 ['—→pick:order', '—→place:place', 'pick→inventory:shelf', 'pick→pack:basket', 'place→pack:basket'].sort())
15})
16
17let t: Awaited<ReturnType<typeof testServer>>
18before(async () => { t = await testServer('r30board') })
19after(async () => { await t.stop() })
20
21test('one board: the same part code goes to picking, cross-dock, packing and inventory without interfering', async () => {
22 assert.deepEqual(await load(t.call), [])
23 for (const step of scenario) {
24 const r = await t.call('POST', '/api/events?responseMode=sync', step.event)
25 assert.ok(r.status === 200 || (!step.expect && r.status === 204), `${step.who} ${JSON.stringify(step.event)} → ${JSON.stringify(r.body)}`)
26 if (step.expect) assert.ok(String(r.body?.screen?.text).includes(step.expect), `${step.who}: «${r.body?.screen?.text}» ≠ «${step.expect}»`)
27 }
28 const tasks = (await t.sql.query<{ data: any }>(`SELECT data FROM workflow_tasks`)).map((r) => r.data)
29 const by = (stage: string, entityId: string) => tasks.find((x) => x.handlerStageId === stage && x.entityId === entityId)
30 assert.equal(by('pick', 'O-1').status, 'completed')
31 assert.equal(by('pack', 'K-7').status, 'completed')
32 assert.equal(by('pack', 'K-9').status, 'open')
33 assert.equal(by('place', 'P-5').status, 'open')
34 assert.equal(by('inventory', 'A-12-3').status, 'completed')
35})
36