simpleQuotationValidation.helpers.test.mjs
3.92 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
124
125
126
127
128
129
130
131
132
133
134
135
import assert from 'node:assert/strict'
import { describe, it } from 'node:test'
import {
normalizeSimplePaymentDocuments,
shouldRequestSimplePaymentDocuments,
validateSimpleQuotationSubmission
} from '../pages/carQuotation/services/simpleQuotationValidation.helpers.js'
const goods = item => [{ goodsFlag: 1, goods: { merchantGoodsId: 'g-1', ...item } }]
describe('simpleQuotationValidation.helpers', () => {
it('IT-EQ-SIMPLE-VALID-001: returns the first existing submit message in business order', () => {
assert.equal(
validateSimpleQuotationSubmission({ vdQuotationGoodsList: [] }).message,
'请选择增值车损险商品'
)
assert.equal(
validateSimpleQuotationSubmission({
vdQuotationGoodsList: goods({}),
payType: 2,
resetOrder: false
}).message,
'请选择4S店收款时间'
)
assert.equal(
validateSimpleQuotationSubmission({
vdQuotationGoodsList: goods({}),
payType: 7,
pay2Time: '2026-09-08',
notes: '',
resetOrder: false
}).message,
'备注不能为空'
)
})
it('IT-EQ-SIMPLE-VALID-002: accepts an explicit zero discount and rejects missing strategy values', () => {
assert.equal(
validateSimpleQuotationSubmission({
vdQuotationGoodsList: goods({ discountType: 1, discountValue: 0 }),
orderType: 2,
payType: 1,
total: '1.00'
}).ok,
true
)
assert.equal(
validateSimpleQuotationSubmission({
vdQuotationGoodsList: goods({ discountType: 1, discountValue: '' }),
orderType: 2,
payType: 1,
total: '1.00'
}).message,
'商品折扣值不能为空'
)
})
it('IT-EQ-SIMPLE-VALID-003: preserves buy-gift and combined-payment strategy rules', () => {
assert.equal(
validateSimpleQuotationSubmission({
vdQuotationGoodsList: goods({ discountType: 4 }),
orderType: 3,
payType: 1,
total: '1.00'
}).message,
'买赠策略至少需要选择两个商品'
)
assert.equal(
validateSimpleQuotationSubmission({
vdQuotationGoodsList: [
...goods({ merchantGoodsId: 'g-1', discountType: 0 }),
...goods({ merchantGoodsId: 'g-2', discountType: 0 })
],
orderType: 3,
payType: 1,
total: '1.00'
}).message,
'买赠策略需要至少有一个商品是赠品'
)
assert.equal(
validateSimpleQuotationSubmission({
vdQuotationGoodsList: goods({ discountType: 0 }),
orderType: 5,
payType: 1,
total: '1.00'
}).message,
'组合付款需要至少有一个商品选择折扣'
)
})
it('IT-EQ-SIMPLE-VALID-004: keeps amount validation and payment-document decisions deterministic', () => {
assert.equal(
validateSimpleQuotationSubmission({
vdQuotationGoodsList: goods({}),
orderType: 1,
payType: 1,
total: '0'
}).message,
'订单总价最低不能小于0.01元'
)
assert.equal(
shouldRequestSimplePaymentDocuments({
payType: 6,
resetOrder: false,
transactionNo: '',
paymentDocList: []
}),
true
)
assert.equal(
shouldRequestSimplePaymentDocuments({
payType: 6,
resetOrder: true,
transactionNo: '',
paymentDocList: []
}),
false
)
})
it('IT-EQ-SIMPLE-VALID-005: normalizes popup strings and detail documents without mutating either input', () => {
const documents = [
'https://example.test/new.png',
{ paymentDocUrl: 'https://example.test/echo.png', type: 2 }
]
const snapshot = structuredClone(documents)
assert.deepEqual(normalizeSimplePaymentDocuments(documents), [
{ paymentDocUrl: 'https://example.test/new.png', type: 1 },
{ paymentDocUrl: 'https://example.test/echo.png', type: 1 }
])
assert.deepEqual(documents, snapshot)
})
})