simpleQuotationRoute.helpers.test.mjs
3.34 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
import assert from 'node:assert/strict'
import { describe, it } from 'node:test'
import {
buildSimpleQuotationRouteState,
getLatestAccountTimestamp
} from '../pages/carQuotation/services/simpleQuotationRoute.helpers.js'
describe('simpleQuotationRoute.helpers', () => {
it('IT-EQ-SIMPLE-ROUTE-001: maps each supported payment entry without mixing route and order state', () => {
assert.deepEqual(buildSimpleQuotationRouteState({ paymentMethod: 1 }), {
pagePatch: { paymentMethod: 1 },
orderPatch: { payType: 1, payee: 0 }
})
assert.deepEqual(buildSimpleQuotationRouteState({ paymentMethod: 3 }), {
pagePatch: { paymentMethod: 3 },
orderPatch: { payType: 2, payee: 1 }
})
assert.deepEqual(buildSimpleQuotationRouteState({ paymentMethod: 4 }), {
pagePatch: { paymentMethod: 4 },
orderPatch: { payType: 6, payee: 0 }
})
assert.deepEqual(buildSimpleQuotationRouteState({ paymentMethod: 6 }), {
pagePatch: { paymentMethod: 6 },
orderPatch: { payType: 7, payee: 0 }
})
assert.deepEqual(buildSimpleQuotationRouteState({ paymentMethod: 5 }), {
pagePatch: { paymentMethod: 5 },
orderPatch: {}
})
})
it('IT-EQ-SIMPLE-ROUTE-002: maps one in-period trade to online pay and keeps zero-cent totals exact', () => {
const trades = [
{
outTradeNo: 'out-1',
tradeNo: 'trade-1',
totalFee: 0,
switchValue: 1,
accountDateValue: 100
}
]
const result = buildSimpleQuotationRouteState(
{ selectOutTradeNoArr: trades },
{ formatAccountDate: value => `date:${value}` }
)
assert.deepEqual(result.pagePatch, {
selectOutTradeNoArr: trades,
switchValue: 1,
outTradeNo: 'out-1',
tradeNo: 'trade-1',
totalFee: 0,
accountDate: 'date:100',
showTips: true,
orderCreateType: 'additionRecordOrder'
})
assert.deepEqual(result.orderPatch, {
payType: 1,
payee: 0,
outTradeNo: 'out-1',
tradeNo: 'trade-1',
transactionNo: 'trade-1',
switchValue: 1,
selectOutTradeNoArr: trades,
successDateTime: '',
pay2Time: ''
})
})
it('IT-EQ-SIMPLE-ROUTE-003: mixed settlement periods use the latest date and combined recorded-payment fields', () => {
const trades = [
{
outTradeNo: 'out-1',
tradeNo: 'trade-1',
totalFee: 101,
switchValue: 1,
accountDateValue: 100
},
{
outTradeNo: 'out-2',
tradeNo: 'trade-2',
totalFee: 202,
switchValue: 2,
accountDateValue: 300
}
]
const result = buildSimpleQuotationRouteState(
{ selectOutTradeNoArr: trades, orderCreateType: 'custom-record' },
{ formatAccountDate: value => `date:${value}` }
)
assert.equal(getLatestAccountTimestamp(trades), 300)
assert.equal(result.pagePatch.switchValue, null)
assert.equal(result.pagePatch.totalFee, 303)
assert.equal(result.pagePatch.accountDate, 'date:300')
assert.equal(result.pagePatch.orderCreateType, 'custom-record')
assert.equal(result.orderPatch.payType, 5)
assert.equal(result.orderPatch.successDateTime, 'date:300')
assert.equal(result.orderPatch.pay2Time, 'date:300')
assert.equal(result.orderPatch.outTradeNo, 'out-1,out-2')
assert.equal(result.orderPatch.transactionNo, 'trade-1,trade-2')
})
})