test(frontend): add real-auth Playwright e2e suite
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
26
frontend/e2e/helpers.ts
Normal file
26
frontend/e2e/helpers.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { expect, type Page } from '@playwright/test';
|
||||
|
||||
/** A fresh, unique account per call so tests never collide in the shared test DB. */
|
||||
export function uniqueUser() {
|
||||
const id = `${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
|
||||
return { username: `e2e_${id}`, password: 'password123' };
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a brand-new user and logs in via the real /api/auth flow.
|
||||
* `page.request` shares the browser context's cookie jar, so the session
|
||||
* cookie it sets makes subsequent page navigations authenticated.
|
||||
*/
|
||||
export async function registerAndLogin(page: Page) {
|
||||
const user = uniqueUser();
|
||||
const register = await page.request.post('/api/auth/register', { data: user });
|
||||
expect(register.ok(), 'register should succeed').toBeTruthy();
|
||||
const login = await page.request.post('/api/auth/login', { data: user });
|
||||
expect(login.ok(), 'login should succeed').toBeTruthy();
|
||||
return user;
|
||||
}
|
||||
|
||||
/** A small in-memory upload fixture (no files on disk needed). */
|
||||
export function textFile(name: string) {
|
||||
return { name, mimeType: 'text/plain', buffer: Buffer.from('e2e test content') };
|
||||
}
|
||||
Reference in New Issue
Block a user