submitGoodsSnapshot.test.mjs
3.29 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
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import {
buildBoutiqueSubOrderList,
buildSubmitGoodsSnapshot
} from '../services/submitGoodsSnapshot.js'
describe('submitGoodsSnapshot', () => {
it('maps goodsList and subOrder fields without dormant approval state', () => {
const snapshot = buildSubmitGoodsSnapshot({
goodsList: [
{
goodsFlag: 1,
count: 2,
marketingFlag: 1,
activityId: 9,
goods: {
sellPrice: 100,
activitySellPrice: 299,
marketingFlag: 1,
activityId: 9,
validMinSellPrice: 'Y',
minSellPrice: 200
}
}
],
orderObj: {
subOrderList: [
{
merchantGoodsId: 1,
totalPrice: 100,
finalPrice: 200,
marketingFlag: 1,
activityId: 9,
modifyFlag: 1,
number: 2
}
]
}
})
assert.equal(snapshot.goodsList.length, 1)
assert.equal(snapshot.goodsList[0].goods.activitySellPrice, 299)
assert.equal('approvalItems' in snapshot, false)
assert.equal(snapshot.subOrderList[0].marketingFlag, 1)
assert.equal(snapshot.subOrderList[0].activityId, 9)
})
it('maps single, multi-spec and package rows with exact totals', () => {
const result = buildBoutiqueSubOrderList(
[
{
goodsFlag: 1,
count: 2,
goods: {
merchantGoodsId: 'single',
sellPrice: '10.01',
discountType: 2,
discountValue: '0.01',
discountAmount: '0.01'
}
},
{
goodsFlag: 2,
count: 1,
multipleSpecificationsGoods: {
goods: {
merchantGoodsId: 'sku',
sellPrice: '20.02',
discountType: 3
}
}
},
{
goodsFlag: 3,
count: 1,
packageGoods: {
packageCode: 'pkg',
packageName: '套餐',
goodsList: [
{
merchantGoodsId: 'pkg-good',
sellPrice: '30.03',
discountType: 4
}
]
}
}
],
{ djOrderType: 2, selectPayType: 1 }
)
assert.equal(result.ok, true)
assert.equal(result.subOrderList.length, 3)
assert.equal(result.subOrderList[0].finalPrice, 20)
assert.equal(result.subOrderList[0].singleProductFinalPrice, 10)
assert.equal(result.subOrderList[1].finalPrice, 20.02)
assert.equal(result.subOrderList[2].packageCode, 'pkg')
assert.equal(result.subOrderList[2].finalPrice, 0)
})
it('reports zero quantity and invalid amounts instead of producing NaN', () => {
const result = buildBoutiqueSubOrderList(
[
{
goodsFlag: 1,
count: 0,
goods: { merchantGoodsId: 'g', sellPrice: 'invalid' }
}
],
{ djOrderType: 1, selectPayType: 1 }
)
assert.equal(result.ok, false)
assert.equal(result.errors.length > 0, true)
assert.equal(
result.subOrderList.some(item =>
[item.totalPrice, item.finalPrice].some(Number.isNaN)
),
false
)
})
})