40 lines
1.7 KiB
TypeScript
40 lines
1.7 KiB
TypeScript
import { expect, test } from '@playwright/test'
|
|
|
|
/**
|
|
* The auth happy path end to end against the live stack: register a brand-new
|
|
* account, log in with it, land on the authenticated app, then log out.
|
|
*
|
|
* Uses a unique email per run because this hits the real database (a duplicate
|
|
* email would 422 on register).
|
|
*/
|
|
test('register, log in, then log out', async ({ page }) => {
|
|
const email = `e2e-${Date.now()}@example.com`
|
|
const password = 'correct-horse-battery-staple'
|
|
|
|
// --- Register -----------------------------------------------------------
|
|
await page.goto('/register')
|
|
await page.getByLabel(/email/i).fill(email)
|
|
await page.getByLabel(/password/i).fill(password)
|
|
await page.getByRole('button', { name: /register/i }).click()
|
|
|
|
// Register does not auto-login — it redirects to the login screen.
|
|
await expect(page).toHaveURL(/\/login$/)
|
|
await expect(page.getByRole('button', { name: /log in/i })).toBeVisible()
|
|
|
|
// --- Log in -------------------------------------------------------------
|
|
await page.getByLabel(/email/i).fill(email)
|
|
await page.getByLabel(/password/i).fill(password)
|
|
await page.getByRole('button', { name: /log in/i }).click()
|
|
|
|
// Lands on the authenticated app (the scenarios placeholder + the logout
|
|
// control in the authed layout).
|
|
await expect(page.getByText(/emergency fund/i)).toBeVisible()
|
|
await expect(page.getByRole('button', { name: /log out/i })).toBeVisible()
|
|
|
|
// --- Log out ------------------------------------------------------------
|
|
await page.getByRole('button', { name: /log out/i }).click()
|
|
|
|
// Back to the login screen; the authed content is gone.
|
|
await expect(page).toHaveURL(/\/login$/)
|
|
await expect(page.getByText(/emergency fund/i)).toHaveCount(0)
|
|
})
|