goodsPriceEcho.integration.test.mjs
3.86 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import assert from 'node:assert/strict'
import { register } from 'node:module'
import test from 'node:test'
register(
'../../../../tests/work-order-migration/shims/create-order-context-loader.mjs',
import.meta.url
)
let pageConfig
globalThis.getApp = () => ({ globalData: {} })
globalThis.Page = config => {
pageConfig = config
}
globalThis.wx = {
getAccountInfoSync: () => ({
miniProgram: { appId: 'test-app-id', envVersion: 'develop' }
}),
getSystemInfoSync: () => ({ platform: 'devtools' }),
getStorageSync: () => '',
$util: {
decimal(value, fixed) {
const pow = Math.pow(10, fixed)
return Math.round(Number(value) * pow) / pow
},
getUserInfo: () => ({})
}
}
await import(`../createOrder.js?goods-price-echo=${Date.now()}`)
function createPage(resetOrder) {
const catalog = [
{
goodsFlag: 1,
goods: { merchantGoodsId: 'NORMAL-1', sellPrice: 2000 }
},
{
goodsFlag: 2,
multipleSpecificationsGoods: {
id: 'SPEC-1',
specificationGoodsMap: {
'A;~;B': [{ merchantGoodsId: 'SKU-1', sellPrice: 2000 }]
}
}
}
]
const orderObj = {
lowPriceFlag: 1,
resetOrder,
subOrderList: [
{
merchantGoodsId: 'NORMAL-1',
number: 5,
totalPrice: 9999.95,
price: resetOrder ? undefined : 1999.9900000000002
},
{
merchantGoodsId: 'SKU-1',
number: 5,
totalPrice: 9999.95,
price: resetOrder ? undefined : 1999.9900000000002,
specificationData: 'A;~;B'
}
],
packageGoodsList: [
{
packageCode: 'PACKAGE-1',
packageName: '精度测试套餐',
packageGoodsOrderList: [
{
merchantGoodsId: 'PACKAGE-GOODS-1',
number: 5,
totalPrice: 9999.95,
sellPrice: resetOrder ? undefined : 1999.9900000000002
}
]
}
]
}
return {
...pageConfig,
data: {
...structuredClone(pageConfig.data),
orderObj,
goodsData: catalog,
copyGoodsData: catalog,
packageList: [],
positionTypeList: [],
marketingFlagMap: {},
activityIdMap: {}
},
setData(patch, callback) {
Object.assign(this.data, patch)
callback?.()
},
setGoodsTotal(goodsList) {
this.data.goodsList = goodsList
}
}
}
test('待跟进回显时普通商品、多规格和套餐子项单价都归一到分', () => {
for (const resetOrder of [false, true]) {
const page = createPage(resetOrder)
pageConfig.getChooseList.call(page)
const ordinary = page.data.goodsList.find(item => item.goodsFlag === 1)
const multiSpec = page.data.goodsList.find(item => item.goodsFlag === 2)
const packageItem = page.data.goodsList.find(item => item.goodsFlag === 3)
assert.equal(ordinary.goods.sellPrice, 1999.99, `ordinary reset=${resetOrder}`)
assert.equal(
multiSpec.multipleSpecificationsGoods.goods.sellPrice,
1999.99,
`multi-spec reset=${resetOrder}`
)
assert.equal(
packageItem.packageGoods.goodsList[0].sellPrice,
1999.99,
`package reset=${resetOrder}`
)
}
})
test('套餐子项缺少 sellPrice 时按总价和数量回退回显,且不误判为 0', () => {
for (const missingSellPrice of [null, '']) {
const page = createPage(false)
const packageChild =
page.data.orderObj.packageGoodsList[0].packageGoodsOrderList[0]
packageChild.sellPrice = missingSellPrice
pageConfig.getChooseList.call(page)
const packageItem = page.data.goodsList.find(item => item.goodsFlag === 3)
assert.equal(
packageItem.packageGoods.goodsList[0].sellPrice,
1999.99,
`sellPrice=${JSON.stringify(missingSellPrice)}`
)
assert.equal(
packageItem.packageGoods.upgradePrice,
1999.99,
`upgradePrice sellPrice=${JSON.stringify(missingSellPrice)}`
)
}
})