test(storefront): phase 3 auth, deep-links, profile & logout E2E tests

This commit is contained in:
Urvish Prajapati 2026-11-27 15:36:02 +05:30
parent fc7660e672
commit 3371c4a3e5
2 changed files with 193 additions and 0 deletions

View File

@ -0,0 +1,106 @@
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();
});
});

View File

@ -0,0 +1,87 @@
import { test, expect } from '@playwright/test';
import { mockAuthenticatedUser, mockPublicStoreApis } from './fixtures/apiMocks';
test.describe('Profile Drawer & Logout Flows', () => {
test('updates profile details and logs out cleanly', async ({ page }) => {
await mockPublicStoreApis(page);
await mockAuthenticatedUser(page, {
display_name: 'Dr. Initial',
phone_number: '+919876543210',
country: 'India',
});
await page.route('**/api/auth/profile', async (route) => {
if (route.request().method() === 'PUT') {
const body = route.request().postDataJSON();
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
id: 'user-1',
email: 'practitioner@acupedia.in',
display_name: body.display_name,
phone_number: body.phone_number,
country: body.country,
}),
});
return;
}
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
id: 'user-1',
email: 'practitioner@acupedia.in',
display_name: 'Dr. Initial',
phone_number: '+919876543210',
country: 'India',
}),
});
});
await page.goto('./');
// Open Profile Drawer via header avatar/button (shows 'Dr. Initial' on desktop, 'D' on mobile)
await page.locator('header button').filter({ hasText: /^D/ }).first().click();
await expect(page.getByText('Save Profile Details')).toBeVisible();
// Update Display Name and save
const nameInput = page.locator('input[value="Dr. Initial"]');
await nameInput.fill('Dr. Updated');
await page.getByRole('button', { name: 'Save Profile Details' }).click();
await expect(page.getByText(/Changes saved successfully!/i)).toBeVisible();
// Logout -> LoggedOutView
await page.getByRole('button', { name: /Log Out/i }).click();
await expect(page.getByText('Successfully Logged Out')).toBeVisible();
});
test('changes password and shows PasswordUpdatedModal', async ({ page }) => {
await mockPublicStoreApis(page);
await mockAuthenticatedUser(page, {
display_name: 'Dr. Initial',
phone_number: '+919876543210',
country: 'India',
});
await page.route('**/api/auth/change-password', async (route) => {
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({ message: 'Password updated successfully!' }),
});
});
await page.goto('./');
await page.locator('header button').filter({ hasText: /^D/ }).first().click();
await expect(page.getByText('Save Profile Details')).toBeVisible();
await page.getByRole('button', { name: 'Change Password' }).click();
await page.getByPlaceholder('Enter current password').fill('OldPass1!');
await page.getByPlaceholder('Min 8 chars, 1 uppercase, 1 digit, 1 special').fill('NewPass1!');
await page.getByPlaceholder('Repeat new password').fill('NewPass1!');
await page.getByRole('button', { name: 'Update Password' }).click();
await expect(page.getByText(/Password Updated/i)).toBeVisible();
});
});