detail-get-null-response.test.mjs
4.26 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
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { createRequire } from 'node:module'
const require = createRequire(import.meta.url)
const {
isApiSuccess,
resolveDetailGetResponse
} = require('../utils/api-response.js')
const { STAFF_DAILY_API_SWITCH } = require('../config/apiSwitch.js')
const { DAILY_REPORT_TEMPLATE_TYPE } = require('../config/dailyReportConstants.js')
const adapters = require('../api/staffDailyReportAdapters.js')
const { loadStaffDailyForm } = require('../services/staffDailyFormLoader.js')
const schemaIndexed = require('../fixtures/schema-staff-daily-full.js')
const { normalizeConfigToSchemaRoot } = require('../config/configCenter.js')
const schemaTemplate = normalizeConfigToSchemaRoot(schemaIndexed)
function buildStaffEmptyDetail(reportTemplateId) {
return {
reportTemplateId: reportTemplateId || 10001,
dailyReportRecordId: null,
values: {}
}
}
describe('detail.get null response', () => {
it('IT-API-SUCCESS-001: isApiSuccess accepts 0 and "0"', () => {
assert.equal(isApiSuccess(0), true)
assert.equal(isApiSuccess('0'), true)
assert.equal(isApiSuccess(1), false)
assert.equal(isApiSuccess('1'), false)
})
it('IT-DETAIL-NULL-001: detail.get code "0" data null normalizes to empty detail', async () => {
const original = STAFF_DAILY_API_SWITCH.detail
STAFF_DAILY_API_SWITCH.detail = 'real'
adapters.__setDynamicDailyReportApi({
dailyReportDetailGet: async () => ({
code: '0',
data: null,
message: '调用服务成功!',
errId: null
})
})
try {
const raw = await adapters.fetchDetailAdapter({
merchantId: 'shop-1',
staffUuid: 'staff-1',
reportDate: '2026-06-15',
sceneType: 0
})
const resolved = resolveDetailGetResponse(
raw,
buildStaffEmptyDetail,
10001
)
assert.equal(resolved.code, 0)
assert.equal(resolved.data.dailyReportRecordId, null)
assert.deepEqual(resolved.data.values, {})
assert.equal(raw.code, '0')
assert.equal(raw.data, null)
} finally {
adapters.__setDynamicDailyReportApi(null)
STAFF_DAILY_API_SWITCH.detail = original
}
})
it('IT-DETAIL-NULL-001b: resolveDetailGetResponse maps null to buildEmptyDetail', () => {
const empty = { reportTemplateId: 99, dailyReportRecordId: null, values: {} }
const res = resolveDetailGetResponse(
{ code: '0', data: null, message: '调用服务成功!' },
() => empty,
99
)
assert.equal(res.code, 0)
assert.equal(res.data, empty)
})
it('IT-DETAIL-NULL-001c: fetchDetailAdapter real mode passes templateType=1', async () => {
const original = STAFF_DAILY_API_SWITCH.detail
STAFF_DAILY_API_SWITCH.detail = 'real'
let captured = null
adapters.__setDynamicDailyReportApi({
dailyReportDetailGet: async data => {
captured = data
return { code: '0', data: null, message: '调用服务成功!' }
}
})
try {
await adapters.fetchDetailAdapter({
merchantId: 'shop-1',
staffUuid: 'staff-1',
reportDate: '2026-06-15',
sceneType: 0
})
assert.equal(captured.templateType, DAILY_REPORT_TEMPLATE_TYPE.staff)
} finally {
adapters.__setDynamicDailyReportApi(null)
STAFF_DAILY_API_SWITCH.detail = original
}
})
it('IT-DETAIL-NULL-002: loadStaffDailyForm succeeds when detail is empty record', async () => {
const pageContext = {
baseSceneCode: 100101,
brandIds: [3454],
sceneList: [{ baseSceneCode: 100101 }],
merchantId: 'm1'
}
const deps = {
fetchMerchantBrandIds: async () => ({ code: 0, data: [3454] }),
fetchMerchantScene: async () => ({
code: 0,
sceneList: [{ baseSceneCode: 100101 }],
baseSceneCode: 100101
}),
fetchReportDetail: async () => ({
code: 0,
data: {
reportTemplateId: 10001,
dailyReportRecordId: null,
values: {}
}
}),
fetchDailyReportCarBrandList: async () => ({ code: 0, data: [] }),
fetchPageContext: async () => ({ code: 0, data: pageContext }),
fetchSchema: async () => ({ code: 0, data: schemaTemplate })
}
const res = await loadStaffDailyForm(
{
userContext: { merchantId: 'm1', staffUuid: 's1' },
reportDate: '2026-06-15',
reportTemplateId: 10001
},
deps
)
assert.equal(res.code, 0)
assert.ok(res.data.pageContext)
assert.ok(res.data.schema)
assert.equal(res.data.detail.dailyReportRecordId, null)
})
})