107 lines
4.0 KiB
TypeScript
107 lines
4.0 KiB
TypeScript
import { test, expect } from '@playwright/test';
|
|
import { mockPublicStoreApis } from './fixtures/apiMocks';
|
|
|
|
test.describe('Authentication & Deep-Link Flows', () => {
|
|
test.beforeEach(async ({ page }) => {
|
|
await mockPublicStoreApis(page);
|
|
});
|
|
|
|
test('login handles invalid credentials and succeeds with valid credentials', async ({ page }) => {
|
|
await page.route('**/api/auth/login', async (route) => {
|
|
const body = route.request().postDataJSON();
|
|
if (body.password === 'WrongPass1!') {
|
|
await route.fulfill({
|
|
status: 401,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({ detail: 'Invalid email or password.' }),
|
|
});
|
|
return;
|
|
}
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({ access_token: 'new-jwt-token' }),
|
|
});
|
|
});
|
|
|
|
await page.route('**/api/auth/profile', async (route) => {
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({
|
|
id: 'user-1',
|
|
email: 'doctor@acupedia.in',
|
|
display_name: 'Dr. Acupedia',
|
|
phone_number: '+919876543210',
|
|
country: 'India',
|
|
}),
|
|
});
|
|
});
|
|
|
|
await page.route('**/api/access/me', async (route) => {
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({ active_subscriptions: [], unlocked_module_codes: [], unlocked_module_slugs: [] }),
|
|
});
|
|
});
|
|
|
|
await page.goto('./');
|
|
await page.getByRole('button', { name: /Login/i }).first().click();
|
|
await expect(page.getByText('Welcome Back!')).toBeVisible();
|
|
|
|
await page.getByPlaceholder('doctor@example.com').fill('doctor@acupedia.in');
|
|
await page.locator('input[type="password"]').fill('WrongPass1!');
|
|
await page.locator('form button[type="submit"]').click();
|
|
await expect(page.getByText('Invalid email or password.')).toBeVisible();
|
|
|
|
await page.locator('input[type="password"]').fill('ValidPass1!');
|
|
await page.locator('form button[type="submit"]').click();
|
|
await expect(page.getByText('Welcome Back!')).not.toBeVisible();
|
|
await expect(page.getByText('Billing Currency:')).toBeVisible();
|
|
});
|
|
|
|
test('forgot password requests OTP and resets password', async ({ page }) => {
|
|
await page.route('**/api/auth/forgot-password', async (route) => {
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({ message: 'OTP sent to your email.' }),
|
|
});
|
|
});
|
|
|
|
await page.route('**/api/auth/reset-password', async (route) => {
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({ message: 'Password reset successful.' }),
|
|
});
|
|
});
|
|
|
|
await page.goto('./?login=true');
|
|
await expect(page.getByText('Welcome Back!')).toBeVisible();
|
|
|
|
await page.getByRole('button', { name: /Forgot/i }).click();
|
|
await expect(page.getByText('Reset Password')).toBeVisible();
|
|
|
|
await page.getByPlaceholder('doctor@example.com').fill('doctor@acupedia.in');
|
|
await page.getByRole('button', { name: 'Send Verification Code' }).click();
|
|
|
|
await expect(page.getByPlaceholder('123456')).toBeVisible();
|
|
await page.getByPlaceholder('123456').fill('654321');
|
|
await page.getByPlaceholder('Min 8 chars (1 uppercase, 1 number, 1 special)').fill('NewPass123!');
|
|
await page.getByPlaceholder('Re-enter new password').fill('NewPass123!');
|
|
await page.getByRole('button', { name: 'Set New Password' }).click();
|
|
|
|
await expect(page.getByText(/Password Updated/i)).toBeVisible();
|
|
});
|
|
|
|
test('deep-link ?planCode=THERAPEUTICS_EAR pre-selects Ear reflexology in cart', async ({ page }) => {
|
|
await page.goto('./?planCode=THERAPEUTICS_EAR');
|
|
|
|
await expect(page.getByText('1 Item')).toBeVisible();
|
|
await expect(page.getByText('Therapeutics: Ear reflexology').last()).toBeVisible();
|
|
await expect(page.getByText('Lifetime Unlimited Access Pass').nth(1)).toBeVisible();
|
|
});
|
|
});
|