import type { BrowserContext, Page } from '@playwright/test'; type E2ERole = 'ADMIN' | 'AGENT' | 'SELLER' | 'BUYER' | 'USER'; interface MockUserOptions { role?: E2ERole; } export async function mockAuthenticatedUser( page: Page, context: BrowserContext, baseURL?: string, options: MockUserOptions = {}, ) { const role = options.role ?? 'AGENT'; const cookieUrl = baseURL ?? 'http://localhost:3000'; await context.addCookies([ { name: 'goodgo_authenticated', value: '1', url: cookieUrl, }, ]); await page.route('**/auth/profile', (route) => route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ id: `e2e-${role.toLowerCase()}-user`, email: `${role.toLowerCase()}@e2e.goodgo.test`, phone: '+84900000002', fullName: `E2E ${role}`, avatarUrl: null, role, kycStatus: 'VERIFIED', isActive: true, createdAt: '2026-01-01T00:00:00.000Z', }), }), ); await page.route('**/auth/refresh', (route) => route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ message: 'refreshed' }), }), ); await page.route('**/notifications/unread-count', (route) => route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ count: 0 }), }), ); }