abnormalFlowDeclaration.mock.test.mjs
2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* 异常流水 API Mock:count / 分页 / 提交联动 / 详情
*/
import { describe, it, beforeEach } from 'node:test'
import assert from 'node:assert/strict'
import {
getMockCount,
getMockShopLock,
getMockUnionPage,
getMockDeclarationPage,
getMockDetail,
submitMock,
resetAbnormalFlowMockStore,
MOCK_SHOP_LOCK
} from './fixtures/abnormalFlowDeclaration.mock.js'
describe('abnormalFlowDeclaration.mock', () => {
beforeEach(() => {
resetAbnormalFlowMockStore()
})
it('getMockCount 初始待报备 4、已报备 5', () => {
const count = getMockCount()
assert.equal(count.notDeclaredCount, 4)
assert.equal(count.declaredCount, 5)
assert.equal(count.totalCount, 9)
})
it('getMockShopLock 默认与 MOCK_SHOP_LOCK 一致', () => {
assert.equal(getMockShopLock(), MOCK_SHOP_LOCK)
})
it('getMockUnionPage 按页切片', () => {
const page = getMockUnionPage({ currentPage: 1, pageSize: 2 })
assert.equal(page.list.length, 2)
assert.equal(page.total, 4)
assert.ok(page.list[0].outTradeNo)
assert.equal(page.list[0].declarationFlag, 0)
})
it('getMockDeclarationPage 覆盖审批状态样例', () => {
const page = getMockDeclarationPage({ currentPage: 1, pageSize: 10 })
const statuses = new Set(page.list.map(i => i.approvalStatus))
assert.ok(statuses.has(1))
assert.ok(statuses.has(5))
})
it('submitMock 后 count 与列表联动', () => {
const before = getMockCount()
const result = submitMock({
outTradeNo: 'MOCK_PAY_001',
abnormalType: 1,
remark: 'mock submit'
})
assert.ok(result.declarationId)
const after = getMockCount()
assert.equal(after.notDeclaredCount, before.notDeclaredCount - 1)
assert.equal(after.declaredCount, before.declaredCount + 1)
const pending = getMockUnionPage({ currentPage: 1, pageSize: 20 })
assert.equal(
pending.list.some(i => i.outTradeNo === 'MOCK_PAY_001'),
false
)
const detail = getMockDetail({ id: result.declarationId })
assert.ok(detail)
assert.equal(detail.declarationInfo.remark, 'mock submit')
assert.ok(Array.isArray(detail.approvalLogs))
})
})