learning_ai_common_plat/dashboards/admin-web/e2e/smartauth-account-linking.spec.ts
saravanakumardb1 0c4e53a0ed feat(auth): Phase 6 — enterprise SAML/OIDC, magic link, HIBP, E2E specs
6A: Enterprise IdP CRUD, SAML callback, OIDC callback, email domain lookup
6B: Magic link send/verify (15min TTL, anti-enumeration), HIBP breach check
6D: 3 new E2E specs (account-linking, step-up, enterprise) — total 8 SmartAuth specs
- All 53 auth tests passing
2026-03-12 15:25:28 -07:00

72 lines
2.3 KiB
TypeScript

/**
* SmartAuth E2E — Account Linking
* Tests OAuth provider linking/unlinking flows in admin dashboard.
*/
import { test, expect } from '@playwright/test';
test.describe('SmartAuth: Account Linking', () => {
test.beforeEach(async ({ page }) => {
// Mock auth state — logged in as admin
await page.route('**/api/auth/me', route =>
route.fulfill({
status: 200,
body: JSON.stringify({
id: 'usr_test',
email: 'admin@acme.com',
role: 'admin',
displayName: 'Test Admin',
providers: [{ provider: 'google', email: 'admin@acme.com', linkedAt: '2026-01-01' }],
mfaEnabled: false,
}),
})
);
});
test('should display linked providers', async ({ page }) => {
await page.route('**/api/auth/providers', route =>
route.fulfill({
status: 200,
body: JSON.stringify([
{ provider: 'google', email: 'admin@acme.com', linkedAt: '2026-01-01T00:00:00Z' },
]),
})
);
await page.goto('/settings/security');
await expect(page.getByText('Google')).toBeVisible();
await expect(page.getByText('admin@acme.com')).toBeVisible();
});
test('should show link provider button', async ({ page }) => {
await page.route('**/api/auth/providers', route =>
route.fulfill({ status: 200, body: JSON.stringify([]) })
);
await page.goto('/settings/security');
await expect(page.getByRole('button', { name: /link/i })).toBeVisible();
});
test('should prevent unlinking last provider', async ({ page }) => {
await page.route('**/api/auth/providers', route =>
route.fulfill({
status: 200,
body: JSON.stringify([
{ provider: 'google', email: 'admin@acme.com', linkedAt: '2026-01-01T00:00:00Z' },
]),
})
);
await page.route('**/api/auth/providers/google', route =>
route.fulfill({
status: 400,
body: JSON.stringify({ error: 'Cannot unlink last auth method' }),
})
);
await page.goto('/settings/security');
// Attempt unlink
const unlinkButton = page.getByRole('button', { name: /unlink/i });
if (await unlinkButton.isVisible()) {
await unlinkButton.click();
await expect(page.getByText(/cannot unlink/i)).toBeVisible();
}
});
});