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

@@ -4,7 +4,7 @@ import type { Payment, Prisma, PaymentOption, Booking } from "@prisma/client";
import { v4 as uuidv4 } from "uuid";
import "vitest-fetch-mock";
import { sendAwaitingPaymentEmail } from "@calcom/emails";
import { sendAwaitingPaymentEmailAndSMS } from "@calcom/emails";
import logger from "@calcom/lib/logger";
import type { CalendarEvent } from "@calcom/types/Calendar";
import type { IAbstractPaymentService } from "@calcom/types/PaymentService";
@@ -64,7 +64,7 @@ export function getMockPaymentService() {
paymentData: Payment
): Promise<void> {
// TODO: App implementing PaymentService is supposed to send email by itself at the moment.
await sendAwaitingPaymentEmail({
await sendAwaitingPaymentEmailAndSMS({
...event,
paymentInfo: {
link: createPaymentLink(/*{
@@ -27,6 +27,7 @@ import type { SchedulingType, SMSLockState, TimeUnit } from "@calcom/prisma/enum
import type { BookingStatus } from "@calcom/prisma/enums";
import type { teamMetadataSchema } from "@calcom/prisma/zod-utils";
import type { userMetadataType } from "@calcom/prisma/zod-utils";
import type { eventTypeBookingFields } from "@calcom/prisma/zod-utils";
import type { AppMeta } from "@calcom/types/App";
import type { NewCalendarEventType } from "@calcom/types/Calendar";
import type { EventBusyDate, IntervalLimit } from "@calcom/types/Calendar";
@@ -34,6 +35,8 @@ import type { EventBusyDate, IntervalLimit } from "@calcom/types/Calendar";
import { getMockPaymentService } from "./MockPaymentService";
import type { getMockRequestDataForBooking } from "./getMockRequestDataForBooking";
type Fields = z.infer<typeof eventTypeBookingFields>;
logger.settings.minLevel = 1;
const log = logger.getSubLogger({ prefix: ["[bookingScenario]"] });
@@ -179,6 +182,7 @@ type WhiteListedBookingProps = {
status: BookingStatus;
attendees?: {
email: string;
phoneNumber?: string;
bookingSeat?: AttendeeBookingSeatInput | null;
}[];
references?: (Omit<ReturnType<typeof getMockBookingReference>, "credentialId"> & {
@@ -1708,10 +1712,19 @@ export function mockCrmApp(
};
}
export function getBooker({ name, email }: { name: string; email: string }) {
export function getBooker({
name,
email,
attendeePhoneNumber,
}: {
name: string;
email: string;
attendeePhoneNumber?: string;
}) {
return {
name,
email,
attendeePhoneNumber,
};
}
@@ -1770,8 +1783,11 @@ export function getMockBookingReference(
}
export function getMockBookingAttendee(
attendee: Omit<Attendee, "bookingId"> & {
attendee: Omit<Attendee, "bookingId" | "phoneNumber" | "email" | "noShow"> & {
bookingSeat?: AttendeeBookingSeatInput;
phoneNumber?: string | null;
email: string;
noShow?: boolean;
}
) {
return {
@@ -1781,6 +1797,8 @@ export function getMockBookingAttendee(
email: attendee.email,
locale: attendee.locale,
bookingSeat: attendee.bookingSeat || null,
phoneNumber: attendee.phoneNumber ?? undefined,
noShow: attendee.noShow ?? false,
};
}
@@ -1823,3 +1841,89 @@ export const replaceDates = (dates: string[], replacement: Record<string, string
return date.replace(/(.*)T/, (_, group1) => `${replacement[group1]}T`);
});
};
export const getDefaultBookingFields = ({
emailField,
bookingFields = [],
}: {
emailField?: Fields[number];
bookingFields: Fields;
}) => {
return [
{
name: "name",
type: "name",
sources: [{ id: "default", type: "default", label: "Default" }],
editable: "system",
required: true,
defaultLabel: "your_name",
},
!!emailField
? emailField
: {
name: "email",
type: "email",
label: "",
hidden: false,
sources: [{ id: "default", type: "default", label: "Default" }],
editable: "system",
required: true,
placeholder: "",
defaultLabel: "email_address",
},
{
name: "location",
type: "radioInput",
sources: [{ id: "default", type: "default", label: "Default" }],
editable: "system",
required: false,
defaultLabel: "location",
getOptionsAt: "locations",
optionsInputs: {
phone: { type: "phone", required: true, placeholder: "" },
attendeeInPerson: { type: "address", required: true, placeholder: "" },
},
hideWhenJustOneOption: true,
},
{
name: "title",
type: "text",
hidden: true,
sources: [{ id: "default", type: "default", label: "Default" }],
editable: "system-but-optional",
required: true,
defaultLabel: "what_is_this_meeting_about",
defaultPlaceholder: "",
},
{
name: "notes",
type: "textarea",
sources: [{ id: "default", type: "default", label: "Default" }],
editable: "system-but-optional",
required: false,
defaultLabel: "additional_notes",
defaultPlaceholder: "share_additional_notes",
},
{
name: "guests",
type: "multiemail",
hidden: false,
sources: [{ id: "default", type: "default", label: "Default" }],
editable: "system-but-optional",
required: false,
defaultLabel: "additional_guests",
defaultPlaceholder: "email",
},
{
name: "rescheduleReason",
type: "textarea",
views: [{ id: "reschedule", label: "Reschedule View" }],
sources: [{ id: "default", type: "default", label: "Default" }],
editable: "system-but-optional",
required: false,
defaultLabel: "reason_for_reschedule",
defaultPlaceholder: "reschedule_placeholder",
},
...bookingFields,
] as Fields;
};
+67 -13
View File
@@ -427,6 +427,16 @@ export async function expectBookingToBeInDatabase(
);
}
export function expectSMSToBeTriggered({ sms, toNumber }: { sms: Fixtures["sms"]; toNumber: string }) {
expect(sms.get()).toEqual(
expect.arrayContaining([
expect.objectContaining({
to: toNumber,
}),
])
);
}
export function expectSuccessfulBookingCreationEmails({
emails,
organizer,
@@ -818,7 +828,7 @@ export function expectBookingRequestedEmails({
}: {
emails: Fixtures["emails"];
organizer: { email: string; name: string };
booker: { email: string; name: string };
booker?: { email: string; name: string };
}) {
expect(emails).toHaveEmail(
{
@@ -829,14 +839,16 @@ export function expectBookingRequestedEmails({
`${organizer.email}`
);
expect(emails).toHaveEmail(
{
titleTag: "booking_submitted_subject",
to: `${booker.email}`,
noIcs: true,
},
`${booker.email}`
);
if (booker) {
expect(emails).toHaveEmail(
{
titleTag: "booking_submitted_subject",
to: `${booker.email}`,
noIcs: true,
},
`${booker.email}`
);
}
}
export function expectBookingRequestRescheduledEmails({
@@ -898,13 +910,17 @@ export function expectBookingRequestedWebhookToHaveBeenFired({
subscriberUrl,
paidEvent,
eventType,
isEmailHidden = false,
isAttendeePhoneNumberHidden = false,
}: {
organizer: { email: string; name: string };
booker: { email: string; name: string };
booker: { email: string; name: string; attendeePhoneNumber?: string };
subscriberUrl: string;
location: string;
paidEvent?: boolean;
eventType: InputEventType;
isEmailHidden?: boolean;
isAttendeePhoneNumberHidden?: boolean;
}) {
// There is an inconsistency in the way we send the data to the webhook for paid events and unpaid events. Fix that and then remove this if statement.
if (!paidEvent) {
@@ -925,8 +941,17 @@ export function expectBookingRequestedWebhookToHaveBeenFired({
email: {
label: "email_address",
value: booker.email,
isHidden: false,
isHidden: isEmailHidden,
},
...(booker.attendeePhoneNumber
? {
attendeePhoneNumber: {
label: "phone_number",
value: booker.attendeePhoneNumber,
isHidden: isAttendeePhoneNumberHidden,
},
}
: null),
location: {
label: "location",
value: { optionValue: "", value: location },
@@ -947,6 +972,14 @@ export function expectBookingRequestedWebhookToHaveBeenFired({
responses: {
name: { label: "name", value: booker.name },
email: { label: "email", value: booker.email },
...(booker.attendeePhoneNumber
? {
attendeePhoneNumber: {
label: "phone_number",
value: booker.attendeePhoneNumber,
},
}
: null),
location: {
label: "location",
value: { optionValue: "", value: location },
@@ -963,13 +996,17 @@ export function expectBookingCreatedWebhookToHaveBeenFired({
subscriberUrl,
paidEvent,
videoCallUrl,
isEmailHidden = false,
isAttendeePhoneNumberHidden = false,
}: {
organizer: { email: string; name: string };
booker: { email: string; name: string };
booker: { email: string; name: string; attendeePhoneNumber?: string };
subscriberUrl: string;
location: string;
paidEvent?: boolean;
videoCallUrl?: string | null;
isEmailHidden?: boolean;
isAttendeePhoneNumberHidden?: boolean;
}) {
if (!paidEvent) {
expectWebhookToHaveBeenCalledWith(subscriberUrl, {
@@ -980,7 +1017,16 @@ export function expectBookingCreatedWebhookToHaveBeenFired({
},
responses: {
name: { label: "your_name", value: booker.name, isHidden: false },
email: { label: "email_address", value: booker.email, isHidden: false },
email: { label: "email_address", value: booker.email, isHidden: isEmailHidden },
...(booker.attendeePhoneNumber
? {
attendeePhoneNumber: {
label: "phone_number",
value: booker.attendeePhoneNumber,
isHidden: isAttendeePhoneNumberHidden,
},
}
: null),
location: {
label: "location",
value: { optionValue: "", value: location },
@@ -1004,6 +1050,14 @@ export function expectBookingCreatedWebhookToHaveBeenFired({
label: "email",
value: booker.email,
},
...(booker.attendeePhoneNumber
? {
attendeePhoneNumber: {
label: "phone_number",
value: booker.attendeePhoneNumber,
},
}
: null),
location: {
label: "location",
value: { optionValue: "", value: location },
@@ -33,6 +33,7 @@ export function getMockRequestDataForBooking({
email: string;
name: string;
location?: { optionValue: ""; value: string };
attendeePhoneNumber?: string;
smsReminderNumber?: string;
};
};