53 lines
2.4 KiB
TypeScript
53 lines
2.4 KiB
TypeScript
import assert from 'node:assert/strict'
|
|
import { readFileSync } from 'node:fs'
|
|
import test from 'node:test'
|
|
|
|
const migration = readFileSync(
|
|
new URL('../../db/migrations/137_fulfillment_item_state_view.sql', import.meta.url),
|
|
'utf8',
|
|
)
|
|
const channelAssign = readFileSync(new URL('./channel-assign-service.ts', import.meta.url), 'utf8')
|
|
const auditScript = readFileSync(
|
|
new URL('../../../scripts/audit-fulfillment-state.ts', import.meta.url),
|
|
'utf8',
|
|
)
|
|
|
|
test('履约读模型按订单项拆分渠道、载体、尝试、异常和锁定原因', () => {
|
|
assert.ok(migration.includes('CREATE OR REPLACE VIEW v_fulfillment_item_state'))
|
|
assert.ok(migration.includes('current_attempt_id'))
|
|
assert.ok(migration.includes('carrier_status'))
|
|
assert.ok(migration.includes('issue_code'))
|
|
assert.ok(migration.includes("'after_sales'"))
|
|
assert.ok(migration.includes("'manual_review'"))
|
|
assert.ok(migration.includes("fulfillment_status IN ('pending', 'assigned')"))
|
|
})
|
|
|
|
test('待分类查询使用统一读模型并返回异常数量', () => {
|
|
assert.ok(channelAssign.includes('FROM v_fulfillment_item_state v'))
|
|
assert.ok(channelAssign.includes('issue_breakdown'))
|
|
assert.ok(channelAssign.includes('retryable_unlocked_item_count'))
|
|
assert.ok(channelAssign.includes('auto_retryable_unlocked_item_count'))
|
|
assert.ok(channelAssign.includes('PENDING_ISSUE_CATEGORIES'))
|
|
assert.ok(channelAssign.includes('issueCategoryInput'))
|
|
})
|
|
|
|
test('重试必须按可重试 issueCode 限定,不能按整个 SKU 处理售后和复核项', () => {
|
|
assert.ok(channelAssign.includes('RETRYABLE_CARRIER_ISSUES'))
|
|
assert.ok(channelAssign.includes('issueCodes?: string[]'))
|
|
assert.ok(channelAssign.includes('oi.issue_code = ANY($2::text[])'))
|
|
})
|
|
|
|
test('保存渠道、解除锁定、归档和重试都按当前问题分类限定作用域', () => {
|
|
assert.ok(channelAssign.includes('issueCategory?: string'))
|
|
assert.ok(channelAssign.includes('state.issue_category = $'))
|
|
assert.ok(channelAssign.includes('issueCodes?: string[]'))
|
|
assert.ok(channelAssign.includes('orderItemIds?: number[]'))
|
|
})
|
|
|
|
test('履约审计脚本覆盖状态不一致、售后队列和重复尝试', () => {
|
|
assert.ok(auditScript.includes('已分配但无有效载体'))
|
|
assert.ok(auditScript.includes('售后关闭仍进入履约队列'))
|
|
assert.ok(auditScript.includes('近 24 小时重复尝试订单项'))
|
|
assert.ok(auditScript.includes('--strict'))
|
|
})
|