test: add E2E tests for price history feature

This commit is contained in:
counterweight 2025-12-22 15:56:12 +01:00
parent 9db43c474e
commit dd7bec6091
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C

View file

@ -0,0 +1,74 @@
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 (to "/" since fallbackRedirect is "/")
await expect(page).toHaveURL("/");
});
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 audit page by default
await expect(page).toHaveURL("/audit");
// 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");
});
});