orderSettingMerchantContext.test.mjs
3.53 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
import assert from 'node:assert/strict'
import { register } from 'node:module'
import test from 'node:test'
import { loadMiniProgramApi } from '../../../../tests/order-lifecycle/support/loadMiniProgramApi.mjs'
register(
'../../../../tests/work-order-migration/shims/create-order-context-loader.mjs',
import.meta.url
)
test('order settings use the selected 4S store and normalize its employee-app settings', async () => {
const app = {
globalData: {
YQorderSetting: { marker: 'wrong-cache' },
YQorderSettingMerchantId: 999,
YQorderSettingYqMerchantId: 100
}
}
const requests = []
globalThis.getApp = () => app
globalThis.wx = {
getAccountInfoSync: () => ({
miniProgram: { appId: 'test-app-id', envVersion: 'develop' }
}),
getSystemInfoSync: () => ({ platform: 'devtools' }),
getStorageSync: () => '',
setStorageSync: () => {},
removeStorageSync: () => {},
$util: {
getUserInfo: () => ({
shopMerchantId: 888,
subLoginUser: { merchantId: 777, merchantName: '登录园区店' }
}),
showLoading: () => {},
hideLoading: () => {}
}
}
globalThis.__WORK_ORDER_MOCK_API__ = {
getMerchantRecordingSettings(params) {
requests.push(params)
return {
code: 0,
data: {
orderFieldSettingList: [
{ fieldKey: 'carBrand', isRequired: true },
{ fieldKey: 'carNo', isRequired: false },
{ fieldKey: 'plateNo', isRequired: false },
{ fieldKey: 'customerPhone', isRequired: false }
],
yqPhoneConfig: JSON.stringify([
{
yqMerchantId: 100,
shopMerchantPhoneList: [{ shopMerchantId: 44210895 }]
},
{
yqMerchantId: 200,
shopMerchantPhoneList: [{ shopMerchantId: 20001 }]
}
])
}
}
}
}
const { getYQorderInfo } = await import(
`../../../../store/index.js?selected-order-setting=${Date.now()}`
)
const result = await getYQorderInfo({
shopMerchantId: 44210895,
shopMerchantName: '波波的单店门店',
yqMerchantId: 100
})
assert.deepEqual(requests, [{ scene: 1, merchantId: 44210895 }])
assert.equal(result.carTypeRequiredFlag, 'Y')
assert.equal(result.standNoRequiredFlag, 'N')
assert.equal(result.plateNumRequiredFlag, 'N')
assert.equal(result.customerPhoneRequiredFlag, 'N')
assert.deepEqual(result.yqPhoneConfig, [{ shopMerchantId: 44210895 }])
assert.equal(app.globalData.YQorderSettingMerchantId, 44210895)
assert.equal(app.globalData.YQorderSettingYqMerchantId, 100)
assert.equal(app.globalData.YQorderSetting.plateNumRequiredFlag, 'N')
await getYQorderInfo({ shopMerchantId: 44210895, yqMerchantId: 100 })
assert.equal(requests.length, 1)
const switchedParkResult = await getYQorderInfo({
shopMerchantId: 44210895,
yqMerchantId: 200
})
assert.equal(requests.length, 2)
assert.deepEqual(switchedParkResult.yqPhoneConfig, [
{ shopMerchantId: 20001 }
])
})
test('the order-settings API forwards to the employee-app light-change endpoint', async () => {
const calls = []
const api = await loadMiniProgramApi('api/api.js', {
post(method, payload) {
calls.push({ method, payload })
return Promise.resolve({ code: 0, data: {} })
}
})
const payload = { scene: 1, merchantId: 44210895 }
await api.getMerchantRecordingSettings(payload)
assert.deepEqual(calls, [
{
method: 'dj.api.smartcarlife.order.field.lightChange.setting.list',
payload
}
])
})