添加LOTTERY_E2E环境变量来控制E2E测试相关功能, 包括绕过验证码、登录限制和钱包API URL验证, 同时更新composer.json以包含E2E专用的提供者和服务。
This commit is contained in:
34
e2e/tests/api/04.admin-auth.spec.ts
Normal file
34
e2e/tests/api/04.admin-auth.spec.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* E2E:超管登录 + ping/dashboard
|
||||
*
|
||||
* 验证:
|
||||
* - super admin 能登录
|
||||
* - /api/v1/admin/ping 不需要 auth?实际看路由
|
||||
* - /api/v1/admin/dashboard 需要 auth 且返回 dashboard
|
||||
*/
|
||||
|
||||
import { test, expect, request as pwRequest } from '@playwright/test';
|
||||
import { adminLoginViaBypass } from './_helper';
|
||||
|
||||
test('超管登录成功,is_super_admin=true', async () => {
|
||||
const session = await adminLoginViaBypass();
|
||||
expect(session.accessToken).toBeTruthy();
|
||||
expect(session.admin.is_super_admin).toBe(true);
|
||||
});
|
||||
|
||||
test('超管带 token 调 /api/v1/admin/dashboard 返回 200', async () => {
|
||||
const session = await adminLoginViaBypass();
|
||||
const ctx = await pwRequest.newContext({
|
||||
extraHTTPHeaders: { Authorization: `Bearer ${session.accessToken}` },
|
||||
});
|
||||
const r = await ctx.get('/api/v1/admin/dashboard');
|
||||
expect(r.ok(), `dashboard status=${r.status()}`).toBeTruthy();
|
||||
await ctx.dispose();
|
||||
});
|
||||
|
||||
test('超管无 token 调 /api/v1/admin/dashboard → 401', async () => {
|
||||
const ctx = await pwRequest.newContext();
|
||||
const r = await ctx.get('/api/v1/admin/dashboard');
|
||||
expect([401, 403]).toContain(r.status());
|
||||
await ctx.dispose();
|
||||
});
|
||||
Reference in New Issue
Block a user