refactor: Introduce crmManager (#14272)
* fix timezone display on booking page to reflect event availability timezone * migrate fetching event owner's schedule to server side * migrate fetching event owner's schedule to server side * fix e2e test errors * Add WEBAPP_URL_FOR_OAUTH to salesforce auth * In event manager constructor include "_crm" credentials as calendar creds * Change crm apps to type to end with `_crm` * Move sendgrid out of CRM * Add zoho bigin to CRM apps * When getting apps, use slug * Add `crm` variants * Hubspot Oauth use `WEBAPP_URL_FOR_OAUTH` * Refactor creating credentials * Fix empty CRM page * Use credentials with `_crm` * Abstract getAppCategoryTitle * Add integration.handler changes * Init crmManager * Change salesforce to CrmService * Create crmManager * Create contact on new event * Create event * Create new CRM reference * - Fix create new contact for salesforce - Add reschedule to crmManager * Create deleteAllCRMEvents * When searching for credential, look for current credentials in class * On cancel, delete 3rd party events * Add delete method * Type fix * Type fix * Convert Close.com to CrmService * Convert Close.com to CrmService * Move hubspot to CrmService * Convert Pipedrive to CrmService * Rename classes to CrmService * Move ZohoCrm to CrmService * Move Bigin to CrmService * Type return for CrmServices * Fix type errors * Close.com create leads and contacts * Fix tests * Type fix * Zoho bug fixes * Clean up * Type fixes * Remove apiDeletes * Type fixes * Specific typing * Type fix * Type fix * Type fix * Type fix * Type fix * feat: Enable CRM apps on a per event type basis (#14450) * Add Salesforce to be an event type app * Handle new booking, only get enabled CRM credentials * Abstract generating search params * Add close.com to event type * Clean up * Move hubspot to event type * Add pipedrive to event type * Add zoho bigin to event type * Add zoho crm to event type * Remove console.log * Add deleting CRM apps from event type * Delete event type apps * Fix deleting credentials * Add CRM app data to event type metadata * Backwards compatibility: add CRM credential if doesn't exist on event type * Don't include user CRM credentials for backwards comp * Backwards compatibility show CRM app is enabled and dirty field * Clean up * Type fixes * Type fixes * Type fix * Type fix * Remove console.log * Test fix * Upgrade embed-react vite version - dev * Change build can't find error message * Add back omni install prop * Clean up * Refactor `writeAppDataToEventType` * Use eventType repository in writeAppDataToEventType * Clean up old comments * Add error logging * createCRMEvents pass event uid as created event uid * Use `getUid` * Clean up props in create crm event * Small changes to `crmManager` * Fix zoho CRM * refactor crmManager * Undo vite config change * Fix teamId query * Fix bigin error * Remove need for `writeAppDataToEventType` * Add `getAllCredentials` test * Add crmManager tests * Type fixes * Fix type errors * Fix getAllCredentials test * Fix tests * Skip CRM manager tests for now * feat: Skip RR Assignment if Contact Exists In Salesforce (#14556) Co-authored-by: CarinaWolli <[email protected]> * Update yarn.lock * @zomars feedback - use new URL for state params * fix: update hook to not produce enabled === undefined * fix: update app card interfaces to use the new enabled from useIsAppEnabled * fix: feedback for crm RR skip (#15160) * code clean up * fix type any * test setup for RR lead skip * code clean up * simplify code * type error * finshed first test for RR lead skip * add seconds test * add test for handleNewBooking * test if teamMember is set * fix missing enabled key * fix tests * fix type error * use setSystemTime instead of getDate * remove nested if --------- Co-authored-by: CarinaWolli <[email protected]> * fix type error * fix: remove app metadata from all eventTypes on deleting the app * fix: update hook to not produce enabled === undefined (default to false) --------- Co-authored-by: Shaik-Sirajuddin <sirajuddinshaik30gmail.com> Co-authored-by: Shaik-Sirajuddin <[email protected]> Co-authored-by: Shaik-Sirajuddin <[email protected]> Co-authored-by: sean-brydon <[email protected]> Co-authored-by: Omar López <[email protected]> Co-authored-by: CarinaWolli <[email protected]> Co-authored-by: sean-brydon <[email protected]> Co-authored-by: Carina Wollendorfer <[email protected]> Co-authored-by: Somay Chauhan <[email protected]>
This commit is contained in:
81 files changed
+2611
-594
No files matched your search
@@ -2408,6 +2408,8 @@
|
||||
"disconnect_account_hint": "Disconnecting your connected account will change the way you log in. You will only be able to login to your account using email + password",
|
||||
"cookie_consent_checkbox": "I consent to our privacy policy and cookie usage",
|
||||
"make_a_call": "Make a Call",
|
||||
"skip_rr_assignment_label": "Skip round robin assignment if contact exists in Salesforce",
|
||||
"skip_rr_description": "URL must contain the contacts email as a parameter ex. ?email=contactEmail",
|
||||
"select_account_header": "Select Account",
|
||||
"select_account_description": "Install {{appName}} on your personal account or on a team account.",
|
||||
"select_event_types_header": "Select Event Types",
|
||||
|
||||
@@ -9,6 +9,8 @@ import {
|
||||
getScenarioData,
|
||||
Timezones,
|
||||
TestData,
|
||||
createCredentials,
|
||||
mockCrmApp,
|
||||
} from "../utils/bookingScenario/bookingScenario";
|
||||
|
||||
import { describe, vi, test } from "vitest";
|
||||
@@ -86,6 +88,289 @@ describe("getSchedule", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("Round robin lead skip - CRM", async () => {
|
||||
test("correctly get slots for event with only round robin hosts", async () => {
|
||||
vi.setSystemTime("2024-05-21T00:00:13Z");
|
||||
|
||||
const plus1DateString = "2024-05-22";
|
||||
const plus2DateString = "2024-05-23";
|
||||
|
||||
const crmCredential = {
|
||||
id: 1,
|
||||
type: "salesforce_crm",
|
||||
key: {
|
||||
clientId: "test-client-id",
|
||||
},
|
||||
userId: 1,
|
||||
teamId: null,
|
||||
appId: "salesforce",
|
||||
invalid: false,
|
||||
user: { email: "[email protected]" },
|
||||
};
|
||||
|
||||
await createCredentials([crmCredential]);
|
||||
|
||||
mockCrmApp("salesforce", {
|
||||
getContacts: [
|
||||
{
|
||||
id: "contact-id",
|
||||
email: "[email protected]",
|
||||
ownerEmail: "[email protected]",
|
||||
},
|
||||
],
|
||||
createContacts: [{ id: "contact-id", email: "[email protected]" }],
|
||||
});
|
||||
|
||||
await createBookingScenario({
|
||||
eventTypes: [
|
||||
{
|
||||
id: 1,
|
||||
slotInterval: 60,
|
||||
length: 60,
|
||||
hosts: [
|
||||
{
|
||||
userId: 101,
|
||||
isFixed: false,
|
||||
},
|
||||
{
|
||||
userId: 102,
|
||||
isFixed: false,
|
||||
},
|
||||
],
|
||||
schedulingType: "ROUND_ROBIN",
|
||||
metadata: {
|
||||
apps: {
|
||||
salesforce: {
|
||||
enabled: true,
|
||||
appCategories: ["crm"],
|
||||
roundRobinLeadSkip: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
users: [
|
||||
{
|
||||
...TestData.users.example,
|
||||
email: "[email protected]",
|
||||
id: 101,
|
||||
schedules: [TestData.schedules.IstEveningShift],
|
||||
},
|
||||
{
|
||||
...TestData.users.example,
|
||||
email: "[email protected]",
|
||||
id: 102,
|
||||
schedules: [TestData.schedules.IstMorningShift],
|
||||
defaultScheduleId: 2,
|
||||
},
|
||||
],
|
||||
bookings: [],
|
||||
});
|
||||
|
||||
const scheduleWithLeadSkip = await getSchedule({
|
||||
input: {
|
||||
eventTypeId: 1,
|
||||
eventTypeSlug: "",
|
||||
startTime: `${plus1DateString}T18:30:00.000Z`,
|
||||
endTime: `${plus2DateString}T18:29:59.999Z`,
|
||||
timeZone: Timezones["+5:30"],
|
||||
isTeamEvent: true,
|
||||
bookerEmail: "[email protected]",
|
||||
},
|
||||
});
|
||||
|
||||
expect(scheduleWithLeadSkip.teamMember).toBe("[email protected]");
|
||||
|
||||
// only slots where [email protected] is available
|
||||
expect(scheduleWithLeadSkip).toHaveTimeSlots(
|
||||
[`11:30:00.000Z`, `12:30:00.000Z`, `13:30:00.000Z`, `14:30:00.000Z`, `15:30:00.000Z`],
|
||||
{
|
||||
dateString: plus2DateString,
|
||||
}
|
||||
);
|
||||
|
||||
const scheduleWithoutLeadSkip = await getSchedule({
|
||||
input: {
|
||||
eventTypeId: 1,
|
||||
eventTypeSlug: "",
|
||||
startTime: `${plus1DateString}T18:30:00.000Z`,
|
||||
endTime: `${plus2DateString}T18:29:59.999Z`,
|
||||
timeZone: Timezones["+5:30"],
|
||||
isTeamEvent: true,
|
||||
bookerEmail: "[email protected]",
|
||||
},
|
||||
});
|
||||
|
||||
expect(scheduleWithoutLeadSkip.teamMember).toBe(undefined);
|
||||
|
||||
// slots where either one of the rr hosts is available
|
||||
expect(scheduleWithoutLeadSkip).toHaveTimeSlots(
|
||||
[
|
||||
`04:30:00.000Z`,
|
||||
`05:30:00.000Z`,
|
||||
`06:30:00.000Z`,
|
||||
`07:30:00.000Z`,
|
||||
`08:30:00.000Z`,
|
||||
`09:30:00.000Z`,
|
||||
`10:30:00.000Z`,
|
||||
`11:30:00.000Z`,
|
||||
`12:30:00.000Z`,
|
||||
`13:30:00.000Z`,
|
||||
`14:30:00.000Z`,
|
||||
`15:30:00.000Z`,
|
||||
],
|
||||
{
|
||||
dateString: plus2DateString,
|
||||
}
|
||||
);
|
||||
});
|
||||
test("correctly get slots for event with round robin and fixed hosts", async () => {
|
||||
const { dateString: plus1DateString } = getDate({ dateIncrement: 1 });
|
||||
const { dateString: plus2DateString } = getDate({ dateIncrement: 2 });
|
||||
|
||||
const crmCredential = {
|
||||
id: 1,
|
||||
type: "salesforce_crm",
|
||||
key: {
|
||||
clientId: "test-client-id",
|
||||
},
|
||||
userId: 1,
|
||||
teamId: null,
|
||||
appId: "salesforce",
|
||||
invalid: false,
|
||||
user: { email: "[email protected]" },
|
||||
};
|
||||
|
||||
await createCredentials([crmCredential]);
|
||||
|
||||
mockCrmApp("salesforce", {
|
||||
getContacts: [
|
||||
{
|
||||
id: "contact-id",
|
||||
email: "[email protected]",
|
||||
ownerEmail: "[email protected]",
|
||||
},
|
||||
{
|
||||
id: "contact-id-1",
|
||||
email: "[email protected]",
|
||||
ownerEmail: "[email protected]",
|
||||
},
|
||||
],
|
||||
createContacts: [{ id: "contact-id", email: "[email protected]" }],
|
||||
});
|
||||
|
||||
await createBookingScenario({
|
||||
eventTypes: [
|
||||
{
|
||||
id: 1,
|
||||
slotInterval: 60,
|
||||
length: 60,
|
||||
hosts: [
|
||||
{
|
||||
userId: 101,
|
||||
isFixed: true,
|
||||
},
|
||||
{
|
||||
userId: 102,
|
||||
isFixed: false,
|
||||
},
|
||||
{
|
||||
userId: 103,
|
||||
isFixed: false,
|
||||
},
|
||||
],
|
||||
schedulingType: "ROUND_ROBIN",
|
||||
metadata: {
|
||||
apps: {
|
||||
salesforce: {
|
||||
enabled: true,
|
||||
appCategories: ["crm"],
|
||||
roundRobinLeadSkip: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
users: [
|
||||
{
|
||||
...TestData.users.example,
|
||||
email: "[email protected]",
|
||||
id: 101,
|
||||
schedules: [TestData.schedules.IstMidShift],
|
||||
},
|
||||
{
|
||||
...TestData.users.example,
|
||||
email: "[email protected]",
|
||||
id: 102,
|
||||
schedules: [TestData.schedules.IstMorningShift],
|
||||
defaultScheduleId: 2,
|
||||
},
|
||||
{
|
||||
...TestData.users.example,
|
||||
email: "[email protected]",
|
||||
id: 103,
|
||||
schedules: [TestData.schedules.IstEveningShift],
|
||||
|
||||
defaultScheduleId: 3,
|
||||
},
|
||||
],
|
||||
bookings: [],
|
||||
});
|
||||
|
||||
const scheduleFixedHostLead = await getSchedule({
|
||||
input: {
|
||||
eventTypeId: 1,
|
||||
eventTypeSlug: "",
|
||||
startTime: `${plus1DateString}T18:30:00.000Z`,
|
||||
endTime: `${plus2DateString}T18:29:59.999Z`,
|
||||
timeZone: Timezones["+5:30"],
|
||||
isTeamEvent: true,
|
||||
bookerEmail: "[email protected]",
|
||||
},
|
||||
});
|
||||
|
||||
expect(scheduleFixedHostLead.teamMember).toBe("[email protected]");
|
||||
|
||||
// show normal slots, example@example + one RR host needs to be available
|
||||
expect(scheduleFixedHostLead).toHaveTimeSlots(
|
||||
[
|
||||
`07:30:00.000Z`,
|
||||
`08:30:00.000Z`,
|
||||
`09:30:00.000Z`,
|
||||
`10:30:00.000Z`,
|
||||
`11:30:00.000Z`,
|
||||
`12:30:00.000Z`,
|
||||
`13:30:00.000Z`,
|
||||
],
|
||||
{
|
||||
dateString: plus2DateString,
|
||||
}
|
||||
);
|
||||
|
||||
const scheduleRRHostLead = await getSchedule({
|
||||
input: {
|
||||
eventTypeId: 1,
|
||||
eventTypeSlug: "",
|
||||
startTime: `${plus1DateString}T18:30:00.000Z`,
|
||||
endTime: `${plus2DateString}T18:29:59.999Z`,
|
||||
timeZone: Timezones["+5:30"],
|
||||
isTeamEvent: true,
|
||||
bookerEmail: "[email protected]",
|
||||
},
|
||||
});
|
||||
|
||||
expect(scheduleRRHostLead.teamMember).toBe("[email protected]");
|
||||
|
||||
// slots where example@example (fixed host) + [email protected] are available together
|
||||
expect(scheduleRRHostLead).toHaveTimeSlots(
|
||||
[`07:30:00.000Z`, `08:30:00.000Z`, `09:30:00.000Z`, `10:30:00.000Z`, `11:30:00.000Z`],
|
||||
{
|
||||
dateString: plus2DateString,
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("User Event", () => {
|
||||
test("correctly identifies unavailable slots from Cal Bookings in different status", async () => {
|
||||
const { dateString: plus1DateString } = getDate({ dateIncrement: 1 });
|
||||
|
||||
@@ -136,6 +136,7 @@ export type InputEventType = {
|
||||
bookingLimits?: IntervalLimit;
|
||||
durationLimits?: IntervalLimit;
|
||||
owner?: number;
|
||||
metadata?: any;
|
||||
} & Partial<Omit<Prisma.EventTypeCreateInput, "users" | "schedule" | "bookingLimits" | "durationLimits">>;
|
||||
|
||||
type AttendeeBookingSeatInput = Pick<Prisma.BookingSeatCreateInput, "referenceUid" | "data">;
|
||||
@@ -169,23 +170,35 @@ export const Timezones = {
|
||||
|
||||
async function addHostsToDb(eventTypes: InputEventType[]) {
|
||||
for (const eventType of eventTypes) {
|
||||
if (eventType.hosts && eventType.hosts.length > 0) {
|
||||
await prismock.host.createMany({
|
||||
data: eventType.hosts.map((host) => ({
|
||||
userId: host.userId,
|
||||
eventTypeId: eventType.id,
|
||||
isFixed: host.isFixed ?? false,
|
||||
})),
|
||||
if (!eventType.hosts?.length) continue;
|
||||
for (const host of eventType.hosts) {
|
||||
const data: Prisma.HostCreateInput = {
|
||||
eventType: {
|
||||
connect: {
|
||||
id: eventType.id,
|
||||
},
|
||||
},
|
||||
isFixed: host.isFixed ?? false,
|
||||
user: {
|
||||
connect: {
|
||||
id: host.userId,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
await prismock.host.create({
|
||||
data,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function addEventTypesToDb(
|
||||
export async function addEventTypesToDb(
|
||||
eventTypes: (Omit<
|
||||
Prisma.EventTypeCreateInput,
|
||||
"users" | "worflows" | "destinationCalendar" | "schedule"
|
||||
> & {
|
||||
id?: number;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
users?: any[];
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
@@ -194,6 +207,7 @@ async function addEventTypesToDb(
|
||||
destinationCalendar?: any;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
schedule?: any;
|
||||
metadata?: any;
|
||||
})[]
|
||||
) {
|
||||
log.silly("TestData: Add EventTypes to DB", JSON.stringify(eventTypes));
|
||||
@@ -247,7 +261,7 @@ async function addEventTypesToDb(
|
||||
return allEventTypes;
|
||||
}
|
||||
|
||||
async function addEventTypes(eventTypes: InputEventType[], usersStore: InputUser[]) {
|
||||
export async function addEventTypes(eventTypes: InputEventType[], usersStore: InputUser[]) {
|
||||
const baseEventType = {
|
||||
title: "Base EventType Title",
|
||||
slug: "base-event-type-slug",
|
||||
@@ -465,7 +479,9 @@ async function addWorkflows(workflows: InputWorkflow[]) {
|
||||
await addWorkflowsToDb(workflows);
|
||||
}
|
||||
|
||||
async function addUsersToDb(users: (Prisma.UserCreateInput & { schedules: Prisma.ScheduleCreateInput[] })[]) {
|
||||
export async function addUsersToDb(
|
||||
users: (Prisma.UserCreateInput & { schedules: Prisma.ScheduleCreateInput[]; id?: number })[]
|
||||
) {
|
||||
log.silly("TestData: Creating Users", JSON.stringify(users));
|
||||
await prismock.user.createMany({
|
||||
data: users,
|
||||
@@ -491,7 +507,7 @@ async function addUsersToDb(users: (Prisma.UserCreateInput & { schedules: Prisma
|
||||
);
|
||||
}
|
||||
|
||||
async function addTeamsToDb(teams: NonNullable<InputUser["teams"]>[number]["team"][]) {
|
||||
export async function addTeamsToDb(teams: NonNullable<InputUser["teams"]>[number]["team"][]) {
|
||||
log.silly("TestData: Creating Teams", JSON.stringify(teams));
|
||||
await prismock.team.createMany({
|
||||
data: teams,
|
||||
@@ -640,6 +656,21 @@ export async function createOrganization(orgData: {
|
||||
return org;
|
||||
}
|
||||
|
||||
export async function createCredentials(
|
||||
credentialData: {
|
||||
type: string;
|
||||
key: any;
|
||||
id?: number;
|
||||
userId?: number | null;
|
||||
teamId?: number | null;
|
||||
}[]
|
||||
) {
|
||||
const credentials = await prismock.credential.createMany({
|
||||
data: credentialData,
|
||||
});
|
||||
return credentials;
|
||||
}
|
||||
|
||||
// async function addPaymentsToDb(payments: Prisma.PaymentCreateInput[]) {
|
||||
// await prismaMock.payment.createMany({
|
||||
// data: payments,
|
||||
@@ -845,6 +876,23 @@ export const TestData = {
|
||||
],
|
||||
timeZone: Timezones["+5:30"],
|
||||
},
|
||||
/**
|
||||
* Has an overlap with IstMorningShift and IstEveningShift
|
||||
*/
|
||||
IstMidShift: {
|
||||
name: "12:30AM to 8PM in India - 7:00AM to 14:30PM in GMT",
|
||||
availability: [
|
||||
{
|
||||
// userId: null,
|
||||
// eventTypeId: null,
|
||||
days: [0, 1, 2, 3, 4, 5, 6],
|
||||
startTime: new Date("1970-01-01T12:30:00.000Z"),
|
||||
endTime: new Date("1970-01-01T20:00:00.000Z"),
|
||||
date: null,
|
||||
},
|
||||
],
|
||||
timeZone: Timezones["+5:30"],
|
||||
},
|
||||
/**
|
||||
* Has an overlap with IstMorningShift from 5PM to 6PM IST(11:30AM to 12:30PM GMT)
|
||||
*/
|
||||
@@ -1444,6 +1492,74 @@ export function mockErrorOnVideoMeetingCreation({
|
||||
});
|
||||
}
|
||||
|
||||
export function mockCrmApp(
|
||||
metadataLookupKey: string,
|
||||
crmData?: {
|
||||
createContacts?: {
|
||||
id: string;
|
||||
email: string;
|
||||
}[];
|
||||
getContacts?: {
|
||||
id: string;
|
||||
email: string;
|
||||
ownerEmail: string;
|
||||
}[];
|
||||
}
|
||||
) {
|
||||
let contactsCreated: {
|
||||
id: string;
|
||||
email: string;
|
||||
}[] = [];
|
||||
let contactsQueried: {
|
||||
id: string;
|
||||
email: string;
|
||||
ownerEmail: string;
|
||||
}[] = [];
|
||||
const eventsCreated: boolean[] = [];
|
||||
const app = appStoreMetadata[metadataLookupKey as keyof typeof appStoreMetadata];
|
||||
const appMock = appStoreMock.default[metadataLookupKey as keyof typeof appStoreMock.default];
|
||||
appMock &&
|
||||
`mockResolvedValue` in appMock &&
|
||||
appMock.mockResolvedValue({
|
||||
lib: {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
//@ts-ignore
|
||||
CrmService: class {
|
||||
constructor() {
|
||||
log.debug("Create CrmSerive");
|
||||
}
|
||||
|
||||
createContact() {
|
||||
if (crmData?.createContacts) {
|
||||
contactsCreated = crmData.createContacts;
|
||||
return Promise.resolve(crmData?.createContacts);
|
||||
}
|
||||
}
|
||||
|
||||
getContacts(email: string) {
|
||||
if (crmData?.getContacts) {
|
||||
contactsQueried = crmData?.getContacts;
|
||||
const contactsOfEmail = contactsQueried.filter((contact) => contact.email === email);
|
||||
|
||||
return Promise.resolve(contactsOfEmail);
|
||||
}
|
||||
}
|
||||
|
||||
createEvent() {
|
||||
eventsCreated.push(true);
|
||||
return Promise.resolve({});
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
contactsCreated,
|
||||
contactsQueried,
|
||||
eventsCreated,
|
||||
};
|
||||
}
|
||||
|
||||
export function getBooker({ name, email }: { name: string; email: string }) {
|
||||
return {
|
||||
name,
|
||||
|
||||
Reference in new issue
Block a user