forked from cartsnitch/cartsnitch
fix(e2e): await route mocks and add session mocking to all tests
- Make mockAuthRoutes async and await all page.route() calls to prevent race conditions - Add auth route mocking to J8 unauth tests (required since VITE_MOCK_AUTH was removed) - Add auth route mocking to smoke test - Replace broken mockSessionPending with mockSessionDelayed for spinner test Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
+7
-6
@@ -14,8 +14,8 @@ export { expect } from "@playwright/test";
|
||||
const MOCK_USER_ID = "mock_user_123";
|
||||
const MOCK_SESSION_ID = "mock_session_456";
|
||||
|
||||
function mockAuthRoutes(page: Page, authenticated = false) {
|
||||
page.route(/.*\/auth\/sign-up\/email.*/, async (route) => {
|
||||
async function mockAuthRoutes(page: Page, authenticated = false) {
|
||||
await page.route(/.*\/auth\/sign-up\/email.*/, async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: "application/json",
|
||||
@@ -33,7 +33,7 @@ function mockAuthRoutes(page: Page, authenticated = false) {
|
||||
});
|
||||
});
|
||||
|
||||
page.route(/.*\/auth\/sign-in\/email.*/, async (route) => {
|
||||
await page.route(/.*\/auth\/sign-in\/email.*/, async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: "application/json",
|
||||
@@ -52,7 +52,7 @@ function mockAuthRoutes(page: Page, authenticated = false) {
|
||||
});
|
||||
});
|
||||
|
||||
page.route(/.*\/auth\/get-session.*/, async (route) => {
|
||||
await page.route(/.*\/auth\/get-session.*/, async (route) => {
|
||||
if (authenticated) {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
@@ -86,8 +86,9 @@ function mockAuthRoutes(page: Page, authenticated = false) {
|
||||
});
|
||||
}
|
||||
|
||||
export function mockSessionPending(page: Page) {
|
||||
page.route(/.*\/auth\/session.*/, async (route) => {
|
||||
export async function mockSessionDelayed(page: Page, delayMs = 3000) {
|
||||
await page.route(/.*\/auth\/get-session.*/, async (route) => {
|
||||
await new Promise((r) => setTimeout(r, delayMs));
|
||||
await route.fulfill({
|
||||
status: 401,
|
||||
contentType: "application/json",
|
||||
|
||||
Reference in New Issue
Block a user