quotationPayload.helpers.test.mjs
5.37 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import {
buildInsurancePayload,
buildOwnerPayload,
parseInsureListToForm,
mapQuotationGoodsList,
mapOwnerSalesTypeForApi,
mapOwnerSalesTypeFromApi
} from '../pages/carQuotation/services/quotationPayload.helpers.js'
describe('quotationPayload.helpers', () => {
it('IT-EQ-PAY-001: buildInsurancePayload flattens insureList', () => {
const payload = buildInsurancePayload(
{
business: { type: 0, base: 100 },
mutualStrength: { type: 1, payPrice: 50 },
vehiclesAndVessels: { type: 2 },
valueAddedVehicleLoss: { type: 3 },
otherInsuranceList: [{ type: 4, base: 10 }]
},
{ merchantId: 'm1', merchantName: '店A' }
)
assert.equal(payload.insureList.length, 5)
assert.equal(payload.business, undefined)
assert.equal(payload.merchantId4s, 'm1')
assert.equal(payload.insureList[0].base, 10000)
})
it('IT-EQ-PAY-002: vdQuotationGoodsList defaults', () => {
const payload = buildInsurancePayload(
{
business: {},
mutualStrength: {},
vehiclesAndVessels: {},
valueAddedVehicleLoss: {},
otherInsuranceList: []
},
{}
)
assert.deepEqual(payload.vdQuotationGoodsList, [])
assert.deepEqual(payload.paymentDocList, [])
})
it('IT-EQ-PAY-003: buildOwnerPayload scales price', () => {
const owner = buildOwnerPayload(
{
price: 12.5,
salesType: 0,
buyCarTime: '2020',
customerTags: '3,1,3',
actualDeliveryDate: '2026-08-04'
},
undefined,
{ baseSceneName: '2.3.1 权益场景' }
)
assert.equal(owner.price, 1250)
assert.equal(owner.buyCarTime, undefined)
assert.equal(owner.customerTags, '1,3')
assert.equal(owner.actualDeliveryDate, '2026-08-04 00:00:00')
})
it('IT-EQ-PAY-003b: buildOwnerPayload keeps empty daily fields', () => {
const owner = buildOwnerPayload({ price: '', customerTags: [], actualDeliveryDate: '' })
assert.equal(owner.customerTags, '')
assert.equal(owner.actualDeliveryDate, '')
})
it('IT-EQ-PAY-003c: buildOwnerPayload clears values hidden by source', () => {
const afterSales = buildOwnerPayload(
{
salesType: 1,
customerTags: '1,3',
actualDeliveryDate: '2026-08-04'
},
undefined,
{ baseSceneName: '2.3.1 权益场景' }
)
assert.equal(afterSales.customerTags, '1,3')
assert.equal(afterSales.actualDeliveryDate, '')
const natural = buildOwnerPayload(
{
salesType: 2,
customerTags: '1,3',
actualDeliveryDate: '2026-08-04'
},
undefined,
{ baseSceneName: '2.3.1 权益场景' }
)
assert.equal(natural.customerTags, '')
assert.equal(natural.actualDeliveryDate, '')
})
it('IT-EQ-PAY-003d: buildOwnerPayload clears date outside template scenes', () => {
const owner = buildOwnerPayload(
{
salesType: 0,
customerTags: '1',
actualDeliveryDate: '2026-08-04'
},
undefined,
{ baseSceneName: '2.4.1 非适用场景' }
)
assert.equal(owner.customerTags, '1')
assert.equal(owner.actualDeliveryDate, '')
})
it('IT-EQ-PAY-003e: buildOwnerPayload retains date for a numeric equity scene', () => {
const owner = buildOwnerPayload(
{
salesType: 0,
customerTags: '1',
actualDeliveryDate: '2026-08-04'
},
undefined,
{ baseSceneName: '', baseSceneCode: 110101 }
)
assert.equal(owner.actualDeliveryDate, '2026-08-04 00:00:00')
})
it('IT-EQ-PAY-004: parseInsureListToForm type 4 multiple', () => {
const form = parseInsureListToForm([
{ type: 0, base: 10000 },
{ type: 4, base: 5000 },
{ type: 4, base: 3000 }
])
assert.equal(form.business.base, 100)
assert.equal(form.otherInsuranceList.length, 2)
})
it('IT-EQ-PAY-005: mapQuotationGoodsList field map', () => {
const rows = mapQuotationGoodsList([
{
upgradeGoodsName: '权益A',
upgradeGoodsServiceItemsList: [1],
goodsInfo: { thumbUrl: 'http://x' }
}
])
assert.equal(rows[0].goodsName, '权益A')
assert.equal(rows[0].titlePictureUrl, 'http://x')
})
it('IT-EQ-PAY-006: mapQuotationGoodsList isSeletct with outTradeNo', () => {
const rows = mapQuotationGoodsList(
[{ shopMinPrice: 100, upgradeGoodsName: 'G' }],
{ outTradeNo: 't', totalFee: 5000 }
)
assert.equal(rows[0].isSeletct, true)
})
it('IT-EQ-PAY-007: salesType mapping', () => {
assert.equal(mapOwnerSalesTypeForApi('售后'), 1)
assert.equal(mapOwnerSalesTypeForApi('售前'), 0)
assert.equal(mapOwnerSalesTypeFromApi(1), '售后')
assert.equal(mapOwnerSalesTypeForApi(2), 2)
assert.equal(mapOwnerSalesTypeFromApi(2), 2)
})
it('IT-EQ-PAY-008: invalid standard quotation amounts fail instead of becoming zero', () => {
assert.throws(
() => buildInsurancePayload({ business: { base: '0.001' } }),
/business\.base/
)
assert.throws(() => buildOwnerPayload({ price: '-1' }), /owner\.price/)
})
it('IT-EQ-PAY-009: minimum-price selection compares integer cents at the safe limit', () => {
const [mapped] = mapQuotationGoodsList(
[{ shopMinPrice: '90071992547409.90' }],
{ outTradeNo: 'trade-1', totalFee: '9007199254740989' }
)
assert.equal(mapped.isSeletct, true)
})
})