fdaae3c560
- 删 ZiniaoVersionSetting.vue / ziniao-version.ts;9 个 Tab 摘 ziniao_version 载荷 - 删 BrandDeleteBrandTab.vue / BrandPatrolDeleteTab.vue 与 delete-brand 类型模块; 路由、工具目录(20→18)、端点表、progress-light 模块(12→10)、withdraw.ts 巡店段、 java-modules re-export 同步摘除 - 测试面:node --test 17 处红按实况收敛(端点冻结快照摘两组、适配器 16→14、窄集合台账 摘两页、六页→五页、reexport/快照随实况),modules-delete-brand.test.ts 整文件删 - vue-tsc+vite build 通过;node --test 837/837 绿
161 lines
6.1 KiB
TypeScript
161 lines
6.1 KiB
TypeScript
import { test } from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { http } from '../src/shared/api/http.ts'
|
|
import {
|
|
listWithdrawCandidates,
|
|
addWithdrawCandidate,
|
|
deleteWithdrawCandidate,
|
|
clearWithdrawCandidates,
|
|
matchWithdrawShops,
|
|
getWithdrawDashboard,
|
|
getWithdrawHistory,
|
|
getWithdrawTaskProgressBatch,
|
|
createWithdrawTask,
|
|
submitWithdrawTaskResult,
|
|
getWithdrawResultDownloadUrl,
|
|
deleteWithdrawTask,
|
|
deleteWithdrawHistory,
|
|
} from '../src/shared/api/types/modules/withdraw.ts'
|
|
|
|
function setupWindow() {
|
|
;(globalThis as Record<string, unknown>).window = {
|
|
localStorage: { getItem: () => '42' },
|
|
location: { origin: 'http://localhost' },
|
|
}
|
|
}
|
|
|
|
function mockRequest(
|
|
t: Parameters<typeof test>[1] extends (t: infer T) => unknown ? T : never,
|
|
impl: (config: { url?: string; method?: string; params?: Record<string, unknown>; data?: unknown; timeout?: number }) => Promise<unknown>,
|
|
) {
|
|
t.mock.method(http, 'request', impl as never)
|
|
}
|
|
|
|
const okResponse = (data: unknown) => Promise.resolve({ data: { success: true, message: 'ok', data } })
|
|
|
|
test('test_withdraw_candidates', async (t) => {
|
|
setupWindow()
|
|
const calls: { url?: string; method?: string; params?: Record<string, unknown>; data?: unknown }[] = []
|
|
mockRequest(t, (config) => {
|
|
calls.push(config)
|
|
return okResponse({ id: 1, shop_name: 's1' })
|
|
})
|
|
await listWithdrawCandidates()
|
|
await addWithdrawCandidate('店铺A')
|
|
await deleteWithdrawCandidate(3)
|
|
await clearWithdrawCandidates(['店铺A', '店铺B'])
|
|
assert.equal(calls[0].url, '/newApi/api/withdraw/candidates')
|
|
assert.deepEqual(calls[0].params, { user_id: 42 })
|
|
assert.equal(calls[1].url, '/newApi/api/withdraw/candidates')
|
|
assert.equal(calls[1].method, 'POST')
|
|
assert.deepEqual(calls[1].data, { user_id: 42, shop_name: '店铺A' })
|
|
assert.equal(calls[2].url, '/newApi/api/withdraw/candidates/3')
|
|
assert.equal(calls[2].method, 'DELETE')
|
|
assert.equal(calls[3].url, '/newApi/api/withdraw/candidates/clear')
|
|
assert.equal(calls[3].method, 'POST')
|
|
assert.deepEqual(calls[3].data, { user_id: 42, shop_names: ['店铺A', '店铺B'] })
|
|
})
|
|
|
|
test('test_withdraw_create', async (t) => {
|
|
setupWindow()
|
|
const calls: { url?: string; method?: string; data?: unknown }[] = []
|
|
mockRequest(t, (config) => {
|
|
calls.push(config)
|
|
return okResponse({ taskId: 1, items: [] })
|
|
})
|
|
await createWithdrawTask([{ shopName: '店铺A', matched: true }], 100)
|
|
assert.equal(calls[0].url, '/newApi/api/withdraw/tasks')
|
|
assert.equal(calls[0].method, 'POST')
|
|
assert.deepEqual(calls[0].data, { user_id: 42, reserved_amount: 100, items: [{ shopName: '店铺A', matched: true }] })
|
|
})
|
|
|
|
test('test_withdraw_submit_result', async (t) => {
|
|
setupWindow()
|
|
const calls: { url?: string; method?: string; data?: unknown }[] = []
|
|
mockRequest(t, (config) => {
|
|
calls.push(config)
|
|
return okResponse(null)
|
|
})
|
|
const payload = {
|
|
shops: [{ shopName: '店铺A', rows: [{ country: 'US', withdrawAmount: 10, status: 'SUCCESS' }], shopDone: true }],
|
|
}
|
|
await submitWithdrawTaskResult(7, payload)
|
|
assert.equal(calls[0].url, '/newApi/api/withdraw/tasks/7/result')
|
|
assert.equal(calls[0].method, 'POST')
|
|
assert.deepEqual(calls[0].data, payload)
|
|
})
|
|
|
|
test('test_withdraw_progress_dashboard_history', async (t) => {
|
|
setupWindow()
|
|
const calls: { url?: string; method?: string; data?: unknown; timeout?: number; params?: Record<string, unknown> }[] = []
|
|
mockRequest(t, (config) => {
|
|
calls.push(config)
|
|
return okResponse({ items: [], missingTaskIds: [] })
|
|
})
|
|
await getWithdrawTaskProgressBatch([5, 3])
|
|
await getWithdrawDashboard()
|
|
await getWithdrawHistory()
|
|
await deleteWithdrawTask(7)
|
|
await deleteWithdrawHistory(9)
|
|
assert.equal(calls[0].url, '/newApi/api/withdraw/tasks/progress/batch')
|
|
assert.equal(calls[0].method, 'POST')
|
|
assert.deepEqual(calls[0].data, { taskIds: [3, 5], userId: 42 })
|
|
assert.equal(calls[0].timeout, 10000)
|
|
assert.equal(calls[1].url, '/newApi/api/withdraw/dashboard')
|
|
assert.deepEqual(calls[1].params, { user_id: 42 })
|
|
assert.equal(calls[2].url, '/newApi/api/withdraw/history')
|
|
assert.equal(calls[3].url, '/newApi/api/withdraw/tasks/7')
|
|
assert.equal(calls[3].method, 'DELETE')
|
|
assert.equal(calls[4].url, '/newApi/api/withdraw/history/9')
|
|
assert.equal(calls[4].method, 'DELETE')
|
|
assert.equal(
|
|
getWithdrawResultDownloadUrl(7),
|
|
'http://localhost/newApi/api/withdraw/results/7/download?user_id=42',
|
|
)
|
|
})
|
|
|
|
test('test_withdraw_match', async (t) => {
|
|
setupWindow()
|
|
const calls: { url?: string; data?: unknown }[] = []
|
|
mockRequest(t, (config) => {
|
|
calls.push(config)
|
|
return okResponse({ items: [] })
|
|
})
|
|
await matchWithdrawShops(['店铺A'])
|
|
assert.equal(calls[0].url, '/newApi/api/withdraw/match-shops')
|
|
assert.deepEqual(calls[0].data, { user_id: 42, shop_names: ['店铺A'] })
|
|
})
|
|
|
|
|
|
|
|
|
|
// 2026-10-15 旧版界面退役:巡店删除的 15 个 API 函数随功能从 withdraw.ts 切掉,
|
|
// 本格只剩提款一组(原 test_withdraw_patrol_export_compat)。
|
|
test('test_withdraw_export_compat', async (t) => {
|
|
setupWindow()
|
|
const fromJavaModules = await import('../src/shared/api/java-modules.ts')
|
|
const fromWithdraw = await import('../src/shared/api/types/modules/withdraw.ts')
|
|
const names = [
|
|
'listWithdrawCandidates', 'addWithdrawCandidate', 'deleteWithdrawCandidate',
|
|
'clearWithdrawCandidates', 'matchWithdrawShops', 'getWithdrawDashboard',
|
|
'getWithdrawHistory', 'getWithdrawTaskProgressBatch', 'createWithdrawTask',
|
|
'submitWithdrawTaskResult', 'getWithdrawResultDownloadUrl',
|
|
'deleteWithdrawTask', 'deleteWithdrawHistory',
|
|
]
|
|
for (const name of names) {
|
|
assert.equal(fromJavaModules[name], fromWithdraw[name], `${name} 应为同一引用`)
|
|
}
|
|
const row = { country: 'US', withdrawAmount: 10, status: 'SUCCESS' }
|
|
assert.equal(row.status, 'SUCCESS')
|
|
})
|
|
|
|
test('test_withdraw_unwrap_and_error', async (t) => {
|
|
setupWindow()
|
|
mockRequest(t, () => okResponse({ taskId: 1, items: [] }))
|
|
const result = await createWithdrawTask([], null)
|
|
assert.equal(result.taskId, 1)
|
|
|
|
mockRequest(t, () => Promise.resolve({ data: { success: false, message: '余额不足' } }))
|
|
await assert.rejects(addWithdrawCandidate('x'), /余额不足/)
|
|
})
|