selectOrderCatalogPreprocess.test.mjs
1.95 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
import { register } from 'node:module'
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
register(
'../../../../tests/work-order-migration/shims/resolve-tilde-loader.mjs',
import.meta.url
)
const { preprocessSelectOrderCatalogItem } = await import(
'../services/selectOrderCatalogPreprocess.js'
)
const { SELECT_ORDER_GOODS_FLAG } = await import(
'../services/selectOrderCatalogClassification.js'
)
describe('selectOrderCatalogPreprocess', () => {
it('IT-WO-PRE-001: single goods seeds price fields', () => {
const item = {
goodsFlag: SELECT_ORDER_GOODS_FLAG.SINGLE,
goods: { sellPrice: 100, merchantGoodsId: 1, position: '前挡' }
}
preprocessSelectOrderCatalogItem(item)
assert.equal(item.goods.price, 100)
assert.equal(item.goods.goodsId, 1)
assert.equal(item.goods.positionStr, '前挡')
})
it('IT-WO-PRE-002: multi-spec builds specificationSelectValueList', () => {
const item = {
goodsFlag: SELECT_ORDER_GOODS_FLAG.MULTI_SPEC,
multipleSpecificationsGoods: {
goods: { sellPrice: 50 },
specificationList: [
{
specificationValueList: [
{ show: true, specificationValue: 'L' },
{ show: false, specificationValue: 'M' }
]
}
]
}
}
preprocessSelectOrderCatalogItem(item)
assert.deepEqual(
item.multipleSpecificationsGoods.specificationList[0]
.specificationSelectValueList,
['L']
)
})
it('IT-WO-PRE-003: package preprocesses child goods', () => {
const item = {
goodsFlag: SELECT_ORDER_GOODS_FLAG.PACKAGE,
packageGoods: {
goodsList: [{ sellPrice: 10, merchantGoodsId: 2 }]
}
}
preprocessSelectOrderCatalogItem(item)
assert.equal(item.packageGoods.goodsList[0].merchantGoodsId, 2)
})
it('IT-WO-PRE-004: null item no-op', () => {
assert.doesNotThrow(() => preprocessSelectOrderCatalogItem(null))
})
})