/ opencodehub / tests / e2e / admin-panel.spec.ts
Swadhin Biswas test(qa): add e2e, integration, unit, and load coverage · 3/6/2026
1c29e63
30 lines · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { expect, test } from "@playwright/test";

test.describe("Admin Panel", () => {
  test("admin page requires auth", async ({ page }) => {
    await page.goto("/admin");
    const url = page.url();
    // Should redirect to login or show forbidden
    expect(
      url.includes("/login") ||
        (await page
          .locator("text=Forbidden")
          .or(page.locator("text=denied"))
          .first()
          .isVisible()
          .catch(() => false)) ||
        (await page
          .locator("text=Login")
          .first()
          .isVisible()
          .catch(() => false)),
    ).toBeTruthy();
  });

  test("admin API requires admin role", async ({ request }) => {
    const res = await request.get("/api/admin/stats");
    // Should be 401 or 403
    expect([401, 403]).toContain(res.status());
  });
});