dailyReportInconsistency.helpers.test.mjs
2.69 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
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import {
isStaffCountInconsistent,
findInconsistentBrandField,
hasExistingInputErrors,
buildBrandCheckWarningLines,
STAFF_DAILY_FIELD_KEYS
} from '../services/dailyReportInconsistency.helpers.js'
const userInfo = { uuid: 'user-b' }
const orderObjBase = {
lastStaffUuid: 'user-a',
lastStaffName: '张三',
recordStaffCount: 3
}
const fieldMeta = [{ key: 'deliveryCount', label: '店端实际交车数' }]
describe('dailyReportInconsistency.helpers', () => {
it('isStaffCountInconsistent returns true when staff count differs', () => {
assert.equal(
isStaffCountInconsistent(
{ ...orderObjBase, staffCount: 5 },
userInfo,
() => false
),
true
)
})
it('isStaffCountInconsistent returns false when can skip validation', () => {
assert.equal(
isStaffCountInconsistent(
{ ...orderObjBase, staffCount: 5 },
userInfo,
() => true
),
false
)
})
it('findInconsistentBrandField finds first mismatched field', () => {
const result = findInconsistentBrandField({
carBandList: [{ deliveryCount: 2, deliveryCountRecord: 1 }],
orderObj: orderObjBase,
userInfo,
fieldMeta,
canSkipValidation: () => false
})
assert.deepEqual(result, {
index: 0,
name: 'deliveryCount',
label: '店端实际交车数'
})
})
it('hasExistingInputErrors detects staffCountError and inputError flags', () => {
assert.equal(
hasExistingInputErrors({
orderObj: { staffCountError: true },
carBandList: []
}),
true
)
assert.equal(
hasExistingInputErrors({
orderObj: {},
carBandList: [{ deliveryCountinputError: true }]
}),
true
)
assert.equal(
hasExistingInputErrors({
orderObj: {},
carBandList: [{ deliveryCount: 1 }]
}),
false
)
})
it('buildBrandCheckWarningLines returns one line per failed brand', () => {
const lines = buildBrandCheckWarningLines([
{ isCheckPass: true, brandName: '问界' },
{ isCheckPass: false, brandName: '鸿蒙', differenceValue: 2 }
])
assert.equal(lines.length, 1)
assert.match(lines[0], /【鸿蒙】/)
assert.match(lines[0], /差异值2/)
})
it('findInconsistentBrandField uses staffDaily field keys', () => {
assert.ok(STAFF_DAILY_FIELD_KEYS.includes('extendedWarrantyToShopCount'))
const result = findInconsistentBrandField({
carBandList: [
{ extendedWarrantyToShopCount: 2, extendedWarrantyToShopCountRecord: 1 }
],
orderObj: orderObjBase,
userInfo,
fieldMeta: [{ key: 'extendedWarrantyToShopCount', label: '延保到店流量' }],
canSkipValidation: () => false,
fieldKeys: STAFF_DAILY_FIELD_KEYS
})
assert.equal(result?.name, 'extendedWarrantyToShopCount')
})
})