lowPriceGoodsValidation.helpers.test.mjs
5.13 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import {
applyLowPriceGoodsPresentation,
LOW_PRICE_NOT_TRIGGERED_MESSAGE,
resolveLowPriceGoodsEntries,
validateLowPriceGoods,
validateLowPriceGoodsList
} from '../services/lowPriceGoodsValidation.helpers.js'
describe('lowPriceGoodsValidation.helpers', () => {
it('IT-WO-LPG-001: accepts an enabled product only when input price is strictly below minSellPrice', () => {
assert.deepEqual(
validateLowPriceGoods({
validMinSellPrice: 'Y',
minSellPrice: 100,
sellPrice: 99.99
}),
{
valid: true,
enabled: true,
minPrice: 100,
currentPrice: 99.99
}
)
assert.equal(
validateLowPriceGoods({
validMinSellPrice: 'Y',
minSellPrice: 100,
sellPrice: 100
}).valid,
false
)
assert.equal(
validateLowPriceGoods({
validMinSellPrice: 'Y',
minSellPrice: 100,
sellPrice: 101
}).valid,
false
)
})
it('IT-WO-LPG-002: rejects disabled, missing-minimum and empty-price products', () => {
const invalidGoods = [
{ validMinSellPrice: 'N', minSellPrice: 100, sellPrice: 50 },
{ validMinSellPrice: 'Y', sellPrice: 50 },
{ validMinSellPrice: 'Y', minSellPrice: '', sellPrice: 50 },
{ validMinSellPrice: 'Y', minSellPrice: 100, sellPrice: '' }
]
invalidGoods.forEach(goods => {
assert.equal(validateLowPriceGoods(goods).valid, false)
})
})
it('IT-WO-LPG-003: validates the edited basePrice before catalog sellPrice', () => {
const result = validateLowPriceGoods({
validMinSellPrice: 'Y',
minSellPrice: 100,
basePrice: 80,
sellPrice: 120,
price: 130
})
assert.equal(result.currentPrice, 80)
assert.equal(result.valid, true)
})
it('IT-WO-LPG-004: flattens single goods, selected SKU and every package child', () => {
const single = { sellPrice: 10 }
const sku = { sellPrice: 20 }
const packageChildA = { sellPrice: 30 }
const packageChildB = { sellPrice: 40 }
assert.deepEqual(
resolveLowPriceGoodsEntries([
{ goodsFlag: 1, goods: single },
{
goodsFlag: 2,
multipleSpecificationsGoods: { goods: sku }
},
{
goodsFlag: 3,
packageGoods: { goodsList: [packageChildA, packageChildB] }
}
]),
[single, sku, packageChildA, packageChildB]
)
})
it('IT-WO-LPG-005: whole-order validation passes when any leaf triggers minimum price', () => {
const result = validateLowPriceGoodsList([
{
goodsFlag: 1,
goods: {
validMinSellPrice: 'Y',
minSellPrice: 100,
sellPrice: 80
}
},
{
goodsFlag: 3,
packageGoods: {
goodsList: [
{
validMinSellPrice: 'Y',
minSellPrice: 50,
sellPrice: 50
}
]
}
}
])
assert.equal(result.valid, true)
assert.equal(result.matchedGoods.length, 1)
assert.equal(result.invalidGoods.length, 1)
})
it('IT-WO-LPG-006: whole-order validation fails when no leaf triggers minimum price', () => {
const result = validateLowPriceGoodsList([
{
goodsFlag: 1,
goods: {
validMinSellPrice: 'Y',
minSellPrice: 100,
sellPrice: 100
}
},
{
goodsFlag: 1,
goods: {
validMinSellPrice: 'N',
minSellPrice: 60,
sellPrice: 30
}
}
])
assert.equal(result.valid, false)
assert.deepEqual(result.matchedGoods, [])
assert.equal(result.invalidGoods.length, 2)
})
it('IT-WO-LPG-007: empty goods cannot satisfy whole-order minimum price', () => {
const result = validateLowPriceGoodsList([])
assert.equal(result.valid, false)
assert.deepEqual(result.matchedGoods, [])
assert.deepEqual(result.invalidGoods, [])
})
it('IT-WO-LPG-008: exposes the required reminder copy', () => {
assert.equal(
LOW_PRICE_NOT_TRIGGERED_MESSAGE,
'价格未触发最低价,其他正常单请到生意助手侧录单'
)
})
it('IT-WO-LPG-009: presentation text never creates or changes input errors', () => {
const enabled = {
validMinSellPrice: 'Y',
minSellPrice: 100,
sellPrice: 120
}
const disabled = {
validMinSellPrice: 'N',
minSellPrice: 80,
sellPrice: 20,
errorTarget: false,
checkError: false,
basePriceError: false
}
applyLowPriceGoodsPresentation([
{ goodsFlag: 1, goods: enabled },
{ goodsFlag: 1, goods: disabled }
])
assert.equal(enabled.lowPriceMinPriceText, '最低价:¥100')
assert.equal(disabled.lowPriceMinPriceText, '最低价:未开启')
assert.equal(Object.hasOwn(enabled, 'errorTarget'), false)
assert.equal(Object.hasOwn(enabled, 'checkError'), false)
assert.equal(Object.hasOwn(enabled, 'basePriceError'), false)
assert.equal(disabled.errorTarget, false)
assert.equal(disabled.checkError, false)
assert.equal(disabled.basePriceError, false)
})
})