- Updated auth-context.tsx to use new exchange permissions (CREATE_EXCHANGE, VIEW_OWN_EXCHANGES, etc.) instead of old appointment permissions (BOOK_APPOINTMENT, etc.) - Updated exchange/page.tsx, trades/page.tsx, admin/trades/page.tsx to use correct permission constants - Updated profile/page.test.tsx mock permissions - Updated admin/availability/page.tsx to use constants.exchange instead of constants.booking - Added /api/exchange/slots endpoint to return available slots for a date, filtering out already booked slots - Fixed E2E tests: - exchange.spec.ts: Wait for button to be enabled before clicking - permissions.spec.ts: Use more specific heading selector - price-history.spec.ts: Expect /exchange redirect for regular users
74 lines
2.7 KiB
TypeScript
74 lines
2.7 KiB
TypeScript
import { test, expect } from "@playwright/test";
|
|
import { clearAuth, loginUser, REGULAR_USER, ADMIN_USER } from "./helpers/auth";
|
|
|
|
test.describe("Price History - E2E", () => {
|
|
test("admin can view price history page", async ({ page }) => {
|
|
await clearAuth(page);
|
|
await loginUser(page, ADMIN_USER.email, ADMIN_USER.password);
|
|
|
|
await page.goto("/admin/price-history");
|
|
await expect(page).toHaveURL("/admin/price-history");
|
|
|
|
// Page title should be visible
|
|
await expect(page.locator("h2")).toContainText("Bitcoin Price History");
|
|
|
|
// Table should exist
|
|
await expect(page.locator("table")).toBeVisible();
|
|
|
|
// Fetch Now button should exist
|
|
await expect(page.getByRole("button", { name: "Fetch Now" })).toBeVisible();
|
|
});
|
|
|
|
test("admin can manually fetch price from Bitfinex", async ({ page }) => {
|
|
await clearAuth(page);
|
|
await loginUser(page, ADMIN_USER.email, ADMIN_USER.password);
|
|
|
|
await page.goto("/admin/price-history");
|
|
await expect(page).toHaveURL("/admin/price-history");
|
|
|
|
// Click the Fetch Now button
|
|
await page.getByRole("button", { name: "Fetch Now" }).click();
|
|
|
|
// Wait for the button to become enabled again (fetch completed)
|
|
await expect(page.getByRole("button", { name: "Fetch Now" })).toBeEnabled({
|
|
timeout: 10000,
|
|
});
|
|
|
|
// The table should now contain a record with bitfinex as source
|
|
await expect(page.locator("table tbody")).toContainText("bitfinex");
|
|
|
|
// Should have BTC/EUR pair
|
|
await expect(page.locator("table tbody")).toContainText("BTC/EUR");
|
|
|
|
// Price should be visible and formatted as EUR
|
|
// The price cell should contain a € symbol
|
|
const priceCell = page.locator("table tbody tr td").nth(2);
|
|
await expect(priceCell).toContainText("€");
|
|
});
|
|
|
|
test("regular user cannot access price history page", async ({ page }) => {
|
|
await clearAuth(page);
|
|
await loginUser(page, REGULAR_USER.email, REGULAR_USER.password);
|
|
|
|
// Try to navigate directly to the admin page
|
|
await page.goto("/admin/price-history");
|
|
|
|
// Should be redirected away (regular users go to /exchange)
|
|
await expect(page).toHaveURL("/exchange");
|
|
});
|
|
|
|
test("price history shows in navigation for admin", async ({ page }) => {
|
|
await clearAuth(page);
|
|
await loginUser(page, ADMIN_USER.email, ADMIN_USER.password);
|
|
|
|
// Admin should be on admin trades page by default
|
|
await expect(page).toHaveURL("/admin/trades");
|
|
|
|
// Prices nav link should be visible
|
|
await expect(page.getByRole("link", { name: "Prices" })).toBeVisible();
|
|
|
|
// Click on Prices link
|
|
await page.getByRole("link", { name: "Prices" }).click();
|
|
await expect(page).toHaveURL("/admin/price-history");
|
|
});
|
|
});
|