From e7ab04c0fc893470311b0d24b3af42c9b71b19cf Mon Sep 17 00:00:00 2001 From: Christ Date: Sat, 15 Aug 2026 11:54:48 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E9=BD=90=E8=AE=A2=E5=8D=95=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E9=BB=98=E8=AE=A4=E5=9B=9E=E5=A4=8DAPI=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/architecture/refactoring-master-plan.md | 1 + frontend/services/api.test.ts | 22 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/docs/architecture/refactoring-master-plan.md b/docs/architecture/refactoring-master-plan.md index a752882..f5ce835 100644 --- a/docs/architecture/refactoring-master-plan.md +++ b/docs/architecture/refactoring-master-plan.md @@ -681,3 +681,4 @@ npm --prefix frontend run build | 2026-08-15 | 完成业务测试覆盖切片“请求层成功文本响应” | 补充普通请求成功返回非 JSON 文本的确定性测试,覆盖共享请求层文本分支,不依赖真实服务;前端请求测试、类型和注释门禁通过 | 下一步:继续补齐剩余 API 适配器与请求取消分支 | | 2026-08-15 | 完成业务测试覆盖切片“Dashboard Hook 经营数据错误” | 补充趋势/有效订单并行请求失败和范围错误状态测试;验证错误信息收口,不触发真实统计或订单数据;前端 Hook 测试、类型和注释门禁通过 | 下一步:继续补齐剩余 API 适配器与请求取消分支 | | 2026-08-15 | 完成业务测试覆盖切片“API 头像、订单分析、批量预检与卡密归一化” | 补充头像 URL 缓存参数/非法地址、数字天数分析、批量预检可选字段、无账号规则守卫和卡密 JSON 配置归一化测试;覆盖 API 适配层确定性分支,不依赖真实账号或平台数据;前端 API 测试、类型和注释门禁通过 | 下一步:继续补齐剩余 API 适配器与请求取消分支 | +| 2026-08-15 | 完成业务测试覆盖切片“订单筛选、通知数组与默认回复归一化” | 补充订单账号/状态筛选参数、通知事件数组格式和默认回复空字段保存载荷测试;覆盖 API 适配层剩余确定性分支,不依赖真实订单或推送服务;前端 API 测试、类型和注释门禁通过 | 下一步:继续补齐剩余 API 适配器与请求取消分支 | diff --git a/frontend/services/api.test.ts b/frontend/services/api.test.ts index c1ef7cd..0c2b185 100644 --- a/frontend/services/api.test.ts +++ b/frontend/services/api.test.ts @@ -338,6 +338,15 @@ test('getOrderAnalytics 支持数字天数参数', /* 当前回调验证订单 expect(fetchMock.mock.calls[0][0]).toContain('end_date='); }); +test('getOrders 序列化账号和状态筛选参数', /* 当前回调验证订单查询筛选参数分支。 */ async () => { + // fetchMock 是订单筛选请求的网络替身。 + const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ data: [], total: 0 })); + vi.stubGlobal('fetch', fetchMock); + await getOrders('account-1', 'pending_ship'); + expect(fetchMock.mock.calls[0][0]).toContain('cookie_id=account-1'); + expect(fetchMock.mock.calls[0][0]).toContain('status=pending_ship'); +}); + test('paid orders are normalized to pending shipment', async () => { vi.stubGlobal('fetch', vi.fn().mockResolvedValue(jsonResponse({ data: [{ order_id: 'o-paid', order_status: 'paid' }] }))); const result = await getOrders(); /* result 表示处理结果。 */ @@ -688,6 +697,17 @@ test('getCards 解析 JSON 和损坏 JSON 的卡密接口配置', /* 当前回 expect(cards[1].api_config).toBeUndefined(); }); +test('默认回复 API 补齐空字段默认值', /* 当前回调验证默认回复字段归一化和保存载荷。 */ async () => { + // fetchMock 是默认回复读取和保存接口的网络替身。 + const fetchMock = vi.fn() + .mockResolvedValueOnce(jsonResponse({ enabled: false })) + .mockResolvedValueOnce(jsonResponse({ success: true })); + vi.stubGlobal('fetch', fetchMock); + await expect(getDefaultReply('account-1')).resolves.toEqual({ cookie_id: 'account-1', enabled: false, reply_content: '', reply_once: false, reply_image_url: '' }); + await updateDefaultReply('account-1', {}); + expect(JSON.parse(fetchMock.mock.calls[1][1].body)).toEqual({ enabled: false, reply_content: '', reply_once: false, reply_image_url: '' }); +}); + test('updateReplyRule preserves keyword image metadata when saving text edits', async () => { const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true })); /* fetchMock 表示fetchMock。 */ vi.stubGlobal('fetch', fetchMock); @@ -823,12 +843,14 @@ test('通知事件字段支持 JSON 数组和分隔符格式', /* 当前回调 const fetchMock = vi.fn().mockResolvedValue(jsonResponse([ { id: 1, name: 'JSON', type: 'bark', config: '{}', event_types: '["system_error", "order_paid"]', enabled: true }, { id: 2, name: '分隔符', type: 'bark', config: '{}', event_types: 'system_error, order_paid; buyer_reviewed', enabled: true }, + { id: 3, name: '数组', type: 'bark', config: '{}', event_types: ['system_error'], enabled: true }, ])); vi.stubGlobal('fetch', fetchMock); // result 是通知事件字段解析后的渠道列表。 const result = await getNotificationChannels(); expect(result.data?.[0].event_types).toEqual(['system_error', 'order_paid']); expect(result.data?.[1].event_types).toEqual(['system_error', 'order_paid', 'buyer_reviewed']); + expect(result.data?.[2].event_types).toEqual(['system_error']); }); test('updateShippingRule posts buyer reviewed gift payload to automation-rules', async () => {