486c5c1d38
- 删除 17 个被测模块已不存在的测试(api-field-schemas / build-chunk-planner /
polling-state-machine 等),套件 94 -> 77 文件
- polling-unknown-status 只保留仍接线的 useTaskProgressLoop 两条,去掉状态机用例
- endpoints 快照重钉 218 -> 215(漂移恰好等于外观专利 parsed-payload/queue-payload/
activate 三个下线端点,无新增、无取值变化)
- brand-rows-version-wiring 的轻量失败回退断言改用 [^}] 锁进 catch 体内:
原窗口会跨过 catch 右花括号读到后面正常分支的 return { taskIds, force: true },
删掉回退也照样绿;五处变异(三页 heavyIds = ids + 外观页两种写法)现全部转红
- appearance-patent-failed-status 改为断言公共映射 taskStatusClass('FAILED')
117 lines
4.5 KiB
TypeScript
117 lines
4.5 KiB
TypeScript
import { test } from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { http } from '../src/shared/api/http.ts'
|
|
import {
|
|
parseAppearancePatent,
|
|
getAppearancePatentDashboard,
|
|
getAppearancePatentHistory,
|
|
getAppearancePatentTaskProgressBatch,
|
|
deleteAppearancePatentTask,
|
|
deleteAppearancePatentHistory,
|
|
getAppearancePatentResultDownloadUrl,
|
|
} from '../src/shared/api/types/modules/appearance-patent.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_appearance_patent_parse_url_payload', async (t) => {
|
|
setupWindow()
|
|
let captured: { url?: string; method?: string; data?: unknown } = {}
|
|
mockRequest(t, (config) => {
|
|
captured = config
|
|
return okResponse({ taskId: 1, totalRows: 1, acceptedRows: 1, droppedRows: 0, items: [] })
|
|
})
|
|
await parseAppearancePatent([{ fileKey: 'k1' }], '请识别', 'api-1')
|
|
assert.equal(captured.url, '/newApi/api/appearance-patent/parse')
|
|
assert.equal(captured.method, 'POST')
|
|
assert.deepEqual(captured.data, {
|
|
user_id: 42,
|
|
files: [{ fileKey: 'k1' }],
|
|
ai_prompt: '请识别',
|
|
api_key: 'api-1',
|
|
})
|
|
})
|
|
|
|
test('test_appearance_patent_dashboard_history', async (t) => {
|
|
setupWindow()
|
|
const calls: { url?: string; params?: Record<string, unknown> }[] = []
|
|
mockRequest(t, (config) => {
|
|
calls.push(config)
|
|
return okResponse({ pendingTaskCount: 0, processedTaskCount: 0, successTaskCount: 1, failedTaskCount: 0 })
|
|
})
|
|
await getAppearancePatentDashboard()
|
|
await getAppearancePatentHistory()
|
|
assert.equal(calls[0].url, '/newApi/api/appearance-patent/dashboard')
|
|
assert.deepEqual(calls[0].params, { user_id: 42 })
|
|
assert.equal(calls[1].url, '/newApi/api/appearance-patent/history')
|
|
assert.deepEqual(calls[1].params, { user_id: 42, limit: 50 })
|
|
})
|
|
|
|
test('test_appearance_patent_progress_batch_timeout', async (t) => {
|
|
setupWindow()
|
|
let captured: { url?: string; method?: string; data?: unknown; timeout?: number } = {}
|
|
mockRequest(t, (config) => {
|
|
captured = config
|
|
return okResponse({ items: [], missingTaskIds: [] })
|
|
})
|
|
const result = await getAppearancePatentTaskProgressBatch([5, 3])
|
|
assert.equal(captured.url, '/newApi/api/appearance-patent/tasks/progress/batch')
|
|
assert.equal(captured.method, 'POST')
|
|
assert.deepEqual(captured.data, { taskIds: [3, 5], userId: 42 })
|
|
assert.equal(captured.timeout, 10000)
|
|
assert.deepEqual(result, { items: [], missingTaskIds: [] })
|
|
})
|
|
|
|
test('test_appearance_patent_delete_task_history', async (t) => {
|
|
setupWindow()
|
|
const calls: { url?: string; method?: string; params?: Record<string, unknown> }[] = []
|
|
mockRequest(t, (config) => {
|
|
calls.push(config)
|
|
return okResponse(null)
|
|
})
|
|
await deleteAppearancePatentTask(7)
|
|
await deleteAppearancePatentHistory(9)
|
|
assert.equal(calls[0].url, '/newApi/api/appearance-patent/tasks/7')
|
|
assert.equal(calls[0].method, 'DELETE')
|
|
assert.deepEqual(calls[0].params, { user_id: 42 })
|
|
assert.equal(calls[1].url, '/newApi/api/appearance-patent/history/9')
|
|
assert.equal(calls[1].method, 'DELETE')
|
|
assert.deepEqual(calls[1].params, { user_id: 42 })
|
|
})
|
|
|
|
test('test_appearance_patent_download_url', async (t) => {
|
|
setupWindow()
|
|
const url = getAppearancePatentResultDownloadUrl(7)
|
|
assert.equal(url, 'http://localhost/newApi/api/appearance-patent/results/7/download?user_id=42')
|
|
})
|
|
|
|
test('test_appearance_patent_export_compat', async (t) => {
|
|
setupWindow()
|
|
const fromJavaModules = await import('../src/shared/api/java-modules.ts')
|
|
const fromAppearance = await import('../src/shared/api/types/modules/appearance-patent.ts')
|
|
const names = [
|
|
'parseAppearancePatent',
|
|
'getAppearancePatentDashboard', 'getAppearancePatentHistory', 'getAppearancePatentTaskProgressBatch',
|
|
'deleteAppearancePatentTask', 'deleteAppearancePatentHistory',
|
|
'getAppearancePatentResultDownloadUrl',
|
|
]
|
|
for (const name of names) {
|
|
assert.equal(fromJavaModules[name], fromAppearance[name], `${name} 应为同一引用`)
|
|
}
|
|
const row = { rowIndex: 1, sourceId: 's1', displayId: 'd1', asin: 'B001', country: 'US' }
|
|
assert.equal(row.country, 'US')
|
|
})
|