orderSubOrderExtras.test.mjs
3.3 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
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
const {
ensureCatalogUpgradePrice,
seedMarketingActivitySellPrice,
resolveSubmitMarketingFlag,
resolveSubmitActivityId,
appendSubmitActivityId,
resolveSubmitModifyFlag
} = await import('../tabWorkOrder/utils/orderSubOrderExtras.js')
describe('orderSubOrderExtras', () => {
it('resolveSubmitMarketingFlag returns 1 when goods has active flag', () => {
assert.equal(
resolveSubmitMarketingFlag({ goods: { marketingFlag: 1 } }),
1
)
assert.equal(
resolveSubmitMarketingFlag({ lineItem: { marketingFlag: '1' } }),
1
)
assert.equal(resolveSubmitMarketingFlag({ goods: { marketingFlag: 0 } }), 0)
})
it('resolveSubmitActivityId reads from same sources as marketingFlag', () => {
assert.equal(
resolveSubmitActivityId({ goods: { activityId: 'A100' } }),
'A100'
)
assert.equal(
resolveSubmitActivityId({ lineItem: { activityId: 2001 } }),
2001
)
assert.equal(
resolveSubmitActivityId({ goods: { marketingFlag: 1 } }),
null
)
})
it('appendSubmitActivityId omits field when no active marketing', () => {
const subOrder = {
marketingFlag: resolveSubmitMarketingFlag({ goods: { marketingFlag: 0 } })
}
appendSubmitActivityId(subOrder, {
goods: { marketingFlag: 0, activityId: 'A100' }
})
assert.equal('activityId' in subOrder, false)
})
it('appendSubmitActivityId writes field only for active marketing goods', () => {
const subOrder = {
marketingFlag: 1
}
appendSubmitActivityId(subOrder, {
goods: { marketingFlag: 1, activityId: 'A100' }
})
assert.equal(subOrder.activityId, 'A100')
})
it('resolveSubmitModifyFlag detects price change against catalogSellPrice', () => {
const goods = ensureCatalogUpgradePrice({ sellPrice: 100, upgradePrice: 100 })
assert.equal(resolveSubmitModifyFlag(goods), 0)
goods.sellPrice = 120
goods.basePrice = 120
assert.equal(resolveSubmitModifyFlag(goods), 1)
})
it('resolveSubmitModifyFlag falls back to upgradePrice for singles', () => {
assert.equal(
resolveSubmitModifyFlag({ sellPrice: 100, upgradePrice: 100 }),
0
)
assert.equal(
resolveSubmitModifyFlag({ sellPrice: 90, upgradePrice: 100 }),
1
)
})
it('ensureCatalogUpgradePrice prefers upgradePrice over modified sellPrice', () => {
const goods = ensureCatalogUpgradePrice({
upgradePrice: 100,
sellPrice: 80,
basePrice: 80
})
assert.equal(goods.catalogSellPrice, 100)
assert.equal(resolveSubmitModifyFlag(goods), 1)
})
it('seedMarketingActivitySellPrice prefers catalog price over modified sellPrice', () => {
const goods = seedMarketingActivitySellPrice({
marketingFlag: 1,
activityId: 7,
sellPrice: '0',
price: 99,
catalogSellPrice: 99,
upgradePrice: 99
})
assert.equal(goods.activitySellPrice, 99)
})
it('seedMarketingActivitySellPrice uses catalog goods when provided', () => {
const goods = seedMarketingActivitySellPrice(
{
marketingFlag: 1,
activityId: 7,
sellPrice: '0',
price: 1
},
{ marketingFlag: 1, activityId: 7, sellPrice: 88 }
)
assert.equal(goods.activitySellPrice, 88)
})
})