lowPriceGoodsValidation.helpers.test.mjs
4.2 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
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import {
LOW_PRICE_NOT_TRIGGERED_MESSAGE,
resolveLowPriceGoodsEntries,
validateLowPriceGoods,
validateLowPriceGoodsList,
applyLowPriceGoodsValidation
} 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 fails when any leaf does not trigger 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, false)
assert.equal(result.invalidGoods.length, 1)
})
it('IT-WO-LPG-006: applies minimum-price echo and clears stale normal-order errors for valid low-price goods', () => {
const valid = {
validMinSellPrice: 'Y',
minSellPrice: 100,
sellPrice: 80,
errorTarget: true,
checkError: true,
basePriceError: true
}
const disabled = {
validMinSellPrice: 'N',
minSellPrice: 60,
sellPrice: 30
}
const goodsList = [
{ goodsFlag: 1, goods: valid },
{ goodsFlag: 1, goods: disabled }
]
const result = applyLowPriceGoodsValidation(goodsList)
assert.equal(result.valid, false)
assert.equal(valid.lowPriceMinPriceText, '最低价:¥100')
assert.equal(valid.errorTarget, false)
assert.equal(valid.checkError, false)
assert.equal(valid.basePriceError, false)
assert.equal(disabled.lowPriceMinPriceText, '最低价:未开启')
assert.equal(disabled.errorTarget, true)
})
it('IT-WO-LPG-007: exposes the required reminder copy', () => {
assert.equal(
LOW_PRICE_NOT_TRIGGERED_MESSAGE,
'价格未触发最低价,其他正常单请到生意助手侧录单'
)
})
})