60 lines
3.7 KiB
JavaScript
60 lines
3.7 KiB
JavaScript
|
|
const { test } = require('node:test')
|
||
|
|
const assert = require('node:assert/strict')
|
||
|
|
const { expectedReadRejection, selectUsableFixture } = require('./api-contract-audit.cjs')
|
||
|
|
const rejected = message => ({ status: 200, code: 500, message })
|
||
|
|
|
||
|
|
test('usable fixtures are selected by business state, not list position', () => {
|
||
|
|
const tasks = [{ id: 1, status: 'SETTLED' }, { id: 2, status: 'OPEN' }]
|
||
|
|
assert.equal(selectUsableFixture(tasks, row => row.status === 'OPEN').id, 2)
|
||
|
|
assert.equal(selectUsableFixture(tasks, row => row.status === 'CANCELLED'), undefined)
|
||
|
|
assert.equal(selectUsableFixture(tasks, row => row.status === 'CANCELLED', true).id, 1)
|
||
|
|
const out = [{ id: 3, costEventId: null }, { id: 4, costEventId: 8 }]
|
||
|
|
assert.equal(selectUsableFixture(out, row => row.costEventId, true).id, 4)
|
||
|
|
})
|
||
|
|
|
||
|
|
test('only exact missing-ID unbatched rejection is accepted without fixture', () => {
|
||
|
|
const p = '/warehouse/purchase/sheet/unbatched'
|
||
|
|
const result = rejected('明细已组批或已删除,请刷新列表')
|
||
|
|
assert.ok(expectedReadRejection(p, result, {}))
|
||
|
|
assert.equal(expectedReadRejection(p, result, { unbatched: { id: 1 } }), undefined)
|
||
|
|
assert.equal(expectedReadRejection(p, rejected('其他业务错误'), {}), undefined)
|
||
|
|
})
|
||
|
|
|
||
|
|
test('settled-task and arbitrary shortage errors can no longer be hidden', () => {
|
||
|
|
const p = '/production/tasks/shortages'
|
||
|
|
assert.equal(expectedReadRejection(p, rejected('已结算任务请先恢复生产'), {}), undefined)
|
||
|
|
assert.ok(expectedReadRejection(p, rejected('生产任务不存在'), {}))
|
||
|
|
assert.equal(expectedReadRejection(p, rejected('生产任务不存在'), { openTask: { id: 2 } }), undefined)
|
||
|
|
})
|
||
|
|
|
||
|
|
test('code zero is never accepted as a generator missing-fixture check', () => {
|
||
|
|
const p = '/tool/gen/column/{tableId}'
|
||
|
|
assert.equal(expectedReadRejection(p, { status: 200, code: 0 }, {}), undefined)
|
||
|
|
const result = rejected('生成配置不存在或已删除,请返回列表刷新')
|
||
|
|
assert.ok(expectedReadRejection(p, result, {}))
|
||
|
|
assert.equal(expectedReadRejection(p, result, { gen: { tableId: 5 } }), undefined)
|
||
|
|
})
|
||
|
|
|
||
|
|
test('legacy out-record protection requires actual evidence of missing cost chain', () => {
|
||
|
|
const p = '/warehouse/out/{id}/returns'
|
||
|
|
const result = rejected('该历史出库未补录成本链,不能自动撤销或退料;现有库存已作为期初保留')
|
||
|
|
assert.ok(expectedReadRejection(p, result, { out: { id: 1, costEventId: null } }))
|
||
|
|
assert.equal(expectedReadRejection(p, result, { out: { id: 2, costEventId: 3 } }), undefined)
|
||
|
|
assert.equal(expectedReadRejection(p, result, {}), undefined)
|
||
|
|
})
|
||
|
|
|
||
|
|
test('server errors and unsupported routes are never categorized as missing fixtures', () => {
|
||
|
|
const p = '/warehouse/purchase/sheet/unbatched'
|
||
|
|
assert.equal(expectedReadRejection(p, { status: 500, code: 500, message: '明细已组批或已删除,请刷新列表' }, {}), undefined)
|
||
|
|
assert.equal(expectedReadRejection(p, rejected('SQLSyntaxErrorException'), {}), undefined)
|
||
|
|
assert.equal(expectedReadRejection('/unknown/{id}', rejected('不存在'), {}), undefined)
|
||
|
|
assert.equal(expectedReadRejection(p, { status: 200, code: 403, message: '明细已组批或已删除,请刷新列表' }, {}), undefined)
|
||
|
|
})
|
||
|
|
|
||
|
|
test('loans and pending groups only accept their exact empty-fixture rejection', () => {
|
||
|
|
assert.ok(expectedReadRejection('/project/loans/{id}/returns', rejected('借用记录不存在'), {}))
|
||
|
|
assert.equal(expectedReadRejection('/project/loans/{id}/returns', rejected('借用记录不存在'), { loan: { id: 1 } }), undefined)
|
||
|
|
assert.ok(expectedReadRejection('/warehouse/in/pending-groups/{key}', rejected('来源编号无效'), {}))
|
||
|
|
assert.equal(expectedReadRejection('/warehouse/in/pending-groups/{key}', rejected('来源编号无效'), { pending: { key: 'B:1' } }), undefined)
|
||
|
|
})
|