selectOrderCatalogClassification.test.mjs
3.33 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
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import {
SELECT_ORDER_GOODS_FLAG,
isPositionBucketCatalogItem,
classifySelectOrderCatalog,
applySelectOrderCatalogItem,
createEmptyCatalogClassification,
flattenCatalogClassification
} from '../services/selectOrderCatalogClassification.js'
describe('selectOrderCatalogClassification', () => {
it('isPositionBucketCatalogItem is true only for single goods', () => {
assert.equal(
isPositionBucketCatalogItem({ goodsFlag: SELECT_ORDER_GOODS_FLAG.SINGLE }),
true
)
assert.equal(
isPositionBucketCatalogItem({
goodsFlag: SELECT_ORDER_GOODS_FLAG.MULTI_SPEC
}),
false
)
assert.equal(
isPositionBucketCatalogItem({ goodsFlag: SELECT_ORDER_GOODS_FLAG.PACKAGE }),
false
)
})
it('classifySelectOrderCatalog buckets single goods by position', () => {
const result = classifySelectOrderCatalog([
{
goodsFlag: 1,
goods: {
merchantGoodsId: 'a',
merchantGoodsPosition: 1,
sellPrice: 100
}
}
])
assert.equal(result.frontGearArr.length, 1)
assert.equal(result.otherProduct.length, 0)
assert.equal(result.packageList.length, 0)
})
it('classifySelectOrderCatalog puts single goods without position in otherProduct', () => {
const result = classifySelectOrderCatalog([
{
goodsFlag: 1,
goods: { merchantGoodsId: 'b', sellPrice: 50 }
}
])
assert.equal(result.otherProduct.length, 1)
assert.equal(result.frontGearArr.length, 0)
})
it('classifySelectOrderCatalog keeps multi-spec in otherProduct only even with SKU position', () => {
const result = classifySelectOrderCatalog([
{
goodsFlag: 2,
multipleSpecificationsGoods: {
specificationList: [
{
specificationValueList: [{ show: true, specificationValue: 'S' }]
}
],
goods: { merchantGoodsPosition: 1, sellPrice: 80 }
}
}
])
assert.equal(result.otherProduct.length, 1)
assert.equal(result.frontGearArr.length, 0)
assert.equal(result.packageList.length, 0)
})
it('classifySelectOrderCatalog puts package only in packageList', () => {
const result = classifySelectOrderCatalog([
{
goodsFlag: 3,
packageGoods: {
packageName: 'pkg',
goodsList: [{ merchantGoodsId: 'c', sellPrice: 10 }]
}
}
])
assert.equal(result.packageList.length, 1)
assert.equal(result.otherProduct.length, 0)
assert.equal(result.frontGearArr.length, 0)
})
it('applySelectOrderCatalogItem syncs subOrderList position for single goods', () => {
const subOrderList = [
{
merchantGoodsId: 'x',
upgradeGoodsId: 'gid',
upgradeGoodsPosition: 2
}
]
const accum = createEmptyCatalogClassification()
applySelectOrderCatalogItem(
accum,
{
goodsFlag: 1,
goods: {
merchantGoodsId: 'x',
upgradeGoodsId: 'gid',
merchantGoodsPosition: 1,
sellPrice: 1
}
},
{ subOrderList }
)
assert.equal(subOrderList[0].upgradeGoodsPosition, 1)
assert.equal(subOrderList[0].active, true)
assert.equal(flattenCatalogClassification(accum).frontGearArr.length, 1)
})
})