From 78a34038d21b30adf688f6f087fbaa453ce9ecdc Mon Sep 17 00:00:00 2001 From: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Date: Thu, 8 May 2025 11:41:21 +0530 Subject: [PATCH] test: add e2e test for round robin event types (#21159) Co-authored-by: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com> --- .../playwright/organization/booking.e2e.ts | 161 ++++++++++++++++++ 1 file changed, 161 insertions(+) diff --git a/apps/web/playwright/organization/booking.e2e.ts b/apps/web/playwright/organization/booking.e2e.ts index 035adeec27..27e034f860 100644 --- a/apps/web/playwright/organization/booking.e2e.ts +++ b/apps/web/playwright/organization/booking.e2e.ts @@ -295,6 +295,167 @@ test.describe("Bookings", () => { await page.goto(`/org/${org.slug}/${teamSlugUpperCase}/${teamEventSlugUpperCase}`); await page.waitForSelector("[data-testid=day]"); }); + + test("Round robin event type properly rotates hosts", async ({ page, users, orgs }) => { + const org = await orgs.create({ + name: "TestOrg", + }); + const teamMatesObj = [{ name: "teammate-1" }, { name: "teammate-2" }, { name: "teammate-3" }]; + + const owner = await users.create( + { + username: "pro-user", + name: "pro-user", + organizationId: org.id, + roleInOrganization: MembershipRole.MEMBER, + }, + { + hasTeam: true, + teammates: teamMatesObj, + schedulingType: SchedulingType.ROUND_ROBIN, + } + ); + + const { team } = await owner.getFirstTeamMembership(); + const teamEvent = await owner.getFirstTeamEvent(team.id); + const eventHostsObj = [...teamMatesObj, { name: "pro-user" }]; + + await doOnOrgDomain( + { + orgSlug: org.slug, + page, + }, + async () => { + await bookTeamEvent({ page, team, event: teamEvent, teamMatesObj: eventHostsObj }); + const firstHost = await page.getByTestId("booking-host-name").textContent(); + expect(firstHost).not.toBeNull(); + + // Second booking - should get a different host + await page.goto(`/org/${org.slug}/${team.slug}/${teamEvent.slug}`); + await selectFirstAvailableTimeSlotNextMonth(page); + await bookTimeSlot(page); + await expect(page.getByTestId("success-page")).toBeVisible(); + const secondHost = await page.getByTestId("booking-host-name").textContent(); + expect(secondHost).not.toBeNull(); + expect(secondHost).not.toBe(firstHost); + + // Third booking - should get a different host + await page.goto(`/org/${org.slug}/${team.slug}/${teamEvent.slug}`); + await selectFirstAvailableTimeSlotNextMonth(page); + await bookTimeSlot(page); + await expect(page.getByTestId("success-page")).toBeVisible(); + const thirdHost = await page.getByTestId("booking-host-name").textContent(); + expect(thirdHost).not.toBeNull(); + expect(thirdHost).not.toBe(firstHost); + expect(thirdHost).not.toBe(secondHost); + + // Fourth booking - should get a different host + await page.goto(`/org/${org.slug}/${team.slug}/${teamEvent.slug}`); + await selectFirstAvailableTimeSlotNextMonth(page); + await bookTimeSlot(page); + await expect(page.getByTestId("success-page")).toBeVisible(); + const fourthHost = await page.getByTestId("booking-host-name").textContent(); + expect(fourthHost).not.toBeNull(); + expect(fourthHost).not.toBe(firstHost); + expect(fourthHost).not.toBe(secondHost); + expect(fourthHost).not.toBe(thirdHost); + + // Verify all hosts were used + const allHosts = [firstHost, secondHost, thirdHost, fourthHost]; + const uniqueHosts = new Set(allHosts); + expect(uniqueHosts.size).toBe(4); + } + ); + }); + + test("Round robin event type with confirmation required handles cancellation and rebooking correctly with the same details and slot", async ({ + page, + users, + orgs, + }) => { + const org = await orgs.create({ + name: "TestOrg", + }); + const teamMatesObj = [ + { name: "teammate-1" }, + { name: "teammate-2" }, + { name: "teammate-3" }, + { name: "teammate-4" }, + ]; + + const owner = await users.create( + { + username: "pro-user", + name: "pro-user", + organizationId: org.id, + roleInOrganization: MembershipRole.MEMBER, + }, + { + hasTeam: true, + teammates: teamMatesObj, + schedulingType: SchedulingType.ROUND_ROBIN, + } + ); + + const { team } = await owner.getFirstTeamMembership(); + const teamEvent = await owner.getFirstTeamEvent(team.id); + const eventHostsObj = [...teamMatesObj, { name: "pro-user" }]; + + // Enable confirmation required for the event + await owner.apiLogin(); + await page.goto(`/event-types/${teamEvent.id}?tabName=advanced`); + await page.getByTestId("requires-confirmation").click(); + await page.getByTestId("update-eventtype").click(); + await page.waitForResponse((response) => response.url().includes("/api/trpc/eventTypes/update")); + + await doOnOrgDomain( + { + orgSlug: org.slug, + page, + }, + async () => { + await bookTeamEvent({ page, team, event: teamEvent, teamMatesObj: eventHostsObj }); + const firstHost = await page.getByTestId("booking-host-name").textContent(); + expect(firstHost).not.toBeNull(); + + const bookingUid = page.url().split("/booking/")[1]; + expect(bookingUid).not.toBeNull(); + + // Login as the host to cancel the booking + await page.goto("/auth/logout"); + const allUsers = await users.get(); + const hostUser = allUsers.find((mate) => mate.name === firstHost); + if (!hostUser) throw new Error("Host not found"); + + await hostUser.apiLogin(); + + // Cancel the booking + await page.goto(`/booking/${bookingUid}`); + await page.getByTestId("cancel").click(); + await page.getByTestId("confirm_cancel").click(); + await page.waitForResponse((response) => response.url().includes("/api/cancel")); + + // Logout and go back to booking page + await page.goto("/auth/logout"); + await page.goto(`/org/${org.slug}/${team.slug}/${teamEvent.slug}`); + + // Rebook with the same details + await selectFirstAvailableTimeSlotNextMonth(page); + await bookTimeSlot(page); + await expect(page.getByTestId("success-page")).toBeVisible(); + + // Verify a new host is assigned + const newHost = await page.getByTestId("booking-host-name").textContent(); + expect(newHost).not.toBeNull(); + expect(newHost).toBe(firstHost); + + // Verify the booking was successful by checking the new booking UID + const newBookingUid = page.url().split("/booking/")[1]; + expect(newBookingUid).not.toBeNull(); + expect(newBookingUid).not.toBe(bookingUid); + } + ); + }); }); test.describe("User Event", () => {