e2e tests added. Core & Authentication

This commit is contained in:
AG
2025-12-08 10:18:42 +02:00
parent d284563301
commit 615c3a0cb7
16 changed files with 740 additions and 133 deletions

55
tests/fixtures.ts Normal file
View File

@@ -0,0 +1,55 @@
import { test as base, expect } from '@playwright/test';
import { request } from '@playwright/test';
// Define the type for our custom fixtures
type MyFixtures = {
createUniqueUser: () => Promise<{ email: string, password: string, id: string }>;
};
// Extend the base test with our custom fixture
export const test = base.extend<MyFixtures>({
createUniqueUser: async ({ }, use) => {
// We use a new API context for setup to avoid polluting request history,
// although setup requests are usually separate anyway.
const apiContext = await request.newContext({
baseURL: 'http://localhost:3001' // Direct access to backend
});
// Setup: Helper function to create a user
const createUser = async () => {
const uniqueId = Math.random().toString(36).substring(7);
const email = `test.user.${uniqueId}@example.com`;
const password = 'StrongPassword123!';
const response = await apiContext.post('/api/auth/register', {
data: {
email,
password
}
});
const body = await response.json();
// If registration fails because we hit a collision (unlikely) or other error, fail the test
if (!response.ok()) {
console.error(`REGISTRATION FAILED: ${response.status()} ${response.statusText()}`);
console.error(`RESPONSE BODY: ${JSON.stringify(body, null, 2)}`);
throw new Error(`Failed to register user: ${JSON.stringify(body)}`);
}
return { email, password, id: body.user.id };
};
// Use the fixture
await use(createUser);
// Cleanup: In a real "test:full" env with ephemeral db, cleanup might not be needed.
// But if we want to be clean, we can delete the user.
// Requires admin privileges usually, or specific delete-me endpoint.
// Given the requirements "delete own account" exists (5.6), we could theoretically login and delete.
// For now we skip auto-cleanup to keep it simple, assuming test DB is reset periodically.
},
});
export { expect };