workOrderUserContext.test.mjs
2.36 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
import assert from 'node:assert/strict'
import test from 'node:test'
import {
createWorkOrderUserContext,
getWorkOrderUserContext
} from '../services/workOrderUserContext.js'
test('separates park and shop identities while preferring the sub-login operator', () => {
const context = createWorkOrderUserContext({
merchantId: 44211025,
shopMerchantId: 44210895,
sceneType: 1,
phone: '18372203315',
merchantName: '流程测试园区门店',
uuid: 'top-user',
name: 'top-name',
subLoginUser: {
uuid: 'sub-user',
name: 'sub-name',
sceneType: 7
}
})
assert.deepEqual(context, {
sceneType: 1,
phone: '18372203315',
parkMerchantId: 44211025,
shopMerchantId: 44210895,
operatorId: 'sub-user',
operatorName: 'sub-name',
parkMerchantName: '流程测试园区门店'
})
})
test('falls back to sub-login and default shop fields when top-level values are absent', () => {
const context = createWorkOrderUserContext({
subLoginUser: {
merchantId: 9001,
shopMerchantId: '',
phone: '18800001111',
uuid: 'sub-user',
name: 'sub-name',
merchantName: '子账号园区'
},
default4SStoreInfo: {
merchantId: 9002
}
})
assert.deepEqual(context, {
sceneType: '',
phone: '18800001111',
parkMerchantId: 9001,
shopMerchantId: 9002,
operatorId: 'sub-user',
operatorName: 'sub-name',
parkMerchantName: '子账号园区'
})
})
test('returns a complete empty context for a missing user', () => {
assert.deepEqual(createWorkOrderUserContext(null), {
sceneType: '',
phone: '',
parkMerchantId: '',
shopMerchantId: '',
operatorId: '',
operatorName: '',
parkMerchantName: ''
})
})
test('reads the raw user once through the injectable runtime boundary', () => {
let readCount = 0
const context = getWorkOrderUserContext(() => {
readCount += 1
return {
merchantId: 7100,
shopMerchantId: 7200,
sceneType: 1,
phone: '18812345678',
merchantName: '测试园区',
uuid: 'operator-1',
name: '测试员工'
}
})
assert.equal(readCount, 1)
assert.deepEqual(context, {
sceneType: 1,
phone: '18812345678',
parkMerchantId: 7100,
shopMerchantId: 7200,
operatorId: 'operator-1',
operatorName: '测试员工',
parkMerchantName: '测试园区'
})
})