low-price-order-flow.test.mjs
11.8 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
import assert from 'node:assert/strict'
import { describe, it } from 'node:test'
import { register } from 'node:module'
import {
LOW_PRICE_FLAG,
buildLowPriceMerchantContext,
filterOrderMerchantOptions,
normalizeOrderMerchantOptions
} from '../../components/orderPromptPop/orderMerchantContext.helpers.js'
import {
APPROVAL_STATUS_TABS,
buildApprovalStatusCounts,
resolveApprovalStatusFilter
} from '../../tabWorkOrder/pages/index/services/lowPriceOrder.helpers.js'
import {
applyLowPriceDefaultScene,
buildLowPriceOrderPatch,
mergeLowPriceOrderContext
} from '../../tabWorkOrder/pages/createOrder/services/lowPriceOrderContext.helpers.js'
import { resolveDirectWorkOrderAction } from '../../pages/tab/workspace/services/workOrderEntry.helpers.js'
register(
'./shims/low-price-list-loader.mjs',
import.meta.url
)
describe('低价单下单门店上下文', () => {
it('将园区下的 4S 店数组展开并保留园区归属', () => {
const result = normalizeOrderMerchantOptions([
{
merchantId: 100,
merchantName: '园区甲',
shopMerchantList: [
{ merchantId: 201, merchantName: '4S 店一' },
{ merchantId: 202, merchantName: '4S 店二' }
]
}
])
assert.deepEqual(result, [
{
merchantId: 201,
merchantName: '4S 店一',
yqMerchantId: 100,
yqMerchantName: '园区甲',
key: '100:201'
},
{
merchantId: 202,
merchantName: '4S 店二',
yqMerchantId: 100,
yqMerchantName: '园区甲',
key: '100:202'
}
])
})
it('兼容园区与 4S 店同一行的接口结构并去重', () => {
const result = normalizeOrderMerchantOptions({
list: [
{
merchantId: 100,
merchantName: '园区甲',
shopMerchantId: 201,
shopMerchantName: '4S 店一'
},
{
yqMerchantId: 100,
yqMerchantName: '园区甲',
merchantId: 201,
merchantName: '4S 店一'
}
]
})
assert.equal(result.length, 1)
assert.equal(result[0].merchantId, 201)
assert.equal(result[0].yqMerchantId, 100)
})
it('搜索同时匹配 4S 店与园区名称', () => {
const options = [
{
merchantId: 201,
merchantName: '城南宝马店',
yqMerchantId: 100,
yqMerchantName: '南区园区',
key: '100:201'
},
{
merchantId: 202,
merchantName: '城北奥迪店',
yqMerchantId: 101,
yqMerchantName: '北区园区',
key: '101:202'
}
]
assert.deepEqual(
filterOrderMerchantOptions(options, '宝马').map(item => item.merchantId),
[201]
)
assert.deepEqual(
filterOrderMerchantOptions(options, '北区').map(item => item.merchantId),
[202]
)
})
it('构建普通下单、补录与待补录共用的低价单参数', () => {
const context = buildLowPriceMerchantContext({
merchantId: 201,
merchantName: '4S 店一',
yqMerchantId: 100,
yqMerchantName: '园区甲'
})
assert.equal(LOW_PRICE_FLAG, 1)
assert.deepEqual(context, {
lowPriceFlag: 1,
merchantId: 201,
merchantName: '4S 店一',
yqMerchantId: 100,
yqMerchantName: '园区甲',
sellerMerchantId: 100,
sellerMerchantName: '园区甲'
})
})
})
describe('低价单审批列表适配', () => {
it('使用全部、待审批、已通过、已驳回页签', () => {
assert.deepEqual(APPROVAL_STATUS_TABS, ['全部', '待审批', '已通过', '已驳回'])
assert.equal(resolveApprovalStatusFilter(0), undefined)
assert.equal(resolveApprovalStatusFilter(1), 2)
assert.equal(resolveApprovalStatusFilter(2), 3)
assert.equal(resolveApprovalStatusFilter(3), 4)
})
it('兼容统计接口的新旧字段命名', () => {
assert.deepEqual(
buildApprovalStatusCounts({
totalCount: 12,
pendingCount: 5,
approvedCount: 4,
rejectedCount: 3
}),
[12, 5, 4, 3]
)
assert.deepEqual(
buildApprovalStatusCounts({
allCount: 9,
waitApplyCount: 2,
passCount: 6,
rejectCount: 1
}),
[9, 2, 6, 1]
)
assert.deepEqual(
buildApprovalStatusCounts({
totalCount: 11,
status1Count: 9,
status2Count: 2,
status3Count: 0,
status4Count: 0
}),
[11, 2, 0, 0]
)
})
it('兜底路由在页面加载时应用待审批页签参数', async () => {
let pageConfig
globalThis.Page = config => {
pageConfig = config
}
globalThis.wx = {
$util: {
getUserInfo: () => ({ merchantAccountList: [] })
}
}
await import(
`../../tabWorkOrder/pages/index/index.js?pending-tab=${Date.now()}`
)
const page = {
...pageConfig,
data: { ...pageConfig.data },
setData(patch, callback) {
Object.assign(this.data, patch)
if (callback) callback()
}
}
pageConfig.onLoad.call(page, { activeIndex: '1' })
assert.equal(page.data.activeIndex, 1)
assert.equal(page.data.tabIndex, 1)
assert.equal(page.data.keyword, '')
assert.equal(page.data.searchObj.merchantId, '')
assert.equal(page.data.searchObj.goodsOrderApplyStatus, undefined)
assert.equal(page.data.searchObj.goodsOrderApplyStatusList, undefined)
})
it('切换页签时使用审批状态参数且全部不绑定状态', async () => {
let pageConfig
globalThis.Page = config => {
pageConfig = config
}
globalThis.wx = {
$util: {
getUserInfo: () => ({ merchantAccountList: [] }),
hideLoading() {}
}
}
await import(
`../../tabWorkOrder/pages/index/index.js?status-filter=${Date.now()}`
)
const expectedApprovalStatuses = [undefined, 2, 3, 4]
const capturedPayloads = []
globalThis.__WORK_ORDER_MOCK_API__ = {
getWorkPackageGoodsList(payload) {
capturedPayloads.push(payload)
return { code: 0, data: { list: [], total: 0 } }
}
}
for (const [
tabIndex,
expectedApprovalStatus
] of expectedApprovalStatuses.entries()) {
const page = {
...pageConfig,
data: {
...pageConfig.data,
tabIndex,
searchObj: {
statusList: [99],
goodsOrderApplyStatusList: [99],
goodsOrderApplyStatus: 99
},
userInfo: {},
status: {}
},
setData(patch) {
Object.assign(this.data, patch)
}
}
page.getWorkList()
await new Promise(resolve => setTimeout(resolve, 0))
const payload = capturedPayloads[tabIndex]
assert.equal('statusList' in payload, false)
assert.equal('goodsOrderApplyStatusList' in payload, false)
if (expectedApprovalStatus !== undefined) {
assert.equal(payload.goodsOrderApplyStatus, expectedApprovalStatus)
} else {
assert.equal('goodsOrderApplyStatus' in payload, false)
}
}
delete globalThis.__WORK_ORDER_MOCK_API__
})
it('列表套餐总价使用子项权威总价且不受单价舍入或数量缺失影响', async () => {
let pageConfig
globalThis.Page = config => {
pageConfig = config
}
globalThis.wx = {
$util: {
decimal: value => Number(value),
getUserInfo: () => ({ merchantAccountList: [] }),
hideLoading() {}
}
}
await import(
`../../tabWorkOrder/pages/index/index.js?package-total=${Date.now()}`
)
const order = {
finalPrice: 20,
status: 1,
selectPayType: 2,
subOrderList: [],
packageGoodsList: [
{
packageGoodsOrderList: [
{
finalPrice: 10,
number: 3,
upgradePrice: 3.33,
constructionStatus: 1
}
]
},
{
packageGoodsOrderList: [
{
finalPrice: 10,
upgradePrice: 4,
constructionStatus: 1
}
]
}
]
}
globalThis.__WORK_ORDER_MOCK_API__ = {
getWorkPackageGoodsList() {
return { code: 0, data: { list: [order], total: 1 } }
}
}
const page = {
...pageConfig,
data: {
...pageConfig.data,
keyword: '',
pageNum: 1,
searchObj: {},
status: {},
tabIndex: 0,
userInfo: {}
},
setData() {}
}
pageConfig.getWorkList.call(page)
await new Promise(resolve => setTimeout(resolve, 0))
assert.equal(order.packageGoodsList[0].price, 3.33)
assert.equal(order.packageGoodsList[0].finalPrice, 10)
assert.equal(order.packageGoodsList[1].price, 4)
assert.equal(order.packageGoodsList[1].finalPrice, 10)
delete globalThis.__WORK_ORDER_MOCK_API__
})
})
describe('创建页低价单上下文', () => {
const routeContext = {
lowPriceFlag: '1',
merchantId: '201',
merchantName: '4S 店一',
yqMerchantId: '100',
yqMerchantName: '园区甲',
sellerMerchantId: '100',
sellerMerchantName: '园区甲'
}
it('只从显式路由参数构建上下文', () => {
assert.deepEqual(buildLowPriceOrderPatch(routeContext), {
lowPriceFlag: 1,
djOrderType: 1,
merchantId: '201',
merchantName: '4S 店一',
yqMerchantId: '100',
yqMerchantName: '园区甲',
sellerMerchantId: '100',
sellerMerchantName: '园区甲'
})
assert.deepEqual(buildLowPriceOrderPatch({ lowPriceFlag: 0 }), {})
})
it('合并时保留订单客户信息并以选中门店为准', () => {
const result = mergeLowPriceOrderContext(
{
customer: { customerName: '张三' },
merchantId: 'old-shop',
sellerMerchantId: 'old-park'
},
routeContext
)
assert.equal(result.customer.customerName, '张三')
assert.equal(result.merchantId, '201')
assert.equal(result.sellerMerchantId, '100')
assert.equal(result.lowPriceFlag, 1)
assert.equal(result.djOrderType, 1)
})
it('低价单场景不完整时在页面状态中使用固定精品升级场景', () => {
const result = applyLowPriceDefaultScene({
lowPriceFlag: 1,
baseSceneCode: 'SCENE-FROM-API',
baseSceneName: '',
sceneType: 7,
customer: { customerName: '张三' }
})
assert.deepEqual(result, {
lowPriceFlag: 1,
baseSceneCode: '100101',
baseSceneName: '精品升级',
sceneType: 1,
customer: { customerName: '张三' }
})
})
it('完整低价场景与普通订单场景都不被默认值改写', () => {
const lowPriceOrderObj = {
lowPriceFlag: 1,
baseSceneCode: 'SCENE-FROM-API',
baseSceneName: '接口场景',
sceneType: 7
}
const orderObj = {
lowPriceFlag: 0,
baseSceneCode: 'NORMAL-SCENE',
baseSceneName: '普通场景',
sceneType: 7
}
assert.equal(applyLowPriceDefaultScene(lowPriceOrderObj), lowPriceOrderObj)
assert.equal(applyLowPriceDefaultScene(orderObj), orderObj)
})
})
describe('工作台低价单直达参数', () => {
it('把收款方式和选中门店一起传给后续流程', () => {
assert.deepEqual(
resolveDirectWorkOrderAction({
payFlag: 1,
lowPriceFlag: 1,
merchantId: 201,
merchantName: '4S 店一',
yqMerchantId: 100,
yqMerchantName: '园区甲',
sellerMerchantId: 100,
sellerMerchantName: '园区甲'
}),
{
action: 'navigate',
params: {
paymentMethod: 1,
skipOrderGuards: true,
lowPriceFlag: 1,
merchantId: 201,
merchantName: '4S 店一',
yqMerchantId: 100,
yqMerchantName: '园区甲',
sellerMerchantId: 100,
sellerMerchantName: '园区甲'
}
}
)
})
})