diff --git a/apps/web/playwright/booking-limits.e2e.ts b/apps/web/playwright/booking-limits.e2e.ts index 7da50a00fc..2089dcefca 100644 --- a/apps/web/playwright/booking-limits.e2e.ts +++ b/apps/web/playwright/booking-limits.e2e.ts @@ -131,7 +131,7 @@ test.describe("Booking limits", () => { // try to book directly via form page await page.goto(slotUrl); - await bookTimeSlot(page); + await bookTimeSlot(page, { expectedStatusCode: 401 }); await expect(page.getByTestId("booking-fail")).toBeVisible({ timeout: 1000 }); }); @@ -266,7 +266,7 @@ test.describe("Booking limits", () => { // try to book directly via form page await page.goto(slotUrl); - await bookTimeSlot(page); + await bookTimeSlot(page, { expectedStatusCode: 401 }); await expect(page.getByTestId("booking-fail")).toBeVisible({ timeout: 5000 }); }); @@ -357,7 +357,7 @@ test.describe("Duration limits", () => { // try to book directly via form page await page.goto(slotUrl); - await bookTimeSlot(page); + await bookTimeSlot(page, { expectedStatusCode: 401 }); await expect(page.getByTestId("booking-fail")).toBeVisible({ timeout: 1000 }); }); @@ -452,7 +452,7 @@ test.describe("Duration limits", () => { // try to book directly via form page await page.goto(slotUrl); - await bookTimeSlot(page); + await bookTimeSlot(page, { expectedStatusCode: 401 }); await expect(page.getByTestId("booking-fail")).toBeVisible({ timeout: 1000 }); }); diff --git a/apps/web/playwright/booking-pages.e2e.ts b/apps/web/playwright/booking-pages.e2e.ts index 6d7972e863..015460d9bb 100644 --- a/apps/web/playwright/booking-pages.e2e.ts +++ b/apps/web/playwright/booking-pages.e2e.ts @@ -11,6 +11,7 @@ import { bookFirstEvent, bookOptinEvent, bookTimeSlot, + confirmBooking, confirmReschedule, selectFirstAvailableTimeSlotNextMonth, testEmail, @@ -92,7 +93,10 @@ test.describe("free user", () => { await page.goto(bookingUrl); // book same time spot again - await bookTimeSlot(page); + await bookTimeSlot(page, { + /** FIXME: this should be a 409 conflict */ + expectedStatusCode: 500, + }); await page.locator("[data-testid=booking-fail]").waitFor({ state: "visible" }); }); @@ -260,7 +264,7 @@ test.describe("pro user", () => { // go back to the booking page to re-book. await page.goto(pageUrl); - await bookTimeSlot(page); + await bookTimeSlot(page, { expectedStatusCode: 409 }); await expect(page.getByText("Could not book the meeting.")).toBeVisible(); }); @@ -277,7 +281,7 @@ test.describe("pro user", () => { await page.locator('[data-testid="add-another-guest"]').click(); await page.locator('input[type="email"]').nth(2).fill(additionalGuests[1]); - await page.locator('[data-testid="confirm-book-button"]').click(); + await confirmBooking(page); await expect(page.locator("[data-testid=success-page]")).toBeVisible(); @@ -423,11 +427,7 @@ test.describe("Booking on different layouts", () => { await page.locator('[name="email"]').fill(`${randomString(4)}@example.com`); await page.locator('[name="notes"]').fill("Test notes"); - await page.click('[data-testid="confirm-book-button"]'); - - await page.waitForURL((url) => { - return url.pathname.startsWith("/booking"); - }); + await confirmBooking(page); // expect page to be booking page await expect(page.locator("[data-testid=success-page]")).toBeVisible(); @@ -448,11 +448,7 @@ test.describe("Booking on different layouts", () => { await page.locator('[name="email"]').fill(`${randomString(4)}@example.com`); await page.locator('[name="notes"]').fill("Test notes"); - await page.click('[data-testid="confirm-book-button"]'); - - await page.waitForURL((url) => { - return url.pathname.startsWith("/booking"); - }); + await confirmBooking(page); // expect page to be booking page await expect(page.locator("[data-testid=success-page]")).toBeVisible(); @@ -504,11 +500,7 @@ test.describe("Booking round robin event", () => { await page.locator('[name="name"]').fill("Test name"); await page.locator('[name="email"]').fill(`${randomString(4)}@example.com`); - await page.click('[data-testid="confirm-book-button"]'); - - await page.waitForURL((url) => { - return url.pathname.startsWith("/booking"); - }); + await confirmBooking(page); await expect(page.locator("[data-testid=success-page]")).toBeVisible(); @@ -534,11 +526,7 @@ test.describe("Booking round robin event", () => { await page.locator('[name="name"]').fill("Test name"); await page.locator('[name="email"]').fill(`${randomString(4)}@example.com`); - await page.click('[data-testid="confirm-book-button"]'); - - await page.waitForURL((url) => { - return url.pathname.startsWith("/booking"); - }); + await confirmBooking(page); await expect(page.locator("[data-testid=success-page]")).toBeVisible(); diff --git a/apps/web/playwright/lib/testUtils.ts b/apps/web/playwright/lib/testUtils.ts index 7d9b98cbaf..0552d6bdec 100644 --- a/apps/web/playwright/lib/testUtils.ts +++ b/apps/web/playwright/lib/testUtils.ts @@ -148,7 +148,13 @@ export async function bookFirstEvent(page: Page) { export const bookTimeSlot = async ( page: Page, - opts?: { name?: string; email?: string; title?: string; attendeePhoneNumber?: string } + opts?: { + name?: string; + email?: string; + title?: string; + attendeePhoneNumber?: string; + expectedStatusCode?: number; + } ) => { // --- fill form await page.fill('[name="name"]', opts?.name ?? testName); @@ -159,7 +165,10 @@ export const bookTimeSlot = async ( if (opts?.attendeePhoneNumber) { await page.fill('[name="attendeePhoneNumber"]', opts.attendeePhoneNumber ?? "+918888888888"); } - await page.press('[name="email"]', "Enter"); + await submitAndWaitForResponse(page, "/api/book/event", { + action: () => page.locator('[name="email"]').press("Enter"), + expectedStatusCode: opts?.expectedStatusCode, + }); }; // Provide an standalone localize utility not managed by next-i18n @@ -498,6 +507,11 @@ export async function confirmReschedule(page: Page, url = "/api/book/event") { action: () => page.locator('[data-testid="confirm-reschedule-button"]').click(), }); } +export async function confirmBooking(page: Page, url = "/api/book/event") { + await submitAndWaitForResponse(page, url, { + action: () => page.locator('[data-testid="confirm-book-button"]').click(), + }); +} export async function bookTeamEvent({ page,