阶段七:完成React feature依赖门禁与旧入口瘦身
This commit is contained in:
1 parent
448713735f
commit
22656c20f1
30 files changed
+1485
-1511
No files matched your search
@@ -0,0 +1,59 @@
|
||||
import { describe, expect, test } from 'vitest';
|
||||
import type { AccountDetail } from '../../../types';
|
||||
import { mergeAccountRuntimeStatuses } from './runtime';
|
||||
|
||||
// account 创建运行状态测试使用的最小账号对象。
|
||||
const account = (overrides: Partial<AccountDetail> = {}): AccountDetail => ({
|
||||
id: 'account-1',
|
||||
cookie: 'cookie',
|
||||
enabled: true,
|
||||
auto_confirm: false,
|
||||
...overrides,
|
||||
});
|
||||
|
||||
describe('Accounts runtime state', () => {
|
||||
test('最新在线状态替换风控恢复中的旧提示', () => {
|
||||
// result 是合并当前运行状态后的账号列表。
|
||||
const result = mergeAccountRuntimeStatuses([account({
|
||||
runtime_state: 'connecting',
|
||||
runtime_message: 'token 风控验证已处理,正在重新获取登录凭证',
|
||||
runtime_updated_at: '2026-07-13T13:16:00+08:00',
|
||||
})], {
|
||||
'account-1': {
|
||||
state: 'online',
|
||||
message: '消息服务连接正常',
|
||||
connected: true,
|
||||
failures: 0,
|
||||
updated_at: '2026-07-13T13:16:02+08:00',
|
||||
},
|
||||
});
|
||||
|
||||
expect(result[0]).toMatchObject({ runtime_state: 'online', runtime_message: '消息服务连接正常', runtime_connected: true });
|
||||
});
|
||||
|
||||
test('晚到达的旧状态响应不会覆盖当前账号状态', () => {
|
||||
// current 是当前页面已经展示的较新账号状态。
|
||||
const current = account({
|
||||
runtime_state: 'online',
|
||||
runtime_message: '消息服务连接正常',
|
||||
runtime_updated_at: '2026-07-13T13:16:02+08:00',
|
||||
});
|
||||
const result = mergeAccountRuntimeStatuses([current], {
|
||||
'account-1': {
|
||||
state: 'connecting',
|
||||
message: 'token 风控验证已处理,正在重新获取登录凭证',
|
||||
connected: false,
|
||||
failures: 0,
|
||||
updated_at: '2026-07-13T13:16:00+08:00',
|
||||
},
|
||||
});
|
||||
|
||||
expect(result[0]).toBe(current);
|
||||
});
|
||||
|
||||
test('缺少对应运行状态时保留原账号对象', () => {
|
||||
// current 是没有新运行状态可合并的账号对象。
|
||||
const current = account();
|
||||
expect(mergeAccountRuntimeStatuses([current], {})[0]).toBe(current);
|
||||
});
|
||||
});
|
||||
@@ -80,3 +80,62 @@ test('密码登录风控和失败状态统一转换且不暴露验证链接',
|
||||
qrCodeUrl: '',
|
||||
});
|
||||
});
|
||||
|
||||
test('登录字段更新不会用空白密码覆盖已有凭证',
|
||||
// 账号或浏览器开关变化时只提交真正变化的非敏感字段。
|
||||
() => {
|
||||
expect(buildAccountLoginInfoUpdate(account({ username: 'old-user', show_browser: true }), {
|
||||
username: 'new-user',
|
||||
login_password: '',
|
||||
show_browser: false,
|
||||
})).toEqual({ username: 'new-user', show_browser: false });
|
||||
});
|
||||
|
||||
test('登录字段更新只在用户输入新密码时提交密码',
|
||||
// 用户输入新密码后才允许将密码字段写入设置补丁。
|
||||
() => {
|
||||
expect(buildAccountLoginInfoUpdate(account(), {
|
||||
username: 'old-user',
|
||||
login_password: 'new-secret',
|
||||
show_browser: false,
|
||||
})).toEqual({ username: 'old-user', login_password: 'new-secret', show_browser: false });
|
||||
});
|
||||
|
||||
test('登录字段没有变化时不生成更新补丁',
|
||||
// 没有任何登录字段变化时避免发起无意义的设置请求。
|
||||
() => {
|
||||
expect(buildAccountLoginInfoUpdate(account(), {
|
||||
username: 'old-user',
|
||||
login_password: '',
|
||||
show_browser: false,
|
||||
})).toBeNull();
|
||||
});
|
||||
|
||||
test('登录字段支持明确清空密码',
|
||||
// 清空密码必须由用户显式勾选,不能由空白输入隐式触发。
|
||||
() => {
|
||||
expect(buildAccountLoginInfoUpdate(account(), {
|
||||
username: 'old-user',
|
||||
login_password: '',
|
||||
show_browser: false,
|
||||
clear_password: true,
|
||||
})).toEqual({ username: 'old-user', show_browser: false, clear_password: true });
|
||||
});
|
||||
|
||||
test('明确清空密码优先于同时输入的新密码',
|
||||
// 同时存在清空和输入时遵循显式清空意图,避免写入新密码。
|
||||
() => {
|
||||
expect(buildAccountLoginInfoUpdate(account(), {
|
||||
username: 'old-user',
|
||||
login_password: 'new-secret',
|
||||
show_browser: false,
|
||||
clear_password: true,
|
||||
})).toEqual({ username: 'old-user', show_browser: false, clear_password: true });
|
||||
});
|
||||
|
||||
test('暂停时长相同不会重新启动账号暂停',
|
||||
// 暂停时长没有变化时保持当前状态,避免重复写入暂停记录。
|
||||
() => {
|
||||
expect(shouldUpdateAccountPause(60, { pause_duration: 60, paused: false })).toBe(false);
|
||||
expect(shouldUpdateAccountPause(60, { pause_duration: 60, paused: true })).toBe(false);
|
||||
});
|
||||
@@ -32,3 +32,9 @@ test('追加目标切换后拒绝旧请求响应和旧代次响应',
|
||||
expect(isCurrentCardRequest(2, 3, '2', '2')).toBe(false);
|
||||
expect(isCurrentCardRequest(3, 3, '2', '3')).toBe(false);
|
||||
});
|
||||
|
||||
test('卡密筛选忽略名称周围空白并支持大小写无关匹配',
|
||||
// 用户输入的名称关键字会先裁剪空白,再进行不区分大小写的匹配。
|
||||
() => {
|
||||
expect(filterCards(cards, '', ' ppt ')).toEqual([cards[0], cards[2]]);
|
||||
});
|
||||
@@ -0,0 +1,50 @@
|
||||
import { expect, test } from 'vitest';
|
||||
import type { AutomationRunIssue } from './api';
|
||||
import { canResolveAutomationIssue, filterAutomationIssues, loadAutomationPageData } from './issueState';
|
||||
|
||||
// issue 创建规则异常测试使用的最小异常对象。
|
||||
const issue = (cookieID: string, allowed: AutomationRunIssue['allowed_resolutions']): AutomationRunIssue => ({
|
||||
id: cookieID === 'a' ? 1 : 2,
|
||||
cookie_id: cookieID,
|
||||
order_id: 'o',
|
||||
trigger_type: 'buyer_reviewed',
|
||||
error_message: 'error',
|
||||
issue_kind: 'invalid_snapshot',
|
||||
allowed_resolutions: allowed,
|
||||
action_cursor: 0,
|
||||
sent_count: 0,
|
||||
updated_at: '',
|
||||
});
|
||||
|
||||
test('规则异常处理动作遵循后端允许列表',
|
||||
// 只有后端明确允许的人工动作才能被页面提交。
|
||||
() => {
|
||||
const invalid = issue('a', ['cancel']);
|
||||
expect(canResolveAutomationIssue(invalid, 'cancel')).toBe(true);
|
||||
expect(canResolveAutomationIssue(invalid, 'continue')).toBe(false);
|
||||
expect(canResolveAutomationIssue(invalid, 'retry')).toBe(false);
|
||||
});
|
||||
|
||||
test('规则异常按账号筛选后再决定是否展示面板',
|
||||
// 异常面板只展示当前账号的运行异常和延迟任务。
|
||||
() => {
|
||||
const visible = filterAutomationIssues({ runs: [issue('a', ['cancel']), issue('b', ['retry', 'cancel'])], pending_tasks: [] }, 'missing');
|
||||
expect(visible.runs).toEqual([]);
|
||||
expect(visible.pending_tasks).toEqual([]);
|
||||
});
|
||||
|
||||
test('规则列表不因异常接口失败而停止加载', async () => {
|
||||
// receivedRules 保存主规则列表加载器收到的结果。
|
||||
const receivedRules: string[][] = [];
|
||||
// errors 保存异常接口失败后的错误回调。
|
||||
const errors: unknown[] = [];
|
||||
await loadAutomationPageData({
|
||||
loadRules: async () => ['rule'],
|
||||
loadIssues: async () => { throw new Error('issues unavailable'); },
|
||||
onRules: rules => receivedRules.push(rules),
|
||||
onIssues: () => { throw new Error('must not receive issues'); },
|
||||
onIssuesError: error => errors.push(error),
|
||||
});
|
||||
expect(receivedRules).toEqual([['rule']]);
|
||||
expect(errors).toHaveLength(1);
|
||||
});
|
||||
@@ -0,0 +1,2 @@
|
||||
// Session feature 只通过本适配层访问会话相关网络接口。
|
||||
export { initializeAdmin, login, logout, verifySession } from '../../../services/api';
|
||||
@@ -0,0 +1,3 @@
|
||||
// System feature 只通过本适配层访问服务健康检查接口。
|
||||
export { getHealth } from '../../../services/api';
|
||||
export type { BuildInfo } from './types';
|
||||
@@ -0,0 +1,7 @@
|
||||
// BuildInfo 描述健康检查接口返回的构建版本信息。
|
||||
export interface BuildInfo {
|
||||
// version 是当前服务构建版本。
|
||||
version: string;
|
||||
// commit 是当前服务对应的提交标识。
|
||||
commit: string;
|
||||
}
|
||||
Reference in new issue
Block a user