goodsChooseEcho.helpers.test.mjs
2.53 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
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import {
mergeSubOrderListForEcho,
findCatalogSingleGoodsItem,
resolveSubOrderUnitPrice,
applySubOrderDiscountEcho,
buildSingleGoodsChooseEntry,
resolveSubOrderMarketingEcho,
isMultiSpecSubOrderLine
} 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-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)
})
})