Add E2E tests for OAuth authentication flows and provider integrations
- Implemented comprehensive E2E tests for OAuth buttons on login and register pages, including Google and GitHub provider interactions. - Verified OAuth provider buttons' visibility, icons, and proper API integration with mock endpoints. - Added button interaction tests to ensure correct API calls for authorization and state handling. - Updated `playwright.config.ts` to include the new `auth-oauth.spec.ts` in test configurations. - Extended mock handlers in `overrides.ts` and `auth.ts` to support OAuth-specific API workflows and demo scenarios.
This commit is contained in:
@@ -227,6 +227,43 @@ export async function setupAuthenticatedMocks(page: Page): Promise<void> {
|
||||
}
|
||||
});
|
||||
|
||||
// Mock GET /api/v1/oauth/providers - Get available OAuth providers
|
||||
await page.route(`${baseURL}/api/v1/oauth/providers`, async (route: Route) => {
|
||||
if (route.request().method() === 'GET') {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
enabled: true,
|
||||
providers: [
|
||||
{ provider: 'google', name: 'Google' },
|
||||
{ provider: 'github', name: 'GitHub' },
|
||||
],
|
||||
}),
|
||||
});
|
||||
} else {
|
||||
await route.continue();
|
||||
}
|
||||
});
|
||||
|
||||
// Mock GET /api/v1/oauth/authorize/:provider - Get OAuth authorization URL
|
||||
await page.route(`${baseURL}/api/v1/oauth/authorize/*`, async (route: Route) => {
|
||||
if (route.request().method() === 'GET') {
|
||||
const url = route.request().url();
|
||||
const provider = url.match(/authorize\/(\w+)/)?.[1] || 'google';
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
authorization_url: `https://mock-oauth.example.com/authorize?provider=${provider}`,
|
||||
state: 'mock-state-token',
|
||||
}),
|
||||
});
|
||||
} else {
|
||||
await route.continue();
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* E2E tests now use the REAL auth store with mocked API routes.
|
||||
* We inject authentication by calling setAuth() directly in the page context.
|
||||
@@ -579,4 +616,41 @@ export async function setupSuperuserMocks(page: Page): Promise<void> {
|
||||
await route.continue();
|
||||
}
|
||||
});
|
||||
|
||||
// Mock GET /api/v1/oauth/providers - Get available OAuth providers
|
||||
await page.route(`${baseURL}/api/v1/oauth/providers`, async (route: Route) => {
|
||||
if (route.request().method() === 'GET') {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
enabled: true,
|
||||
providers: [
|
||||
{ provider: 'google', name: 'Google' },
|
||||
{ provider: 'github', name: 'GitHub' },
|
||||
],
|
||||
}),
|
||||
});
|
||||
} else {
|
||||
await route.continue();
|
||||
}
|
||||
});
|
||||
|
||||
// Mock GET /api/v1/oauth/authorize/:provider - Get OAuth authorization URL
|
||||
await page.route(`${baseURL}/api/v1/oauth/authorize/*`, async (route: Route) => {
|
||||
if (route.request().method() === 'GET') {
|
||||
const url = route.request().url();
|
||||
const provider = url.match(/authorize\/(\w+)/)?.[1] || 'google';
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
authorization_url: `https://mock-oauth.example.com/authorize?provider=${provider}`,
|
||||
state: 'mock-state-token',
|
||||
}),
|
||||
});
|
||||
} else {
|
||||
await route.continue();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user