createOrderUserContextIntegration.test.mjs
1.72 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
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
)
test('router init normalizes the operator and merchant fields before submission', async () => {
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: {
getUserInfo: () => ({})
}
}
await import(`../createOrder.js?user-context=${Date.now()}`)
const page = {
data: {
scene: '',
orderObj: {},
workOrderUserContext: null
},
setData(patch) {
Object.assign(this.data, patch)
}
}
const rawUser = {
merchantId: 44211025,
merchantName: '流程测试园区门店',
shopMerchantId: 44210895,
sceneType: 1,
phone: '18372203315',
uuid: 'top-user',
name: 'top-name',
subLoginUser: {
uuid: 'sub-user',
name: 'sub-name'
}
}
pageConfig.init.call(page, rawUser)
assert.deepEqual(page.data.workOrderUserContext, {
sceneType: 1,
phone: '18372203315',
parkMerchantId: 44211025,
shopMerchantId: 44210895,
operatorId: 'sub-user',
operatorName: 'sub-name',
parkMerchantName: '流程测试园区门店'
})
assert.deepEqual(page.data.orderObj, {
sellerMerchantName: '流程测试园区门店',
sellerName: 'sub-name',
sellerMerchantId: 44211025,
sellerUserId: 'sub-user'
})
})