storeMonthlyPendingCount.test.mjs
5.17 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { createRequire } from 'node:module'
const require = createRequire(import.meta.url)
const { STORE_DAILY_API_SWITCH } = require('../config/apiSwitch.js')
const adapters = require('../api/storeDailyReportAdapters.js')
const {
normalizeMonthlyPendingCountResponse,
extractPendingCountFromResponseData
} = adapters
const {
STORE_MONTHLY_PENDING_FIELD_KEY,
isMonthlyPendingFieldVisible,
isMonthlyPendingValueEmpty,
shouldFetchMonthlyPendingCount
} = require('../utils/store-monthly-pending.js')
const fieldF224 = { key: STORE_MONTHLY_PENDING_FIELD_KEY, type: 'numberInput' }
describe('store-monthly-pending utils', () => {
it('isMonthlyPendingFieldVisible detects F2-24 in fixedFields', () => {
assert.equal(
isMonthlyPendingFieldVisible({ fixedFields: [fieldF224], sectionGroups: [] }),
true
)
assert.equal(isMonthlyPendingFieldVisible({ fixedFields: [], sectionGroups: [] }), false)
})
it('isMonthlyPendingFieldVisible detects F2-24 in section group children', () => {
assert.equal(
isMonthlyPendingFieldVisible({
fixedFields: [],
sectionGroups: [{ type: 'group', children: [fieldF224] }]
}),
true
)
})
it('isMonthlyPendingValueEmpty treats 0 as filled', () => {
assert.equal(isMonthlyPendingValueEmpty({}), true)
assert.equal(isMonthlyPendingValueEmpty({ 'F2-24': '' }), true)
assert.equal(isMonthlyPendingValueEmpty({ 'F2-24': null }), true)
assert.equal(isMonthlyPendingValueEmpty({ 'F2-24': 0 }), false)
assert.equal(isMonthlyPendingValueEmpty({ 'F2-24': 5 }), false)
})
it('shouldFetchMonthlyPendingCount requires today, visible, and empty', () => {
const viewState = { fixedFields: [fieldF224], sectionGroups: [] }
assert.equal(
shouldFetchMonthlyPendingCount({
isTodayReport: true,
viewState,
values: {}
}),
true
)
assert.equal(
shouldFetchMonthlyPendingCount({
isTodayReport: false,
viewState,
values: {}
}),
false
)
assert.equal(
shouldFetchMonthlyPendingCount({
isTodayReport: true,
viewState: { fixedFields: [], sectionGroups: [] },
values: {}
}),
false
)
assert.equal(
shouldFetchMonthlyPendingCount({
isTodayReport: true,
viewState,
values: { 'F2-24': 3 }
}),
false
)
})
})
describe('fetchMonthlyPendingCount', () => {
it('IT-STORE-PENDING-ADAPTER-001: mock adapter returns fixed pendingCount', async () => {
const original = STORE_DAILY_API_SWITCH.monthlyPendingCount
STORE_DAILY_API_SWITCH.monthlyPendingCount = 'mock'
try {
const res = await adapters.fetchMonthlyPendingCountAdapter({
merchantId: '4s-1',
reportDate: '2026-06-03'
})
assert.equal(res.code, 0)
assert.equal(res.data.pendingCount, 12)
} finally {
STORE_DAILY_API_SWITCH.monthlyPendingCount = original
}
})
it('IT-STORE-PENDING-ADAPTER-002: real adapter calls monthly.pending.count POST', async () => {
const original = STORE_DAILY_API_SWITCH.monthlyPendingCount
STORE_DAILY_API_SWITCH.monthlyPendingCount = 'real'
let captured = null
adapters.__setDynamicDailyReportApi({
dailyReportMonthlyPendingCountGet: async data => {
captured = data
return { code: 0, message: 'ok', data: { pendingCount: 7 } }
}
})
try {
const res = await adapters.fetchMonthlyPendingCountAdapter({
merchantId: '4s-2',
reportDate: '2026-06-03',
sceneType: 1
})
assert.equal(captured.merchantId, '4s-2')
assert.equal(captured.reportDate, '2026-06-03')
assert.equal(captured.sceneType, 1)
assert.equal(res.data.pendingCount, 7)
} finally {
adapters.__setDynamicDailyReportApi(null)
STORE_DAILY_API_SWITCH.monthlyPendingCount = original
}
})
it('IT-STORE-PENDING-FACADE-001: normalizeMonthlyPendingCountResponse parses pendingCount', () => {
const ok = normalizeMonthlyPendingCountResponse({
code: 0,
message: 'ok',
data: { pendingCount: 8 }
})
assert.equal(ok.code, 0)
assert.equal(ok.data.pendingCount, 8)
const zero = normalizeMonthlyPendingCountResponse({
code: 0,
data: { pendingCount: 0 }
})
assert.equal(zero.data.pendingCount, 0)
})
it('IT-STORE-PENDING-FACADE-002: invalid pendingCount in response fails', () => {
const bad = normalizeMonthlyPendingCountResponse({
code: 0,
data: { pendingCount: 'n/a' }
})
assert.notEqual(bad.code, 0)
assert.equal(bad.data, null)
})
it('IT-STORE-PENDING-FACADE-003: normalize reads pendingcount lowercase from API', () => {
const res = normalizeMonthlyPendingCountResponse({
code: 0,
message: 'ok',
data: { pendingcount: 15 }
})
assert.equal(res.code, 0)
assert.equal(res.data.pendingCount, 15)
})
it('IT-STORE-PENDING-FACADE-004: normalize reads scalar data value', () => {
const res = normalizeMonthlyPendingCountResponse({
code: 0,
data: 9
})
assert.equal(res.data.pendingCount, 9)
})
it('IT-STORE-PENDING-EXTRACT-001: extractPendingCountFromResponseData priority', () => {
assert.equal(extractPendingCountFromResponseData({ pendingcount: 3 }), 3)
assert.equal(extractPendingCountFromResponseData({ pendingCount: 4 }), 4)
assert.equal(extractPendingCountFromResponseData(11), 11)
assert.equal(extractPendingCountFromResponseData('6'), 6)
})
})