refactor: bookings failures should be caught faster (#18817)

* refactor: bookings failures should be caught faster

* fix for expected failures

* Update booking-pages.e2e.ts
This commit is contained in:
Omar López authored and GitHub committed 2025-01-23 05:52:42 +05:30
1 parent 1af3caa8cc
commit 3765c76c96
3 files changed
+31 -29

No files matched your search

+4 -4
View File
@@ -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 });
});
+11 -23
View File
@@ -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();
+16 -2
View File
@@ -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,