abnormalFlowReport.helpers.test.mjs
10 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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
describe('abnormalFlowReport.helpers', async () => {
const {
ABNORMAL_TYPE_OPTIONS,
SUCCESS_MODAL,
getApprovalStatusStyle,
getRmApprovalStatusStyle,
getBgApprovalStatusStyle,
getBgApprovalStatusText,
getAbnormalTypeLabel,
formatTradeTime,
formatTradeDate,
normalizeVoucherUrls,
validateReportForm,
fenToYuan,
mapUnionCount,
mapPendingListItem,
mapReportedListItem,
mapDetailFromApi,
unwrapRouterQuery
} = await import('../tabWorkOrder/services/abnormalFlowReport.helpers.js')
it('has 7 abnormal type options aligned with swagger', () => {
assert.equal(ABNORMAL_TYPE_OPTIONS.length, 7)
assert.equal(getAbnormalTypeLabel(4), '对公收款')
assert.equal(getAbnormalTypeLabel(5), '混合支付')
})
it('success modal copy matches design', () => {
assert.equal(SUCCESS_MODAL.title, '报备提交成功')
assert.ok(SUCCESS_MODAL.message.includes('审核'))
})
it('maps approval status 1-5 colors', () => {
assert.equal(getApprovalStatusStyle(1).text, '待区域经理审批')
assert.equal(getApprovalStatusStyle(1).color, '#F7A431')
assert.equal(getApprovalStatusStyle(2).color, '#F24724')
assert.equal(getApprovalStatusStyle(5).text, '审批通过')
})
it('bg approval status links with rm round', () => {
assert.equal(getBgApprovalStatusText(3, 3), '待后台审批')
assert.equal(getBgApprovalStatusText(3, ''), '待后台审批')
assert.equal(getBgApprovalStatusText(1, 3), '-')
assert.equal(getBgApprovalStatusText(2, 3), '-')
})
it('rm log status 3 means approved; bg log status 5 means approved', () => {
const rmPending = getRmApprovalStatusStyle(1, 3)
const bgWhileRmPending = getBgApprovalStatusStyle(1, 3)
assert.equal(rmPending.text, '待区域经理审批')
assert.equal(rmPending.color, '#F7A431')
assert.equal(bgWhileRmPending.text, '-')
assert.equal(bgWhileRmPending.background, '#F4F5F7')
const rmApproved = getRmApprovalStatusStyle(3, 3)
const bgPending = getBgApprovalStatusStyle(3, 3)
assert.equal(rmApproved.text, '区域经理已通过')
assert.equal(rmApproved.color, '#35C376')
assert.equal(bgPending.text, '待后台审批')
assert.equal(bgPending.color, '#F7A431')
const bgApproved = getBgApprovalStatusStyle(3, 5)
assert.equal(bgApproved.text, '审批通过')
assert.equal(bgApproved.color, '#35C376')
const rmRejected = getRmApprovalStatusStyle(2, 3)
const bgWhileRmRejected = getBgApprovalStatusStyle(2, 3)
assert.equal(rmRejected.text, '区域经理审批驳回')
assert.equal(rmRejected.color, '#F24724')
assert.equal(bgWhileRmRejected.text, '-')
const bgRejected = getBgApprovalStatusStyle(3, 4)
assert.equal(bgRejected.text, '后台审批驳回')
assert.equal(bgRejected.color, '#F24724')
})
it('validateReportForm requires type and remark', () => {
assert.equal(validateReportForm({}).valid, false)
assert.equal(validateReportForm({ abnormalType: 1 }).valid, false)
assert.equal(
validateReportForm({ abnormalType: 1, remark: '测试备注' }).valid,
true
)
})
it('fenToYuan converts cents', () => {
assert.equal(fenToYuan(152052), 1520.52)
})
it('formatTradeTime normalizes timestamp and date string', () => {
assert.equal(
formatTradeTime('2020-06-12 15:12:52'),
'2020-06-12 15:12:52'
)
const ts = new Date('2020-06-12 15:12:52').getTime()
assert.equal(formatTradeTime(ts), '2020-06-12 15:12:52')
assert.equal(formatTradeTime(''), '')
assert.equal(formatTradeTime(null), '')
})
it('formatTradeDate returns date without time', () => {
assert.equal(formatTradeDate('2020-06-14 18:00:00'), '2020-06-14')
assert.equal(formatTradeDate('2020-02-05'), '2020-02-05')
assert.equal(formatTradeDate(''), '')
assert.equal(formatTradeDate(null), '')
})
it('normalizeVoucherUrls handles array object and comma string', () => {
assert.deepEqual(normalizeVoucherUrls(null), [])
assert.deepEqual(normalizeVoucherUrls(''), [])
assert.deepEqual(normalizeVoucherUrls(['https://a.png', '', 'https://b.png']), [
'https://a.png',
'https://b.png'
])
assert.deepEqual(
normalizeVoucherUrls([
{ url: 'https://c.png' },
{ imageUrl: 'https://d.png' },
{ voucherImageUrl: 'https://e.png' }
]),
['https://c.png', 'https://d.png', 'https://e.png']
)
assert.deepEqual(
normalizeVoucherUrls('https://f.png, https://g.png'),
['https://f.png', 'https://g.png']
)
})
it('mapUnionCount reads tab totals', () => {
assert.deepEqual(
mapUnionCount({
totalCount: 10,
notDeclaredCount: 4,
declaredCount: 6
}),
{ notDeclaredCount: 4, declaredCount: 6, totalCount: 10 }
)
})
it('mapPendingListItem maps union.page fields', () => {
const item = mapPendingListItem({
outTradeNo: 'PAY1',
tradeNo: 'TN1',
totalFee: 10000,
accountDate: '2020-06-12 15:12:52',
shopMerchantName: '门店A'
})
assert.equal(item.outTradeNo, 'PAY1')
assert.equal(item.tradeRefNo, 'TN1')
assert.equal(item.payAmount, 100)
assert.equal(item.merchantName, '门店A')
assert.equal(item.tradeTime, '2020-06-12 15:12:52')
assert.equal(item.statusStyle.text, '待报备')
})
it('mapReportedListItem maps declaration.page fields', () => {
const item = mapReportedListItem({
id: 9,
tradeNo: 'TN2',
totalPrice: 88.8,
accountDate: '2020-01-01',
merchantName: '门店B',
approvalStatus: 1
})
assert.equal(item.id, 9)
assert.equal(item.statusStyle.text, '待区域经理审批')
})
it('unwrapRouterQuery flattens router params wrapper', () => {
assert.deepEqual(unwrapRouterQuery({ params: { id: 1001 } }), {
params: { id: 1001 },
id: 1001
})
assert.deepEqual(unwrapRouterQuery({ id: 9 }), { id: 9 })
})
it('mapDetailFromApi splits approval logs by source', () => {
const detail = mapDetailFromApi({
tradeInfo: {
tradeNo: 'TN3',
totalPrice: 12,
payDate: '2020-02-02',
merchantName: '店C'
},
declarationInfo: {
abnormalType: 1,
remark: '备注',
createdBy: '张三',
createdDate: '2020-02-03',
voucherImageUrls: ['https://a.png']
},
approvalLogs: [
{
approvalSource: 0,
approvalStatus: 1,
operatorName: '经理',
createdDate: '2020-02-04',
remark: '一审'
},
{
approvalSource: 1,
approvalStatus: 3,
operatorName: '',
createdDate: '',
remark: ''
}
]
})
assert.equal(detail.tradeRefNo, 'TN3')
assert.equal(detail.abnormalTypeText, '已付款未录单')
assert.equal(detail.tradeTime, '2020-02-02 08:00:00')
assert.equal(detail.reportTime, '2020-02-03 08:00:00')
assert.equal(detail.rmApprover, '经理')
assert.equal(detail.rmApproveTime, '2020-02-04 08:00:00')
assert.equal(detail.rmStatusStyle.text, '待区域经理审批')
assert.equal(detail.bgApproveTime, '')
assert.equal(detail.bgStatusStyle.text, '-')
assert.equal(detail.vouchers.length, 1)
})
it('mapDetailFromApi maps voucherImageUrls and empty list', () => {
const withUrls = mapDetailFromApi({
declarationInfo: {
abnormalType: 1,
remark: '备注',
voucherImageUrls: [{ url: 'https://a.png' }, 'https://b.png']
}
})
assert.deepEqual(withUrls.vouchers, ['https://a.png', 'https://b.png'])
const empty = mapDetailFromApi({
declarationInfo: { abnormalType: 1, remark: '无凭证' }
})
assert.deepEqual(empty.vouchers, [])
})
it('mapDetailFromApi treats rm log status 3 as rm approved', () => {
const detail = mapDetailFromApi({
declarationInfo: { abnormalType: 1, remark: 'x', approvalStatus: 5 },
approvalLogs: [
{
approvalSource: 0,
approvalStatus: 3,
operatorName: '何穗',
createdDate: '2020-02-04',
remark: '同意'
},
{
approvalSource: 1,
approvalStatus: 5,
operatorName: '总部',
createdDate: '2020-02-05',
remark: '通过'
}
]
})
assert.equal(detail.rmStatusStyle.text, '区域经理已通过')
assert.equal(detail.bgStatusStyle.text, '审批通过')
})
it('mapDetailFromApi maps declarationInfo.delayDeadline', () => {
const withDeadline = mapDetailFromApi({
declarationInfo: {
abnormalType: 1,
remark: 'x',
delayDeadline: '2020-02-05'
}
})
assert.equal(withDeadline.delayDeadline, '2020-02-05')
const without = mapDetailFromApi({
declarationInfo: { abnormalType: 1, remark: 'x' }
})
assert.equal(without.delayDeadline, '')
})
it('mapDetailFromApi falls back to declarationInfo.approvalStatus when logs missing', () => {
const rmPending = mapDetailFromApi({
declarationInfo: { abnormalType: 1, remark: 'x', approvalStatus: 1 }
})
assert.equal(rmPending.rmStatusStyle.text, '待区域经理审批')
assert.equal(rmPending.bgStatusStyle.text, '-')
const bgPending = mapDetailFromApi({
declarationInfo: { abnormalType: 1, remark: 'x', approvalStatus: 3 }
})
assert.equal(bgPending.rmStatusStyle.text, '区域经理已通过')
assert.equal(bgPending.bgStatusStyle.text, '待后台审批')
})
it('mapDetailFromApi prefers approvalLogs over declarationInfo.approvalStatus', () => {
const detail = mapDetailFromApi({
declarationInfo: { abnormalType: 1, remark: 'x', approvalStatus: 1 },
approvalLogs: [
{
approvalSource: 0,
approvalStatus: 2,
operatorName: '经理',
createdDate: '2020-02-04',
remark: '驳回'
}
]
})
assert.equal(detail.rmStatusStyle.text, '区域经理审批驳回')
assert.equal(detail.rmApprover, '经理')
})
})