删除内容: - 前端: health/(67文件), ai/(2文件), Copilot, MediaPicker, 相关API/Store/Hook - 后端: wechat_handler, wechat_service, wechat_user entity, analytics handler, ai_workflow_seed - 配置: WechatConfig, AppConfig.wechat, AuthState wechat 字段 - 启动: 微信凭据检查块, ensure_ai_workflows() 调用 - 迁移: 新增 m20260613_000170_drop_wechat_users.rs - 脚本: api_test_health_alert.py, api_test_mp.py, mpsync.sh/ps1 - E2E: health-data page, flows/ 目录 保留: erp-core/auth/workflow/message/config/plugin + 基座前端 + 通用组件
44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import { test as base } from '@playwright/test';
|
|
|
|
const API_BASE = 'http://localhost:3000/api/v1';
|
|
|
|
let loginPromise: Promise<{ token: string; user: unknown }> | null = null;
|
|
|
|
function login(): Promise<{ token: string; user: unknown }> {
|
|
if (!loginPromise) {
|
|
loginPromise = (async () => {
|
|
for (let attempt = 0; attempt < 3; attempt++) {
|
|
try {
|
|
const res = await fetch(`${API_BASE}/auth/login`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ username: 'admin', password: 'Admin@2026' }),
|
|
});
|
|
const json = await res.json();
|
|
if (json.success) {
|
|
return { token: json.data.access_token, user: json.data.user };
|
|
}
|
|
} catch {}
|
|
// Wait before retry on collision
|
|
await new Promise((r) => setTimeout(r, 500 * (attempt + 1)));
|
|
}
|
|
throw new Error('Login failed after 3 attempts');
|
|
})();
|
|
}
|
|
return loginPromise;
|
|
}
|
|
|
|
export const test = base.extend({
|
|
page: async ({ page }, use) => {
|
|
const { token, user } = await login();
|
|
await page.addInitScript((args) => {
|
|
localStorage.setItem('access_token', args.token);
|
|
localStorage.setItem('refresh_token', args.token);
|
|
localStorage.setItem('user', JSON.stringify(args.user));
|
|
}, { token, user });
|
|
await use(page);
|
|
},
|
|
});
|
|
|
|
export { expect } from '@playwright/test';
|