userMerchant.test.mjs
2.9 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
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { createRequire } from 'node:module'
const require = createRequire(import.meta.url)
const {
resolveShopMerchantId,
resolveShopMerchantName,
resolveSaveMerchantId,
normalizeDailyReportUserInfo
} = require('../utils/user-merchant.js')
describe('user-merchant', () => {
it('resolveShopMerchantId prefers shopMerchantId over merchantId', () => {
assert.equal(
resolveShopMerchantId({
shopMerchantId: 1001,
merchantId: 2002
}),
1001
)
})
it('resolves the used-car default 4S store when shopMerchantId is absent', () => {
const userInfo = {
merchantId: 2002,
default4SStoreInfo_usedCar: {
merchantId: 7001,
merchantName: '二手车测试门店'
}
}
assert.equal(resolveShopMerchantId(userInfo), 7001)
assert.equal(resolveShopMerchantName(userInfo), '二手车测试门店')
assert.equal(normalizeDailyReportUserInfo(userInfo).shopMerchantId, 7001)
})
it('normalizeDailyReportUserInfo uses shopMerchantId and shopMerchantName for 4S', () => {
const normalized = normalizeDailyReportUserInfo({
shopMerchantId: 1001,
shopMerchantName: '测试4S店',
merchantId: 2002,
merchantName: '园区店名',
yqMerchantId: 3003,
uuid: 'staff-1',
name: '张三'
})
assert.equal(normalized.merchantId, 1001)
assert.equal(normalized.shopMerchantId, 1001)
assert.equal(normalized.yqMerchantId, 3003)
assert.equal(normalized.staffUuid, 'staff-1')
assert.equal(normalized.shopMerchantName, '测试4S店')
assert.equal(normalized.merchantName, '测试4S店')
assert.equal(normalized.staffName, '张三')
})
it('re-normalize preserves shopMerchantName for pageContext title', () => {
const once = normalizeDailyReportUserInfo({
shopMerchantId: 1001,
shopMerchantName: '崇文4s店A',
merchantId: 2002,
merchantName: '园区店名'
})
const twice = normalizeDailyReportUserInfo(once)
assert.equal(twice.shopMerchantName, '崇文4s店A')
assert.equal(twice.merchantName, '崇文4s店A')
})
it('resolveShopMerchantName prefers shopMerchantName over merchantName', () => {
assert.equal(
resolveShopMerchantName({
shopMerchantName: '4S门店',
merchantName: '园区门店'
}),
'4S门店'
)
})
it('resolveSaveMerchantId ignores pageContext merchantId when it is园区店', () => {
const userContext = normalizeDailyReportUserInfo({
shopMerchantId: 1001,
merchantId: 2002,
yqMerchantId: 3003
})
assert.equal(
resolveSaveMerchantId(userContext, { merchantId: 2002, yqMerchantId: 3003 }),
1001
)
})
it('re-normalize from userContext keeps 4S merchantId via shopMerchantId', () => {
const once = normalizeDailyReportUserInfo({
shopMerchantId: 1001,
merchantId: 2002,
yqMerchantId: 3003
})
const twice = normalizeDailyReportUserInfo(once)
assert.equal(twice.merchantId, 1001)
assert.equal(twice.yqMerchantId, 3003)
})
})