merchantStaffSelection.test.mjs
6.67 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
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import * as merchantStaffHelpers from '../services/merchantStaffSelection.helpers.js'
import {
STAFF_MODE,
applySystemStaffFallbackIfNeeded,
buildOrderPatch,
buildSalesSingleMerchantDefault,
getPickerLabels,
hasStaffConflict,
shouldEchoSystemStaff,
shouldUseSystemStaffFallback,
updateMerchantSelection,
updateStaffSelection
} from '../services/merchantStaffSelection.helpers.js'
describe('merchantStaffSelection', () => {
it('buildOrderPatch maps sales fields', () => {
const patch = buildOrderPatch(
STAFF_MODE.SALES,
{ merchantId: 'm1', merchantName: '门店A' },
{ uuid: 'u1', staffName: '张三' }
)
assert.deepEqual(patch, {
merchantId: 'm1',
merchantName: '门店A',
userId: 'u1',
employeeName: '张三'
})
})
it('buildOrderPatch normalizes raw sales staff fields at the write boundary', () => {
const patch = buildOrderPatch(
STAFF_MODE.SALES,
{ merchantId: 'm1', merchantName: '门店A' },
{
uuid: '',
userId: 'u-raw-1',
name: '原始接口销售顾问'
}
)
assert.deepEqual(patch, {
merchantId: 'm1',
merchantName: '门店A',
userId: 'u-raw-1',
employeeName: '原始接口销售顾问'
})
})
it('buildOrderPatch maps conversion fields', () => {
const patch = buildOrderPatch(
STAFF_MODE.CONVERSION,
{ merchantId: 'yq1', merchantName: '园区店' },
{ uuid: 's1', staffName: '李四' }
)
assert.deepEqual(patch, {
sellerMerchantId: 'yq1',
sellerMerchantName: '园区店',
sellerUserId: 's1',
sellerName: '李四'
})
})
it('getPickerLabels adjusts sales title for points multi role', () => {
const labels = getPickerLabels(STAFF_MODE.SALES, 'Y')
assert.equal(labels.popupTitle, '销售顾问/录单员')
assert.equal(labels.staffTitle, '选择销售顾问/录单员')
})
it('hasStaffConflict blocks same person for sales and delivery', () => {
const orderObj = { deliveryUserId: 'u2', userId: 'u1' }
assert.equal(hasStaffConflict(STAFF_MODE.SALES, orderObj, 'u2'), true)
assert.equal(hasStaffConflict(STAFF_MODE.DELIVERY, orderObj, 'u1'), true)
assert.equal(hasStaffConflict(STAFF_MODE.CONVERSION, orderObj, 'u1'), false)
})
it('updateMerchantSelection marks only selected merchant active', () => {
const list = updateMerchantSelection(
[
{ merchantId: 'm1', merchantName: 'A', active: true },
{ merchantId: 'm2', merchantName: 'B', active: false }
],
'm2'
)
assert.equal(list[0].active, false)
assert.equal(list[1].active, true)
})
it('buildSalesSingleMerchantDefault uses system staff when list empty', () => {
const patch = buildSalesSingleMerchantDefault(
[{ merchantId: 'm1', merchantName: '唯一门店' }],
[]
)
assert.equal(patch.merchantId, 'm1')
assert.equal(patch.userId, -1)
assert.equal(patch.employeeName, '系统')
})
it('updateStaffSelection marks only selected staff active', () => {
const list = updateStaffSelection(
[
{ uuid: 'u1', staffName: 'A', active: true },
{ uuid: 'u2', staffName: 'B', active: false }
],
'u2'
)
assert.equal(list[0].active, false)
assert.equal(list[1].active, true)
})
it('shouldUseSystemStaffFallback requires single merchant and empty order merchant', () => {
const context = {
orderObj: {},
orderCreateType: 'createdOrder',
merchantList: [{ merchantId: 'm1' }]
}
assert.equal(shouldUseSystemStaffFallback(STAFF_MODE.SALES, context), true)
assert.equal(
shouldUseSystemStaffFallback(STAFF_MODE.SALES, {
...context,
merchantList: [{ merchantId: 'm1' }, { merchantId: 'm2' }]
}),
false
)
assert.equal(
shouldUseSystemStaffFallback(STAFF_MODE.SALES, {
...context,
orderObj: { merchantId: 'm1' }
}),
false
)
assert.equal(
shouldUseSystemStaffFallback(STAFF_MODE.SALES, {
...context,
orderCreateType: 'additionRecordOrder'
}),
false
)
})
it('applySystemStaffFallbackIfNeeded injects system for empty staff list', () => {
const result = applySystemStaffFallbackIfNeeded(STAFF_MODE.SALES, [], {
orderObj: {},
orderCreateType: 'createdOrder',
merchantList: [{ merchantId: 'm1' }]
})
assert.equal(result.length, 1)
assert.equal(result[0].uuid, -1)
assert.equal(result[0].staffName, '系统')
})
it('applySystemStaffFallbackIfNeeded does not inject system during search', () => {
const result = applySystemStaffFallbackIfNeeded(STAFF_MODE.SALES, [], {
orderObj: {},
orderCreateType: 'createdOrder',
merchantList: [{ merchantId: 'm1' }],
keyWord: '张三'
})
assert.deepEqual(result, [])
})
it('shouldEchoSystemStaff detects userId -1', () => {
assert.equal(
shouldEchoSystemStaff(STAFF_MODE.SALES, { userId: -1 }),
true
)
assert.equal(
shouldEchoSystemStaff(STAFF_MODE.SALES, { userId: 'u1' }),
false
)
})
it('applySystemStaffFallbackIfNeeded echoes system staff for userId -1', () => {
const result = applySystemStaffFallbackIfNeeded(STAFF_MODE.SALES, [], {
orderObj: { userId: -1, merchantId: 'm1' },
orderCreateType: 'createdOrder',
merchantList: [{ merchantId: 'm1' }, { merchantId: 'm2' }]
})
assert.equal(result[0].staffName, '系统')
})
it('低价单销售顾问使用前一步选中的园区店和 4S 店', () => {
assert.equal(
typeof merchantStaffHelpers.resolveStaffMerchantScope,
'function',
'尚未实现 resolveStaffMerchantScope'
)
const scope = merchantStaffHelpers.resolveStaffMerchantScope(
{
lowPriceFlag: 1,
merchantId: 44210999,
yqMerchantId: 44211999,
sellerMerchantId: 44211999
},
{
parkMerchantId: 44211025,
shopMerchantId: 44210895
}
)
assert.deepEqual(scope, {
parkMerchantId: 44211999,
shopMerchantId: 44210999
})
})
it('非低价单销售顾问继续使用原用户门店上下文', () => {
assert.equal(
typeof merchantStaffHelpers.resolveStaffMerchantScope,
'function',
'尚未实现 resolveStaffMerchantScope'
)
const scope = merchantStaffHelpers.resolveStaffMerchantScope(
{
merchantId: 44210999,
sellerMerchantId: 44211999
},
{
parkMerchantId: 44211025,
shopMerchantId: 44210895
}
)
assert.deepEqual(scope, {
parkMerchantId: 44211025,
shopMerchantId: 44210895
})
})
})