submitPayload.helpers.test.mjs
3.56 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import {
buildSubmitPayload,
prepareSubmitPayload,
resolveSubmitApiName
} from '../services/submitPayload.helpers.js'
describe('submitPayload.helpers', () => {
const baseOrder = {
orderCode: 'OC1',
sceneType: 1,
baseSceneCode: '100101',
subOrderList: [{}],
customerCouponCode: 'C1',
selectPayType: 1,
customer: { buyTime: 'x', createdDate: 'y', plateNumber: 'P' },
profitAllocatinList: [],
associateOrderCode: 'OLD1'
}
it('IT-WO-SUB-001: resolveSubmitApiName normal pay', () => {
assert.equal(
resolveSubmitApiName({ save: false, isErrorOrder: false }),
'createWithPay'
)
})
it('IT-WO-SUB-002: resolveSubmitApiName prerecorded save', () => {
assert.equal(
resolveSubmitApiName({ save: true, isErrorOrder: false }),
'createPrerecordedOrder'
)
})
it('IT-WO-SUB-003: resolveSubmitApiName correction', () => {
assert.equal(
resolveSubmitApiName({ save: false, isErrorOrder: true }),
'correctionOrder'
)
})
it('IT-WO-SUB-004: resolveSubmitApiName supplement overrides', () => {
assert.equal(
resolveSubmitApiName({
save: true,
isErrorOrder: false,
orderCreateType: 'additionRecordOrder'
}),
'supplementOrder'
)
})
it('IT-WO-SUB-005: strips audit fields on build', () => {
const out = buildSubmitPayload(baseOrder, {})
assert.equal(out.profitAllocatinList, undefined)
assert.equal(out.customer.buyTime, undefined)
})
it('IT-WO-SUB-006: save removes subOrderList and coupon', () => {
const out = buildSubmitPayload(baseOrder, { save: true })
assert.equal(out.subOrderList, undefined)
assert.equal(out.customerCouponCode, undefined)
assert.equal(out.selectPayType, undefined)
})
it('IT-WO-SUB-007: error order sets oldOrderCode', () => {
const out = buildSubmitPayload(baseOrder, { isErrorOrder: true })
assert.equal(out.oldOrderCode, 'OLD1')
})
it('IT-WO-SUB-008: defeat order clears customer fields', () => {
const out = buildSubmitPayload(
{ ...baseOrder, selectPayType: 0, remark: 'r' },
{}
)
assert.equal(out.remark, undefined)
assert.equal(out.customer.experienceFlag, 'Y')
assert.equal(out.customer.plateNumber, undefined)
})
it('IT-WO-SUB-009: no scene keeps orderCode when present', () => {
const out = buildSubmitPayload({ orderCode: 'X' }, {})
assert.equal(out.orderCode, 'X')
})
it('IT-WO-SUB-010: scene keeps orderCode', () => {
const out = buildSubmitPayload({ orderCode: 'X' }, { scene: 's' })
assert.equal(out.orderCode, 'X')
})
it('IT-WO-SUB-011: no baseSceneCode drops sceneType', () => {
const out = buildSubmitPayload({ sceneType: 2 }, {})
assert.equal(out.sceneType, undefined)
})
it('IT-WO-SUB-012: prepareSubmitPayload bundles apiName', () => {
const { apiName, submitObj } = prepareSubmitPayload(baseOrder, {
save: false,
isErrorOrder: false,
orderCreateType: 'createdOrder'
})
assert.equal(apiName, 'createWithPay')
assert.equal(submitObj.filmOrder, 0)
})
it('IT-WO-SUB-013: low price store context survives submit cleanup', () => {
const out = buildSubmitPayload(
{
...baseOrder,
lowPriceFlag: 1,
merchantId: 201,
yqMerchantId: 100,
sellerMerchantId: 100
},
{}
)
assert.equal(out.lowPriceFlag, 1)
assert.equal(out.merchantId, 201)
assert.equal(out.yqMerchantId, 100)
assert.equal(out.sellerMerchantId, 100)
})
})