feat: booking with phone number (#14461)

Co-authored-by: Omar López <[email protected]>
Co-authored-by: Joe Au-Yeung <[email protected]>
Co-authored-by: Joe Au-Yeung <[email protected]>
This commit is contained in:
authored and GitHub committed 2024-09-11 17:56:04 -07:00
1 parent 74a9f3c19e
commit 4a59841b02
85 files changed
+2078 -274

No files matched your search

+7 -1
View File
@@ -137,13 +137,19 @@ export async function bookFirstEvent(page: Page) {
await bookEventOnThisPage(page);
}
export const bookTimeSlot = async (page: Page, opts?: { name?: string; email?: string; title?: string }) => {
export const bookTimeSlot = async (
page: Page,
opts?: { name?: string; email?: string; title?: string; attendeePhoneNumber?: string }
) => {
// --- fill form
await page.fill('[name="name"]', opts?.name ?? testName);
await page.fill('[name="email"]', opts?.email ?? testEmail);
if (opts?.title) {
await page.fill('[name="title"]', opts.title);
}
if (opts?.attendeePhoneNumber) {
await page.fill('[name="attendeePhoneNumber"]', opts.attendeePhoneNumber ?? "+918888888888");
}
await page.press('[name="email"]', "Enter");
};
+154 -1
View File
@@ -80,6 +80,63 @@ test.describe("Bookings", () => {
// TODO: Assert whether the user received an email
});
test("Can create a booking for Collective EventType with only phone number", 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.COLLECTIVE,
}
);
const { team } = await owner.getFirstTeamMembership();
const teamEvent = await owner.getFirstTeamEvent(team.id);
await owner.apiLogin();
await markPhoneNumberAsRequiredAndEmailAsOptional(page, teamEvent.id);
await expectPageToBeNotFound({ page, url: `/team/${team.slug}/${teamEvent.slug}` });
await doOnOrgDomain(
{
orgSlug: org.slug,
page,
},
async () => {
await bookTeamEvent({
page,
team,
event: teamEvent,
opts: { attendeePhoneNumber: "+918888888888" },
});
// All the teammates should be in the booking
for (const teammate of teamMatesObj.concat([{ name: owner.name || "" }])) {
await expect(page.getByText(teammate.name, { exact: true })).toBeVisible();
}
}
);
// TODO: Assert whether the user received an email
});
test("Can create a booking for Round Robin EventType", async ({ page, users, orgs }) => {
const org = await orgs.create({
name: "TestOrg",
@@ -130,6 +187,69 @@ test.describe("Bookings", () => {
// TODO: Assert whether the user received an email
});
test("Can create a booking for Round Robin EventType with both phone number and email required", 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);
await owner.apiLogin();
await markPhoneNumberAsRequiredField(page, teamEvent.id);
await expectPageToBeNotFound({ page, url: `/team/${team.slug}/${teamEvent.slug}` });
await doOnOrgDomain(
{
orgSlug: org.slug,
page,
},
async () => {
await bookTeamEvent({
page,
team,
event: teamEvent,
teamMatesObj,
opts: { attendeePhoneNumber: "+918888888888" },
});
// Since all the users have the same leastRecentlyBooked value
// Anyone of the teammates could be the Host of the booking.
const chosenUser = await page.getByTestId("booking-host-name").textContent();
expect(chosenUser).not.toBeNull();
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
expect(teamMatesObj.concat([{ name: owner.name! }]).some(({ name }) => name === chosenUser)).toBe(
true
);
}
);
// TODO: Assert whether the user received an email
});
test("Can access booking page with event slug and team page in lowercase/uppercase/mixedcase", async ({
page,
orgs,
@@ -485,6 +605,7 @@ async function bookTeamEvent({
team,
event,
teamMatesObj,
opts,
}: {
page: Page;
team: {
@@ -493,6 +614,7 @@ async function bookTeamEvent({
};
event: { slug: string; title: string; schedulingType: SchedulingType | null };
teamMatesObj?: { name: string }[];
opts?: { attendeePhoneNumber?: string };
}) {
// Note that even though the default way to access a team booking in an organization is to not use /team in the URL, but it isn't testable with playwright as the rewrite is taken care of by Next.js config which can't handle on the fly org slug's handling
// So, we are using /team in the URL to access the team booking
@@ -501,7 +623,7 @@ async function bookTeamEvent({
await page.goto(`/team/${team.slug}/${event.slug}`);
await selectFirstAvailableTimeSlotNextMonth(page);
await bookTimeSlot(page);
await bookTimeSlot(page, opts);
await expect(page.getByTestId("success-page")).toBeVisible();
// The title of the booking
@@ -526,3 +648,34 @@ async function expectPageToBeNotFound({ page, url }: { page: Page; url: string }
await page.goto(`${url}`);
await expect(page.getByTestId(`404-page`)).toBeVisible();
}
const markPhoneNumberAsRequiredAndEmailAsOptional = async (page: Page, eventId: number) => {
// Make phone as required
await markPhoneNumberAsRequiredField(page, eventId);
// Make email as not required
await page.locator('[data-testid="field-email"] [data-testid="edit-field-action"]').click();
const emailRequiredFiled = await page.locator('[data-testid="field-required"]');
await emailRequiredFiled.locator("> :nth-child(2)").click();
await page.getByTestId("field-add-save").click();
const submitPromise = page.waitForResponse("/api/trpc/eventTypes/update?batch=1");
await page.locator("[data-testid=update-eventtype]").click();
const response = await submitPromise;
expect(response.status()).toBe(200);
};
const markPhoneNumberAsRequiredField = async (page: Page, eventId: number) => {
await page.goto(`/event-types/${eventId}?tabName=advanced`);
await page.locator('[data-testid="field-attendeePhoneNumber"] [data-testid="toggle-field"]').click();
await page.locator('[data-testid="field-attendeePhoneNumber"] [data-testid="edit-field-action"]').click();
const phoneRequiredFiled = await page.locator('[data-testid="field-required"]');
await phoneRequiredFiled.locator("> :nth-child(1)").click();
await page.getByTestId("field-add-save").click();
const submitPromise = page.waitForResponse("/api/trpc/eventTypes/update?batch=1");
await page.locator("[data-testid=update-eventtype]").click();
const response = await submitPromise;
expect(response.status()).toBe(200);
};