merged tests
This commit is contained in:
parent
4be45f8f7c
commit
67ffe6a823
7 changed files with 212 additions and 599 deletions
|
|
@ -21,40 +21,25 @@ test.describe("Availability Page - Admin Access", () => {
|
|||
await loginUser(page, ADMIN_USER.email, ADMIN_USER.password);
|
||||
});
|
||||
|
||||
test("admin can access availability page", async ({ page }) => {
|
||||
await page.goto("/admin/availability");
|
||||
test("admin can access availability page and UI elements work", async ({ page }) => {
|
||||
// Test navigation link
|
||||
await page.goto("/admin/trades");
|
||||
const availabilityLink = page.locator('a[href="/admin/availability"]');
|
||||
await expect(availabilityLink).toBeVisible();
|
||||
|
||||
// Test page access and structure
|
||||
await page.goto("/admin/availability");
|
||||
await expect(page).toHaveURL("/admin/availability");
|
||||
await expect(page.getByRole("heading", { name: "Availability" })).toBeVisible();
|
||||
await expect(page.getByText("Configure your available time slots")).toBeVisible();
|
||||
});
|
||||
|
||||
test("admin sees Availability link in nav", async ({ page }) => {
|
||||
await page.goto("/admin/trades");
|
||||
|
||||
const availabilityLink = page.locator('a[href="/admin/availability"]');
|
||||
await expect(availabilityLink).toBeVisible();
|
||||
});
|
||||
|
||||
test("availability page shows calendar grid", async ({ page }) => {
|
||||
await page.goto("/admin/availability");
|
||||
|
||||
// Should show tomorrow's date in the calendar
|
||||
// Test calendar grid
|
||||
const tomorrowText = getTomorrowDisplay();
|
||||
await expect(page.getByText(tomorrowText)).toBeVisible();
|
||||
|
||||
// Should show "No availability" for days without slots
|
||||
await expect(page.getByText("No availability").first()).toBeVisible();
|
||||
});
|
||||
|
||||
test("can open edit modal by clicking a day", async ({ page }) => {
|
||||
await page.goto("/admin/availability");
|
||||
|
||||
// Click on the first day card
|
||||
const tomorrowText = getTomorrowDisplay();
|
||||
// Test edit modal
|
||||
await page.getByText(tomorrowText).click();
|
||||
|
||||
// Modal should appear
|
||||
await expect(page.getByRole("heading", { name: /Edit Availability/ })).toBeVisible();
|
||||
await expect(page.getByRole("button", { name: "Save" })).toBeVisible();
|
||||
await expect(page.getByRole("button", { name: "Cancel" })).toBeVisible();
|
||||
|
|
@ -205,46 +190,35 @@ test.describe("Availability Page - Admin Access", () => {
|
|||
});
|
||||
|
||||
test.describe("Availability Page - Access Control", () => {
|
||||
test("regular user cannot access availability page", async ({ page }) => {
|
||||
test("regular user and unauthenticated user cannot access availability page", async ({
|
||||
page,
|
||||
}) => {
|
||||
// Test unauthenticated access
|
||||
await clearAuth(page);
|
||||
await loginUser(page, REGULAR_USER.email, REGULAR_USER.password);
|
||||
|
||||
await page.goto("/admin/availability");
|
||||
await expect(page).toHaveURL("/login");
|
||||
|
||||
// Should be redirected (to counter/home for regular users)
|
||||
await expect(page).not.toHaveURL("/admin/availability");
|
||||
});
|
||||
|
||||
test("regular user does not see Availability link", async ({ page }) => {
|
||||
await clearAuth(page);
|
||||
// Test regular user access
|
||||
await loginUser(page, REGULAR_USER.email, REGULAR_USER.password);
|
||||
|
||||
await page.goto("/");
|
||||
|
||||
const availabilityLink = page.locator('a[href="/admin/availability"]');
|
||||
await expect(availabilityLink).toHaveCount(0);
|
||||
});
|
||||
|
||||
test("unauthenticated user redirected to login", async ({ page }) => {
|
||||
await clearAuth(page);
|
||||
|
||||
await page.goto("/admin/availability");
|
||||
|
||||
await expect(page).toHaveURL("/login");
|
||||
await expect(page).not.toHaveURL("/admin/availability");
|
||||
});
|
||||
});
|
||||
|
||||
test.describe("Availability API", () => {
|
||||
test("admin can set availability via API", async ({ page, request }) => {
|
||||
test("admin can set availability via API, regular user cannot", async ({ page, request }) => {
|
||||
// Test admin API access
|
||||
await clearAuth(page);
|
||||
await loginUser(page, ADMIN_USER.email, ADMIN_USER.password);
|
||||
|
||||
const cookies = await page.context().cookies();
|
||||
const authCookie = cookies.find((c) => c.name === "auth_token");
|
||||
|
||||
if (authCookie) {
|
||||
const dateStr = getTomorrowDateStr();
|
||||
|
||||
const response = await request.put(`${API_URL}/api/admin/availability`, {
|
||||
headers: {
|
||||
Cookie: `auth_token=${authCookie.value}`,
|
||||
|
|
@ -261,27 +235,23 @@ test.describe("Availability API", () => {
|
|||
expect(data.date).toBe(dateStr);
|
||||
expect(data.slots).toHaveLength(1);
|
||||
}
|
||||
});
|
||||
|
||||
test("regular user cannot access availability API", async ({ page, request }) => {
|
||||
// Test regular user API access
|
||||
await clearAuth(page);
|
||||
await loginUser(page, REGULAR_USER.email, REGULAR_USER.password);
|
||||
const regularCookies = await page.context().cookies();
|
||||
const regularAuthCookie = regularCookies.find((c) => c.name === "auth_token");
|
||||
|
||||
const cookies = await page.context().cookies();
|
||||
const authCookie = cookies.find((c) => c.name === "auth_token");
|
||||
|
||||
if (authCookie) {
|
||||
if (regularAuthCookie) {
|
||||
const dateStr = getTomorrowDateStr();
|
||||
|
||||
const response = await request.get(
|
||||
`${API_URL}/api/admin/availability?from=${dateStr}&to=${dateStr}`,
|
||||
{
|
||||
headers: {
|
||||
Cookie: `auth_token=${authCookie.value}`,
|
||||
Cookie: `auth_token=${regularAuthCookie.value}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
expect(response.status()).toBe(403);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue