simpleQuotationProduct.strategy.test.mjs
2.83 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
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import {
DISCOUNT_TYPE,
getProductStrategy
} from '../pages/carQuotation/services/simpleQuotationProduct.strategy.js'
describe('simpleQuotationProduct.strategy money units', () => {
it('IT-EQ-PRODUCT-001: compares a cent price with a yuan minimum using the same unit', () => {
const strategy = getProductStrategy({
goods: {
price: 100,
minSellPrice: '1.01',
validMinSellPrice: 'Y'
}
})
assert.deepEqual(strategy.performValidation(), {
valid: false,
message: '单价不可低于商品最低价'
})
})
it('IT-EQ-PRODUCT-002: fixed-amount discount converts yuan to exact integer cents', () => {
const item = { goods: { price: 100 } }
const strategy = getProductStrategy(item)
strategy.setDiscount(DISCOUNT_TYPE.AMOUNT, '0.29')
assert.equal(item.goods.finalPrice, 71)
assert.equal(item.goods.discountAmount, 29)
})
it('IT-EQ-PRODUCT-003: package child uses the same exact amount and minimum-price rules', () => {
const item = {
packageGoods: {
price: 100,
goodsList: [
{
price: 100,
minSellPrice: '1.01',
validMinSellPrice: 'Y'
}
]
}
}
const strategy = getProductStrategy(item)
strategy.updateSubItemDiscount(0, DISCOUNT_TYPE.AMOUNT, '0.29')
assert.equal(item.packageGoods.goodsList[0].finalPrice, 71)
assert.equal(strategy.performValidation().valid, false)
})
it('IT-EQ-PRODUCT-004: ratio discount preserves the existing upward cent rule', () => {
const item = { goods: { price: 101 } }
getProductStrategy(item).setDiscount(DISCOUNT_TYPE.RATIO, '9.5')
assert.equal(item.goods.finalPrice, 96)
})
it('IT-EQ-PRODUCT-005: malformed minimum-price inputs fail closed', () => {
const invalidPrice = getProductStrategy({
goods: {
price: 'invalid',
minSellPrice: '1.00',
validMinSellPrice: 'Y'
}
})
assert.equal(invalidPrice.validatePrice().valid, false)
const invalidMinimum = getProductStrategy({
goods: {
price: 100,
minSellPrice: 'invalid',
validMinSellPrice: 'Y'
}
})
assert.equal(invalidMinimum.validatePrice().valid, false)
})
it('IT-EQ-PRODUCT-006: explicit zero quantity never falls back to one', () => {
const strategy = getProductStrategy({ count: 0, goods: { price: 100 } })
assert.equal(strategy.getCount(), 0)
assert.equal(strategy.calculateSubtotal(), 0)
})
it('IT-EQ-PRODUCT-007: over-precision ratios do not create float-tail totals', () => {
const item = { goods: { price: 101 } }
getProductStrategy(item).setDiscount(DISCOUNT_TYPE.RATIO, '9.501')
assert.equal(item.goods.finalPrice, 101)
assert.equal(item.goods.discountAmount, 0)
})
})