File size: 3,876 Bytes
05c5ed5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { test, expect } from "@playwright/test";
import { TEST_USERS } from "../constants/test-users";
import { ensureSidebarOpen } from "../helpers/sidebar-helper";

test.describe("Permissions", () => {
  test("regular user can access basic functionality", async ({ browser }) => {
    // Create context with regular user auth
    const context = await browser.newContext({
      storageState: TEST_USERS.regular.authFile,
    });
    const page = await context.newPage();

    // Regular users might access through profile/settings
    // Test basic navigation works
    await page.goto("/");

    // Check if user has access to basic functionality
    await page.waitForLoadState("networkidle");
    const url = page.url();
    expect(url).not.toContain("/sign-in");

    await context.close();
  });

  test("editor user can access application but not admin panel", async ({
    browser,
  }) => {
    const context = await browser.newContext({
      storageState: TEST_USERS.editor.authFile,
    });
    const page = await context.newPage();

    // Editor should have access to main app
    await page.goto("/");
    await page.waitForLoadState("networkidle");
    const homeUrl = page.url();
    expect(homeUrl).not.toContain("/sign-in");

    // But should not have access to admin panel
    await page.goto("/admin/users");
    await page.waitForLoadState("networkidle");
    await expect(page.getByText("401")).toBeVisible();
  });

  test("regular user cannot access admin panel", async ({ browser }) => {
    const context = await browser.newContext({
      storageState: TEST_USERS.regular.authFile,
    });
    const page = await context.newPage();

    // But should not have access to admin panel
    await page.goto("/admin/users");
    await page.waitForLoadState("networkidle");
    await expect(page.getByText("401")).toBeVisible();

    await context.close();
  });
  test("ensure admin sidebar link is visible to admin", async ({ browser }) => {
    const context = await browser.newContext({
      storageState: TEST_USERS.admin.authFile,
    });
    const page = await context.newPage();
    await page.goto("/");
    await page.waitForLoadState("networkidle");
    await ensureSidebarOpen(page);
    await expect(page.getByTestId("admin-sidebar-link")).toBeVisible();
    await context.close();
  });
  test("ensure admin sidebar link is not visible to editor", async ({
    browser,
  }) => {
    const context = await browser.newContext({
      storageState: TEST_USERS.editor.authFile,
    });
    const page = await context.newPage();
    await page.goto("/");
    await page.waitForLoadState("networkidle");
    await ensureSidebarOpen(page);
    await expect(page.getByTestId("admin-sidebar-link")).not.toBeVisible();
    await context.close();
  });
  test("ensure admin sidebar link is not visible to regular user", async ({
    browser,
  }) => {
    const context = await browser.newContext({
      storageState: TEST_USERS.regular.authFile,
    });
    const page = await context.newPage();
    await page.goto("/");
    await page.waitForLoadState("networkidle");
    await ensureSidebarOpen(page);
    await expect(page.getByTestId("admin-sidebar-link")).not.toBeVisible();
    await context.close();
  });
  test("ensure admin sidebar link goes to users page and shows user menu", async ({
    browser,
  }) => {
    const context = await browser.newContext({
      storageState: TEST_USERS.admin.authFile,
    });
    const page = await context.newPage();
    await page.goto("/");
    await page.waitForLoadState("networkidle");
    await ensureSidebarOpen(page);
    await page.getByTestId("admin-sidebar-link").click();
    await page.waitForLoadState("networkidle");
    await expect(page.getByTestId("admin-sidebar-link-users")).toBeVisible();
    expect(page.url()).toContain("/admin/users");
    await context.close();
  });
});