dailyReportCarBrand.test.mjs
2.39 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
import { describe, it, beforeEach } from 'node:test'
import assert from 'node:assert/strict'
import { createRequire } from 'node:module'
const require = createRequire(import.meta.url)
const {
normalizeCarBrandListForSave,
normalizeSceneCodeListToSceneList,
fetchDailyReportCarBrandList,
clearDailyReportCarBrandCache,
__setStaffDailyReportCarBrand
} = require('../api/dailyReportCarBrand.js')
describe('dailyReportCarBrand', () => {
beforeEach(() => {
clearDailyReportCarBrandCache()
__setStaffDailyReportCarBrand(null)
})
it('normalizeCarBrandListForSave maps four fields', () => {
const list = normalizeCarBrandListForSave([
{
firstBrandId: 3454,
firstBrandName: '问界',
brandId: 3454,
brandName: 'AITO',
brandType: 0
}
])
assert.deepEqual(list, [
{
firstBrandId: 3454,
firstBrandName: '问界',
brandId: 3454,
brandName: 'AITO'
}
])
})
it('normalizeCarBrandListForSave uses firstBrandName when brandId is -1', () => {
const list = normalizeCarBrandListForSave([
{
firstBrandId: 999,
firstBrandName: '自定义品牌',
brandId: -1,
brandName: ''
}
])
assert.equal(list[0].brandName, '自定义品牌')
})
it('normalizeSceneCodeListToSceneList converts string codes', () => {
assert.deepEqual(normalizeSceneCodeListToSceneList(['110201', '100101']), [
{ baseSceneCode: 110201 },
{ baseSceneCode: 100101 }
])
})
it('normalizeSceneCodeListToSceneList converts scene objects', () => {
assert.deepEqual(
normalizeSceneCodeListToSceneList([
{ baseSceneCode: '110201', name: '售前延保' },
{ baseSceneCode: 100101, name: '精品' }
]),
[{ baseSceneCode: 110201 }, { baseSceneCode: 100101 }]
)
})
it('fetchDailyReportCarBrandList uses mock fixture when useMock', async () => {
const res = await fetchDailyReportCarBrandList({
merchantId: 'm1',
sceneType: 1,
useMock: true
})
assert.equal(res.code, 0)
assert.equal(res.data.length, 2)
})
it('fetchDailyReportCarBrandList caches by merchantId and sceneType', async () => {
let calls = 0
__setStaffDailyReportCarBrand(async () => {
calls += 1
return {
code: 0,
data: [{ firstBrandId: 1, firstBrandName: 'A', brandId: 1, brandName: 'A' }]
}
})
await fetchDailyReportCarBrandList({ merchantId: 'm1', sceneType: 0 })
await fetchDailyReportCarBrandList({ merchantId: 'm1', sceneType: 0 })
assert.equal(calls, 1)
})
})