diff --git a/docs/architecture/refactoring-master-plan.md b/docs/architecture/refactoring-master-plan.md index 7c4beda..7ae197a 100644 --- a/docs/architecture/refactoring-master-plan.md +++ b/docs/architecture/refactoring-master-plan.md @@ -675,3 +675,4 @@ npm --prefix frontend run build | 2026-08-15 | 完成业务测试覆盖切片“Accounts Hook 运行状态轮询错误” | 补充账号运行状态轮询失败测试,验证账号列表保留、错误记录和轮询生命周期清理;不触发真实账号运行时;前端 Hook 测试、类型和注释门禁通过 | 下一步:继续补齐剩余可控业务分支并分类外部依赖分支 | | 2026-08-15 | 完成业务测试覆盖切片“账号子模块通知与密码登录中间状态” | 补充通知渠道独立失败、AI 弹窗关闭、密码登录处理中和编辑弹窗关闭取消测试;覆盖子模块请求隔离与生命周期清理,不触发真实账号凭证或平台登录;前端 Hook 测试、类型和注释门禁通过 | 下一步:继续补齐剩余可控业务分支并分类外部依赖分支 | | 2026-08-15 | 完成阶段性业务覆盖率审计 | 前端全量测试 50 个文件、268 个用例通过;业务代码 V8 覆盖率达到语句 92.27%、分支 73.19%、函数 93.41%、行 96.24%;纯 UI 组件按用户要求排除,剩余未覆盖项集中在 API 适配器未调用接口、请求取消/过期保护和真实平台生命周期分支,下一轮继续按可控性补测并保留外部依赖跳过说明 | 下一步:继续补齐剩余可控业务分支,最终形成业务覆盖率验收清单 | +| 2026-08-15 | 完成业务测试覆盖切片“通知 API 序列化与绑定响应” | 补充通知渠道更新配置/事件序列化和消息通知数组展开、非法绑定值忽略测试;覆盖 API 适配层确定性响应归一化,不触发推送服务;前端 API 测试、类型和注释门禁通过 | 下一步:继续补齐剩余 API 适配器与请求取消分支 | diff --git a/frontend/services/api.test.ts b/frontend/services/api.test.ts index 5a3a150..2788330 100644 --- a/frontend/services/api.test.ts +++ b/frontend/services/api.test.ts @@ -742,6 +742,27 @@ test('updateNotificationChannel supports partial enabled updates', async () => { }); } /* 回调函数负责当前业务流程。 */); +test('updateNotificationChannel serializes config and event types', /* 当前回调验证通知渠道请求体序列化。 */ async () => { + // fetchMock 是通知渠道更新接口的网络替身。 + const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true })); + vi.stubGlobal('fetch', fetchMock); + await updateNotificationChannel('7', { config: { server_url: 'https://example.com' }, event_types: ['system_error'] }); + // body 是通知渠道更新请求体。 + const body = JSON.parse(fetchMock.mock.calls[0][1].body); + expect(body.config).toBe(JSON.stringify({ server_url: 'https://example.com' })); + expect(body.event_types).toBe(JSON.stringify(['system_error'])); +}); + +test('getMessageNotifications 展开数组并忽略非法绑定值', /* 当前回调验证消息通知响应归一化。 */ async () => { + // fetchMock 是消息通知接口的网络替身。 + const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ + 'account-1': [{ channel_id: 1, channel_name: '邮件', enabled: true }], + 'account-2': null, + })); + vi.stubGlobal('fetch', fetchMock); + await expect(getMessageNotifications()).resolves.toEqual({ success: true, data: [{ cookie_id: 'account-1', channel_id: 1, channel_name: '邮件', enabled: true }] }); +}); + test('updateShippingRule posts buyer reviewed gift payload to automation-rules', async () => { const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true, id: 1 })); /* fetchMock 表示fetchMock。 */ vi.stubGlobal('fetch', fetchMock);