dailyReportWeeklyList.test.mjs
4.82 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
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 { DAILY_REPORT_TEMPLATE_TYPE } = require('../config/dailyReportConstants.js')
const staffAdapters = require('../api/staffDailyReportAdapters.js')
const storeAdapters = require('../api/storeDailyReportAdapters.js')
const negotiationAdapters = require('../api/negotiationDailyReportAdapters.js')
const {
STAFF_DAILY_API_SWITCH,
STORE_DAILY_API_SWITCH,
NEGOTIATION_DAILY_API_SWITCH
} = require('../config/apiSwitch.js')
describe('dailyReportWeeklyList adapters', () => {
beforeEach(() => {
staffAdapters.__setDynamicDailyReportApi(null)
storeAdapters.__setDynamicDailyReportApi(null)
negotiationAdapters.__setDynamicDailyReportApi(null)
})
it('fetchWeeklyAdapter staff real mode calls dailyReportWeeklyList with templateType=1', async () => {
const original = STAFF_DAILY_API_SWITCH.weekly
STAFF_DAILY_API_SWITCH.weekly = 'real'
let captured = null
staffAdapters.__setDynamicDailyReportApi({
dailyReportWeeklyList: async data => {
captured = data
return { code: 0, message: 'ok', data: ['2026-05-26'] }
}
})
try {
const res = await staffAdapters.fetchWeeklyAdapter({
merchantId: 1001,
staffUuid: 'uuid-1',
sceneType: 1,
reportStartDate: '2026-05-20',
reportEndDate: '2026-05-26'
})
assert.equal(captured.merchantId, 1001)
assert.equal(captured.staffUuid, 'uuid-1')
assert.equal(captured.sceneType, 1)
assert.equal(captured.templateType, DAILY_REPORT_TEMPLATE_TYPE.staff)
assert.equal(captured.reportStartDate, '2026-05-20')
assert.equal(captured.reportEndDate, '2026-05-26')
assert.deepEqual(res.data, ['2026-05-26'])
} finally {
staffAdapters.__setDynamicDailyReportApi(null)
STAFF_DAILY_API_SWITCH.weekly = original
}
})
it('fetchWeeklyAdapter store real mode uses templateType=2', async () => {
const original = STORE_DAILY_API_SWITCH.weekly
STORE_DAILY_API_SWITCH.weekly = 'real'
let captured = null
storeAdapters.__setDynamicDailyReportApi({
dailyReportWeeklyList: async data => {
captured = data
return { code: 0, message: 'ok', data: ['2026-05-25'] }
}
})
try {
const res = await storeAdapters.fetchWeeklyAdapter({
merchantId: 2002,
staffUuid: 'uuid-2',
reportStartDate: '2026-05-20',
reportEndDate: '2026-05-26',
templateType: DAILY_REPORT_TEMPLATE_TYPE.store
})
assert.equal(captured.templateType, 2)
assert.deepEqual(res.data, ['2026-05-25'])
} finally {
storeAdapters.__setDynamicDailyReportApi(null)
STORE_DAILY_API_SWITCH.weekly = original
}
})
it('fetchWeeklyAdapter negotiation real mode uses templateType=3', async () => {
const original = NEGOTIATION_DAILY_API_SWITCH.weekly
NEGOTIATION_DAILY_API_SWITCH.weekly = 'real'
let captured = null
negotiationAdapters.__setDynamicDailyReportApi({
dailyReportWeeklyList: async data => {
captured = data
return { code: 0, message: 'ok', data: ['2026-05-24'] }
}
})
try {
const res = await negotiationAdapters.fetchWeeklyAdapter({
merchantId: 3003,
staffUuid: 'uuid-3',
reportStartDate: '2026-05-20',
reportEndDate: '2026-05-26'
})
assert.equal(captured.merchantId, 3003)
assert.equal(captured.staffUuid, 'uuid-3')
assert.equal(captured.templateType, DAILY_REPORT_TEMPLATE_TYPE.negotiation)
assert.equal(captured.templateType, 3)
assert.deepEqual(res.data, ['2026-05-24'])
} finally {
negotiationAdapters.__setDynamicDailyReportApi(null)
NEGOTIATION_DAILY_API_SWITCH.weekly = original
}
})
it('fetchWeeklyAdapter mock mode returns empty list', async () => {
const original = STAFF_DAILY_API_SWITCH.weekly
STAFF_DAILY_API_SWITCH.weekly = 'mock'
let called = false
staffAdapters.__setDynamicDailyReportApi({
dailyReportWeeklyList: async () => {
called = true
return { code: 0, data: ['2026-05-26'] }
}
})
try {
const res = await staffAdapters.fetchWeeklyAdapter({ merchantId: 1 })
assert.equal(called, false)
assert.deepEqual(res.data, [])
} finally {
staffAdapters.__setDynamicDailyReportApi(null)
STAFF_DAILY_API_SWITCH.weekly = original
}
})
it('fetchWeeklyAdapter negotiation mock mode returns empty list', async () => {
const original = NEGOTIATION_DAILY_API_SWITCH.weekly
NEGOTIATION_DAILY_API_SWITCH.weekly = 'mock'
let called = false
negotiationAdapters.__setDynamicDailyReportApi({
dailyReportWeeklyList: async () => {
called = true
return { code: 0, data: ['2026-05-26'] }
}
})
try {
const res = await negotiationAdapters.fetchWeeklyAdapter({ merchantId: 1 })
assert.equal(called, false)
assert.deepEqual(res.data, [])
} finally {
negotiationAdapters.__setDynamicDailyReportApi(null)
NEGOTIATION_DAILY_API_SWITCH.weekly = original
}
})
})