/**
 * 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();
});
