goodsChooseEcho.helpers.test.mjs
3.5 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
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import {
mergeSubOrderListForEcho,
findCatalogSingleGoodsItem,
resolveSubOrderUnitPrice,
applySubOrderDiscountEcho,
buildSingleGoodsChooseEntry,
resolveSubOrderMarketingEcho,
isMultiSpecSubOrderLine,
normalizeOrderMoney
} from '../services/goodsChooseEcho.helpers.js'
describe('goodsChooseEcho.helpers', () => {
it('IT-WO-ECHO-001: merge filters package rows from subOrder', () => {
const merged = mergeSubOrderListForEcho(
[{ id: 1 }, { packageName: 'pkg' }],
[{ id: 2 }]
)
assert.equal(merged.length, 2)
assert.equal(merged[0].id, 1)
assert.equal(merged[1].id, 2)
})
it('IT-WO-ECHO-002: findCatalogSingleGoodsItem', () => {
const cat = findCatalogSingleGoodsItem(
[{ goodsFlag: 1, goods: { merchantGoodsId: 9 } }],
9
)
assert.equal(cat.goods.merchantGoodsId, 9)
})
it('IT-WO-ECHO-003: resolveSubOrderUnitPrice resetOrder uses sellPrice', () => {
assert.equal(
resolveSubOrderUnitPrice({ sellPrice: 88, number: 2 }, true),
88
)
})
it('IT-WO-ECHO-004: resolveSubOrderUnitPrice from total', () => {
assert.equal(
resolveSubOrderUnitPrice({ totalPrice: 200, number: 2 }, false),
100
)
})
it('IT-WO-ECHO-010: total price division is normalized to cents', () => {
for (const resetOrder of [false, true]) {
assert.equal(
resolveSubOrderUnitPrice(
{ totalPrice: 9999.95, number: 5 },
resetOrder
),
1999.99,
`resetOrder=${resetOrder}`
)
}
})
it('IT-WO-ECHO-011: echoed sell price drops binary floating-point tails', () => {
assert.equal(
resolveSubOrderUnitPrice(
{ sellPrice: 1999.9900000000002, number: 5 },
true
),
1999.99
)
})
it('IT-WO-ECHO-012: missing echoed money is distinct from explicit zero', () => {
assert.equal(normalizeOrderMoney(null), undefined)
assert.equal(normalizeOrderMoney(undefined), undefined)
assert.equal(normalizeOrderMoney(''), undefined)
assert.equal(normalizeOrderMoney(' '), undefined)
assert.equal(normalizeOrderMoney(0), 0)
assert.equal(normalizeOrderMoney('0'), 0)
})
it('IT-WO-ECHO-005: applySubOrderDiscountEcho ratio', () => {
const g = { sellPrice: 100, discountType: 1, discountValue: 8 }
applySubOrderDiscountEcho(g)
assert.equal(g.finalPrice, 80)
})
it('IT-WO-ECHO-006: applySubOrderDiscountEcho gift', () => {
const g = { sellPrice: 50, discountType: 4 }
applySubOrderDiscountEcho(g)
assert.equal(g.finalPrice, 0)
})
it('IT-WO-ECHO-007: resolveSubOrderMarketingEcho', () => {
const meta = resolveSubOrderMarketingEcho(
{ marketingFlag: 1, activityId: 3 },
{ marketingFlag: 0, activityId: 9 }
)
assert.equal(meta.activityId, 3)
assert.equal(meta.isMarketingGoods, true)
})
it('IT-WO-ECHO-008: buildSingleGoodsChooseEntry', () => {
const line = {
merchantGoodsId: 1,
number: 2,
specificationData: 'S'
}
const entry = buildSingleGoodsChooseEntry(line, {
marketingFlag: 1,
activityId: 5
})
assert.equal(entry.goodsFlag, 1)
assert.equal(entry.count, 2)
assert.equal(entry.activityId, 5)
})
it('IT-WO-ECHO-009: skips multi-spec lines', () => {
assert.equal(
buildSingleGoodsChooseEntry({
specificationData: 'A;~;B'
}),
null
)
assert.equal(isMultiSpecSubOrderLine({ specificationData: 'A;~;B' }), true)
})
})