diff --git a/e2e/journeys/j1-registration-login.spec.ts b/e2e/journeys/j1-registration-login.spec.ts index e860f4f..c5122a1 100644 --- a/e2e/journeys/j1-registration-login.spec.ts +++ b/e2e/journeys/j1-registration-login.spec.ts @@ -4,7 +4,7 @@ import { mockAuthRoutes } from '../fixtures'; const uniqueEmail = () => `betty+e2e-${Date.now()}@cartsnitch.test`; test.describe('J1: Registration and Login', () => { - test('can register a new account and lands on dashboard', async ({ page }) => { + test('can register a new account and see check your email screen', async ({ page }) => { mockAuthRoutes(page, true); await page.goto('/register'); await page.fill('[placeholder="Full Name"]', 'Betty Tester'); @@ -12,8 +12,7 @@ test.describe('J1: Registration and Login', () => { await page.fill('[placeholder="Password (min. 8 characters)"]', 'TestPass123!'); await page.click('button[type="submit"]'); - await expect(page).toHaveURL('http://localhost:5173/'); - await expect(page.getByRole('heading', { name: /cart/i })).toBeVisible(); + await expect(page.getByRole('heading', { name: /check your email/i })).toBeVisible(); }); test('shows validation error when registration fields are empty', async ({ page }) => { @@ -32,20 +31,9 @@ test.describe('J1: Registration and Login', () => { }); test('can sign in with credentials and land on dashboard', async ({ page }) => { - const email = uniqueEmail(); mockAuthRoutes(page, true); - await page.goto('/register'); - await page.fill('[placeholder="Full Name"]', 'Login Betty'); - await page.fill('[placeholder="Email"]', email); - await page.fill('[placeholder="Password (min. 8 characters)"]', 'TestPass123!'); - await page.click('button[type="submit"]'); - await expect(page).toHaveURL('http://localhost:5173/'); - - await page.goto('/'); - await page.reload(); - await page.goto('/login'); - await page.fill('[placeholder="Email"]', email); + await page.fill('[placeholder="Email"]', 'test@cartsnitch.test'); await page.fill('[placeholder="Password"]', 'TestPass123!'); await page.click('button[type="submit"]'); diff --git a/e2e/journeys/j8-unauth-access.spec.ts b/e2e/journeys/j8-unauth-access.spec.ts index 9ed40da..f729edd 100644 --- a/e2e/journeys/j8-unauth-access.spec.ts +++ b/e2e/journeys/j8-unauth-access.spec.ts @@ -1,8 +1,9 @@ import { test, expect } from '@playwright/test'; +import { mockAuthRoutes } from '../fixtures'; test.describe('J8: Unauthenticated Access', () => { test('redirects /dashboard (/) to /login when not authenticated', async ({ page }) => { - // No session cookie — start fresh + mockAuthRoutes(page, false); await page.context().clearCookies(); await page.goto('/'); @@ -11,6 +12,7 @@ test.describe('J8: Unauthenticated Access', () => { }); test('redirects /purchases to /login when not authenticated', async ({ page }) => { + mockAuthRoutes(page, false); await page.context().clearCookies(); await page.goto('/purchases'); @@ -19,6 +21,7 @@ test.describe('J8: Unauthenticated Access', () => { }); test('redirects /products to /login when not authenticated', async ({ page }) => { + mockAuthRoutes(page, false); await page.context().clearCookies(); await page.goto('/products'); @@ -27,6 +30,7 @@ test.describe('J8: Unauthenticated Access', () => { }); test('redirects /coupons to /login when not authenticated', async ({ page }) => { + mockAuthRoutes(page, false); await page.context().clearCookies(); await page.goto('/coupons'); @@ -35,15 +39,9 @@ test.describe('J8: Unauthenticated Access', () => { }); test('shows loading spinner while auth session is pending', async ({ page }) => { - // Intercept but don't respond — session stays pending + mockAuthRoutes(page, false); await page.context().clearCookies(); - await page.request.fetch('/api/auth/session', { - method: 'GET', - }); - - // Just navigate to a protected route — ProtectedRoute will show spinner while session is pending await page.goto('/purchases'); - // Spinner is visible briefly; once resolved, should redirect to login await expect(page).toHaveURL(/\/login/, { timeout: 10_000 }); }); }); diff --git a/e2e/smoke.spec.ts b/e2e/smoke.spec.ts index 2819d15..4409a08 100644 --- a/e2e/smoke.spec.ts +++ b/e2e/smoke.spec.ts @@ -1,6 +1,7 @@ -import { test, expect } from './fixtures'; +import { test, expect, mockAuthRoutes } from './fixtures'; test('app loads', async ({ page }) => { + mockAuthRoutes(page, false); await page.goto('/'); // Unauthenticated users are redirected to /login await expect(page).toHaveURL(/\/login/); diff --git a/playwright.config.ts b/playwright.config.ts index a2d7b0b..43843e3 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -12,6 +12,9 @@ export default defineConfig({ command: 'npm run dev', url: 'http://localhost:5173', reuseExistingServer: !process.env.CI, + env: { + VITE_MOCK_AUTH: 'true', + }, }, use: { baseURL: 'http://localhost:5173',