Files
ssw-mvp/docs/e2e/cases/TC-DELIVERY_API-004.mjs
T
admin 3247e9fd15 init: ssw-mvp initial commit
- boot/ (Java/Maven, JNPF 7.0) — 移除旧的 boot/.git,源码直接纳入仓库
- web/ (Vue 3 + Vite + Ant Design Vue, pnpm)
- docs/, scard/, nax/
- refs/INDEX.md + refs/国标/(其余 refs/* 开源子仓库不纳入)
- 已忽略: connector_data/, jweb/, log/, web/{dist,node_modules,.pnpm}, boot/*/target/, .DS_Store, .idea, .vscode
2026-08-05 18:29:12 +08:00

73 lines
3.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* TC-DELIVERY_API-004 · 重复办理数据传输时不会重复处理
* REQ-066 数据传输 / FL 12.2 反向/状态迁移 P1
*
* 前置:已存在一条可以办理的数据传输记录。
* 步骤:1. 正常办理一次数据传输
* 2. 再次提交相同操作
* 3. 查看状态、列表和相关记录
* 预期:第一次按正常流程处理;第二次不会生成重复数据,状态和相关记录正确。
*
* 说明:「重复处理」对数据传输接口的语义:
* (a) 重复 xOrderCode 调用不会被吞掉,每次都会写一条独立消费日志;
* (b) callCount 按调用次数累加,不因重复而丢失前序记录;
* (c) 但当达到 useTimesLimit 时会被策略拒绝(参考 TC_DEL_004)。
*/
export const meta = {
tc: 'TC-DELIVERY_API-004',
req: 'REQ-066',
title: '重复办理数据传输时不会重复处理',
type: '反向/状态迁移',
priority: 'P1',
route: '',
needs: ['be']
}
export async function run(t) {
let target = null
await t.step('前置:登录', async () => {
await t.login()
})
await t.step('前置:选一条 deliveryType=API 的任务', async () => {
const r = await fetch('http://localhost:30000/api/ssw/tdc/DeliveryTask?currentPage=1&pageSize=20&deliveryType=API', {
headers: { Authorization: t.token, 'App-Code': 'sswflow', 'Jnpf-Origin': 'pc', 'Vue-Version': '3' }
})
const j = await r.json()
target = (j.data?.list || []).find((x) => x.taskCode && x.productId)
if (!target) t.skip('库中没有 API 交付任务')
t.assert(true, `选定 ${target.taskCode}`)
})
await t.step('正向:连发两次 Invoke 都成功,callCount 累加', async () => {
const expectAppId = 'app_' + target.id.substring(0, Math.min(8, target.id.length))
const before = (await t.api('GET', `/api/ssw/tdc/DeliveryTask/${target.id}`)).data?.callCount ?? 0
const r1 = await t.api('POST', '/api/ssw/tdc/Gateway/Invoke', {
appId: expectAppId, appKey: 'k', xOrderCode: target.taskCode
})
t.assert(r1.code === 200, `第一次 Invoke 200(${r1.code})`)
const r2 = await t.api('POST', '/api/ssw/tdc/Gateway/Invoke', {
appId: expectAppId, appKey: 'k', xOrderCode: target.taskCode
})
t.assert(r2.code === 200, `第二次 Invoke 200(${r2.code})`)
t.assert(r2.data?.callCount === before + 2, `callCount 累加两次(${before} → ${r2.data?.callCount})`)
})
await t.step('核对:消费日志按 deliveryTaskId 找到至少 2 条 SUCCESS 留痕', async () => {
const r = await t.api('GET', `/api/ssw/tdc/ApiConsumeLog?currentPage=1&pageSize=50&deliveryTaskId=${target.id}&status=SUCCESS`)
const list = r.data?.list || []
t.assert(list.length >= 2, `至少 2 条 SUCCESS 留痕(${list.length})`)
})
await t.step('反向:相同请求体两次(验证幂等性 - 不需要再次断言 callCount 已增加)', async () => {
const expectAppId = 'app_' + target.id.substring(0, Math.min(8, target.id.length))
const r = await t.api('POST', '/api/ssw/tdc/Gateway/Invoke', {
appId: expectAppId, appKey: 'k', xOrderCode: target.taskCode
})
// 关键点:重复处理 = 每次都按 xOrderCode 真实执行 + 落独立留痕,不会被前端 / 接口合并
t.assert(r.code === 200, `重复调用仍正常执行(${r.code})`)
t.assert(typeof r.data?.callCount === 'number', `每次响应都回带 callCount`)
})
}