template-saas/apps/frontend/tests/e2e/fixtures/auth.fixture.ts
rckrdmrd 50a821a415
Some checks failed
CI / Backend CI (push) Has been cancelled
CI / Frontend CI (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / CI Summary (push) Has been cancelled
[SIMCO-V38] feat: Actualizar a SIMCO v3.8.0
- HERENCIA-SIMCO.md actualizado con directivas v3.7 y v3.8
- Actualizaciones de configuracion

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 08:53:08 -06:00

116 lines
2.8 KiB
TypeScript

import { test as base, expect, Page } from '@playwright/test';
// Test user credentials
export const testUser = {
email: 'test@example.com',
password: 'TestPassword123!',
firstName: 'Test',
lastName: 'User',
};
export const adminUser = {
email: 'admin@example.com',
password: 'AdminPassword123!',
firstName: 'Admin',
lastName: 'User',
};
// Auth fixture type
type AuthFixture = {
authenticatedPage: Page;
adminPage: Page;
};
/**
* Extended test with authentication fixtures
*/
export const test = base.extend<AuthFixture>({
authenticatedPage: async ({ page }, use) => {
// Login before test
await loginAs(page, testUser.email, testUser.password);
await use(page);
},
adminPage: async ({ page }, use) => {
// Login as admin before test
await loginAs(page, adminUser.email, adminUser.password);
await use(page);
},
});
/**
* Login helper function
*/
export async function loginAs(
page: Page,
email: string,
password: string
): Promise<void> {
await page.goto('/auth/login');
await page.fill('input[name="email"]', email);
await page.fill('input[name="password"]', password);
await page.click('button[type="submit"]');
// Wait for redirect to dashboard
await page.waitForURL(/\/(dashboard|onboarding)/, { timeout: 10000 });
}
/**
* Logout helper function
*/
export async function logout(page: Page): Promise<void> {
// Click user menu
await page.click('[data-testid="user-menu"]');
await page.click('[data-testid="logout-button"]');
// Wait for redirect to login
await page.waitForURL('/auth/login');
}
/**
* Register a new user
*/
export async function registerUser(
page: Page,
userData: {
email: string;
password: string;
firstName: string;
lastName: string;
companyName?: string;
}
): Promise<void> {
await page.goto('/auth/register');
await page.fill('input[name="firstName"]', userData.firstName);
await page.fill('input[name="lastName"]', userData.lastName);
await page.fill('input[name="email"]', userData.email);
await page.fill('input[name="password"]', userData.password);
if (userData.companyName) {
await page.fill('input[name="companyName"]', userData.companyName);
}
await page.click('button[type="submit"]');
// Wait for redirect (either to onboarding or verification page)
await page.waitForURL(/\/(onboarding|verify-email)/, { timeout: 10000 });
}
/**
* Check if user is authenticated
*/
export async function isAuthenticated(page: Page): Promise<boolean> {
try {
// Check for auth token in localStorage or auth indicator in UI
const token = await page.evaluate(() => {
return localStorage.getItem('auth_token') || sessionStorage.getItem('auth_token');
});
return !!token;
} catch {
return false;
}
}
export { expect };