minPriceApproval.test.mjs
3.03 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
import { test } from 'node:test'
import assert from 'node:assert/strict'
import {
buildMinPriceApprovalList,
needsMinPriceApproval,
needsPackageSubMinPriceApproval,
resolveApprovalActivityPrice,
resolveApprovalCheckPrice
} from '../services/minPriceApproval.js'
test('historical approval comparison uses exact cents and keeps gifts excluded', () => {
assert.equal(
needsMinPriceApproval({
validMinSellPrice: 'Y',
upgradeShopMinPrice: '200.00',
minSellPrice: 100,
sellPrice: '199.99'
}),
true
)
assert.equal(
needsMinPriceApproval({
validMinSellPrice: 'Y',
minSellPrice: 200,
sellPrice: 200
}),
false
)
assert.equal(
needsMinPriceApproval({
validMinSellPrice: 'Y',
minSellPrice: 200,
sellPrice: 100,
discountType: 4
}),
false
)
})
test('resolveApprovalCheckPrice prefers basePrice', () => {
assert.equal(resolveApprovalCheckPrice({ basePrice: 100, sellPrice: 200 }), 100)
})
test('activity price preserves catalog authority and safe unit-price fallback', () => {
assert.equal(
resolveApprovalActivityPrice({ catalogSellPrice: 299, sellPrice: 100 }),
299
)
assert.equal(
resolveApprovalActivityPrice({ price: 598, number: 2 }),
299
)
assert.equal(
resolveApprovalActivityPrice({ price: '1.001', number: 1 }),
0
)
assert.equal(
resolveApprovalActivityPrice({ price: 100, number: 0 }),
0
)
})
test('approval list keeps single, package and multi-spec display contracts', () => {
const list = buildMinPriceApprovalList([
{
goodsFlag: 1,
count: 2,
marketingFlag: 1,
goods: {
validMinSellPrice: 'Y',
minSellPrice: 200,
activitySellPrice: 299,
sellPrice: 100,
number: 1,
upgradeGoodsName: '太阳膜'
}
},
{
goodsFlag: 3,
count: 1,
packageGoods: {
packageName: '套餐',
goodsList: [
{
validMinSellPrice: 'Y',
minSellPrice: 199,
sellPrice: 179,
upgradeGoodsName: '车窗膜'
},
{
validMinSellPrice: 'Y',
minSellPrice: 320,
sellPrice: 320,
upgradeGoodsName: '正常商品'
}
]
}
},
{
goodsFlag: 2,
count: 1,
multipleSpecificationsGoods: {
goods: {
validMinSellPrice: 'Y',
minSellPrice: 100,
sellPrice: 0.1,
activitySellPrice: 30,
upgradeGoodsName: '多规格 SKU'
}
}
}
])
assert.equal(list.length, 3)
assert.equal(list[0].count, 2)
assert.equal(list[0].activityPrice, 299)
assert.equal(list[1].children.length, 1)
assert.equal(list[1].totalPrice, 179)
assert.equal(list[2].activityPrice, 30)
})
test('package approval compares its own minSellPrice', () => {
assert.equal(
needsPackageSubMinPriceApproval({
validMinSellPrice: 'Y',
minSellPrice: 30,
upgradeShopMinPrice: 200,
sellPrice: 40
}),
false
)
})