merchantStaffSelection.test.mjs
4.94 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
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
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 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, '系统')
})
})