simpleQuotationPayload.helpers.test.mjs
4.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
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
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import {
buildSimpleQuotationPayload,
mapSimpleQuotationGoods
} from '../pages/carQuotation/services/simpleQuotationPayload.helpers.js'
describe('simpleQuotationPayload.helpers', () => {
it('IT-EQ-SIMPLE-PAY-001: maps single, package and multi-spec goods without re-deriving authoritative line totals', () => {
const goods = [
{
goods: {
merchantGoodsId: 'single-1',
goodsName: '单品',
goodsAlias: '单品别名',
specificationNameSequence: '颜色',
specificationData: '红;~;大',
price: 100,
finalPrice: 123,
quantity: 3,
discountType: 1,
discountValue: 9,
discountAmount: 7
}
},
{
packageGoods: {
packageCode: 'package-1',
packageName: '套餐',
packageAlias: '套餐别名',
goodsList: [
{
merchantGoodsId: 'package-good-1',
goodsName: '套餐商品',
price: 200,
finalPrice: 150,
quantity: 0,
discountType: 2
}
]
}
},
{
multipleSpecificationsGoods: {
goods: {
merchantGoodsId: 'sku-1',
upgradeGoodsName: '多规格商品',
price: 300,
finalPrice: 260,
discountType: 3
}
}
},
{
goods: {
merchantGoodsId: 'gift-1',
goodsName: '赠品',
price: 999,
finalPrice: 999,
discountType: 4
}
}
]
const mapped = mapSimpleQuotationGoods(goods)
assert.equal(mapped.length, 4)
assert.equal(mapped[0].finalPrice, 123)
assert.equal(mapped[0].singleProductFinalPrice, 123)
assert.equal(mapped[1].packageId, 'package-1')
assert.equal(mapped[1].finalPrice, 150)
assert.equal(mapped[2].goodsId, 'sku-1')
assert.equal(mapped[2].finalPrice, 260)
assert.equal(mapped[3].finalPrice, 0)
})
it('IT-EQ-SIMPLE-PAY-002: builds the existing API payload in integer cents without mutating page state', () => {
const input = {
owner: {
customerName: '张三',
price: '0.29',
salesType: '售后'
},
orderInfo: {
id: 8,
insurancePrice: '1.01',
total: '2.02',
quotedPriceUpdate: '3.03',
finalPrice: '4.04',
minEquityPrice: '5.05',
paymentDocList: undefined,
vdQuotationGoodsList: [
{
goods: {
merchantGoodsId: 'g-1',
goodsName: '商品',
price: 99,
discountType: 4
}
}
]
},
context: {
merchant4s: { merchantId: 11, merchantName: '测试门店' }
}
}
const snapshot = structuredClone(input)
const result = buildSimpleQuotationPayload(input)
assert.equal(result.ok, true)
assert.equal(result.payload.insurancePrice, 101)
assert.equal(result.payload.total, 202)
assert.equal(result.payload.quotedPriceUpdate, 303)
assert.equal(result.payload.finalPrice, 404)
assert.equal(result.payload.minEquityPrice, 505)
assert.equal(result.payload.owner.price, 29)
assert.equal(result.payload.owner.salesType, 1)
assert.deepEqual(result.payload.paymentDocList, [])
assert.deepEqual(result.payload.vdQuotationGoodsList[0], {
goodsId: 'g-1',
goodsName: '商品',
goodsNameAlias: undefined,
specificationsName: undefined,
specificationsValue: '',
goodsPrice: 99,
finalPrice: 0,
singleProductFinalPrice: 0,
discountType: 4,
discountValue: undefined,
discountAmount: 0
})
assert.equal(result.payload.merchantId4s, 11)
assert.deepEqual(input, snapshot)
})
it('IT-EQ-SIMPLE-PAY-003: missing optional amounts become zero but invalid amounts block submission', () => {
const empty = buildSimpleQuotationPayload({
owner: {},
orderInfo: { vdQuotationGoodsList: [] },
context: {}
})
assert.equal(empty.ok, true)
assert.equal(empty.payload.total, 0)
assert.deepEqual(empty.payload.vdQuotationGoodsList, [])
const invalid = buildSimpleQuotationPayload({
owner: {},
orderInfo: {
total: '0.001',
finalPrice: '-1',
vdQuotationGoodsList: []
},
context: {}
})
assert.equal(invalid.ok, false)
assert.deepEqual(
invalid.errors.map(item => item.field),
['total', 'finalPrice']
)
})
})