import { describe, it, beforeAll, afterAll, expect } from 'vitest'; import { DeviceDriver } from '../../drivers/types'; import { createDriver } from '../../drivers/factory'; import { TestReporter } from '../../utils/test-reporter'; import { registerAccount, forgotPassword, deleteAccount, isLoggedIn, onesPlatform } from '../../utils/common'; import * as dotenv from 'dotenv'; import * as path from 'path'; dotenv.config({ path: path.resolve(__dirname, '../../.env') }); const A_REGISTER = `① ${onesPlatform(15940)} 注册新账号`; const A_FORGOT = `② ${onesPlatform(15941)} 忘记密码改密`; const A_DELETE = '③ 注销账号'; // 注销暂无独立 P0 必测项 // 全链路:同一个临时账号 注册 → 忘记密码改密 → 注销。三步顺序共享账号。 describe('Auth - 账号全链路(注册→忘记密码→注销)', () => { let driver: DeviceDriver; let reporter: TestReporter; const account: { email: string; password: string; token: string } = { email: '', password: '', token: '' }; beforeAll(async () => { driver = createDriver(); await driver.createSession(); reporter = new TestReporter('Auth_FullLifecycle', driver.platform.toUpperCase()); }); afterAll(async () => { reporter.generate(); await driver.destroySession(); }); it(A_REGISTER, { timeout: 240000 }, async () => { const start = Date.now(); try { const acct = await registerAccount(driver); Object.assign(account, acct); expect(await isLoggedIn(driver)).toBe(true); reporter.record(A_REGISTER, 'PASS', Date.now() - start, `注册并自动登录: ${acct.email}`); } catch (e: any) { const ss = await driver.screenshot().catch(() => ''); reporter.record(A_REGISTER, 'FAIL', Date.now() - start, e.message, ss); throw e; } }); it(A_FORGOT, { timeout: 240000 }, async () => { const start = Date.now(); if (!account.email) { reporter.record(A_FORGOT, 'SKIP', 0, '注册未成功,跳过'); return; } try { account.password = await forgotPassword(driver, { email: account.email, token: account.token }); expect(await isLoggedIn(driver)).toBe(true); reporter.record(A_FORGOT, 'PASS', Date.now() - start, `${account.email} 改密并自动登录`); } catch (e: any) { const ss = await driver.screenshot().catch(() => ''); reporter.record(A_FORGOT, 'FAIL', Date.now() - start, e.message, ss); throw e; } }); it(A_DELETE, { timeout: 240000 }, async () => { const start = Date.now(); if (!account.email) { reporter.record(A_DELETE, 'SKIP', 0, '前置未成功,跳过'); return; } try { const ok = await deleteAccount(driver, { token: account.token }); expect(ok).toBe(true); reporter.record(A_DELETE, 'PASS', Date.now() - start, `${account.email} 注销成功`); } catch (e: any) { const ss = await driver.screenshot().catch(() => ''); reporter.record(A_DELETE, 'FAIL', Date.now() - start, e.message, ss); throw e; } }); });