fix: Don't force reschedule with same RR host if reschedule is actually rerouting (#17511)

* Dont force reschedule with same RR host if routed there

* Add unit tests
This commit is contained in:
Hariom Balhara authored and GitHub committed 2024-12-05 09:30:22 -05:00
1 parent 119edb5389
commit 2408337c78
7 files changed
+499 -19

No files matched your search

+280 -3
View File
@@ -19,7 +19,7 @@ import dayjs from "@calcom/dayjs";
import { SchedulingType, type BookingStatus } from "@calcom/prisma/enums";
import { getAvailableSlots as getSchedule } from "@calcom/trpc/server/routers/viewer/slots/util";
import { expect } from "./getSchedule/expects";
import { expect, expectedSlotsForSchedule } from "./getSchedule/expects";
import { setupAndTeardown } from "./getSchedule/setupAndTeardown";
import { timeTravelToTheBeginningOfToday } from "./getSchedule/utils";
@@ -89,7 +89,8 @@ describe("getSchedule", () => {
});
});
describe("Round robin lead skip - CRM", async () => {
// TODO: Move these inside describe('Team Event')
describe("Round robin lead skip(i.e. use contact owner specified by teamMemberEmail) - CRM", async () => {
test("correctly get slots for event with only round robin hosts", async () => {
vi.setSystemTime("2024-05-21T00:00:13Z");
@@ -367,7 +368,7 @@ describe("getSchedule", () => {
}
);
});
test("correctly get slots for event with only round robin hosts", async () => {
test("correctly get slots for event with only round robin hosts - When no availability is found", async () => {
vi.setSystemTime("2024-05-21T00:00:13Z");
const plus1DateString = "2024-05-22";
@@ -496,6 +497,119 @@ describe("getSchedule", () => {
}
);
});
test("Negative case(i.e. skipContactOwner is true) - when teamMemberEmail is provided but not used", 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 scheduleWhenContactOwnerIsSkipped = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
startTime: `${plus1DateString}T18:30:00.000Z`,
endTime: `${plus2DateString}T18:29:59.999Z`,
timeZone: Timezones["+5:30"],
isTeamEvent: true,
teamMemberEmail: "[email protected]",
skipContactOwner: true,
orgSlug: null,
},
});
// Both users slot would be available as contact owner([email protected]) is skipped and we fallback to all users of RR
expect(scheduleWhenContactOwnerIsSkipped).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,
}
);
});
});
describe("User Event", () => {
@@ -2163,5 +2277,168 @@ describe("getSchedule", () => {
}
);
});
test("Reschedule: should reschedule with same host if rescheduleWithSameRoundRobinHost is true", async () => {
vi.setSystemTime("2024-05-21T00:00:13Z");
const plus1DateString = "2024-05-22";
const plus2DateString = "2024-05-23";
// An event with common schedule
await createBookingScenario({
eventTypes: [
{
id: 1,
slotInterval: 60,
length: 60,
rescheduleWithSameRoundRobinHost: true,
hosts: [
{
userId: 101,
isFixed: false,
},
{
userId: 102,
isFixed: false,
},
],
schedulingType: "ROUND_ROBIN",
},
],
users: [
{
...TestData.users.example,
email: "[email protected]",
id: 101,
schedules: [TestData.schedules.IstEveningShift],
defaultScheduleId: 1,
},
{
...TestData.users.example,
email: "[email protected]",
id: 102,
schedules: [TestData.schedules.IstMorningShift],
defaultScheduleId: 2,
},
],
bookings: [
{
uid: "BOOKING_TO_RESCHEDULE_UID",
userId: 101,
attendees: [
{
email: "[email protected]",
},
],
eventTypeId: 1,
status: "ACCEPTED",
startTime: `${plus2DateString}T04:00:00.000Z`,
endTime: `${plus2DateString}T04:15:00.000Z`,
},
],
});
const schedule = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
startTime: `${plus1DateString}T18:30:00.000Z`,
endTime: `${plus2DateString}T18:29:59.999Z`,
timeZone: Timezones["+5:30"],
isTeamEvent: true,
rescheduleUid: "BOOKING_TO_RESCHEDULE_UID",
},
});
// expect only slots of IstEveningShift as this is the slots for the original host of the booking
expect(schedule).toHaveTimeSlots(
[`11:30:00.000Z`, `12:30:00.000Z`, `13:30:00.000Z`, `14:30:00.000Z`, `15:30:00.000Z`],
{
dateString: plus2DateString,
}
);
});
test("Reschedule: should reschedule as per routedTeamMemberIds(instead of same host) even if rescheduleWithSameRoundRobinHost is true but it is a rerouting scenario", async () => {
vi.setSystemTime("2024-05-21T00:00:13Z");
const plus1DateString = "2024-05-22";
const plus2DateString = "2024-05-23";
// An event with common schedule
await createBookingScenario({
eventTypes: [
{
id: 1,
slotInterval: 60,
length: 60,
rescheduleWithSameRoundRobinHost: true,
hosts: [
{
userId: 101,
isFixed: false,
},
{
userId: 102,
isFixed: false,
},
],
schedulingType: "ROUND_ROBIN",
},
],
users: [
{
...TestData.users.example,
email: "[email protected]",
id: 101,
schedules: [TestData.schedules.IstEveningShift],
defaultScheduleId: 1,
},
{
...TestData.users.example,
email: "[email protected]",
id: 102,
schedules: [TestData.schedules.IstMorningShift],
defaultScheduleId: 2,
},
],
bookings: [
{
uid: "BOOKING_TO_RESCHEDULE_UID",
userId: 101,
attendees: [
{
email: "[email protected]",
},
],
eventTypeId: 1,
status: "ACCEPTED",
startTime: `${plus2DateString}T04:00:00.000Z`,
endTime: `${plus2DateString}T04:15:00.000Z`,
},
],
});
const schedule = await getSchedule({
input: {
eventTypeId: 1,
eventTypeSlug: "",
startTime: `${plus1DateString}T18:30:00.000Z`,
endTime: `${plus2DateString}T18:29:59.999Z`,
timeZone: Timezones["+5:30"],
isTeamEvent: true,
rescheduleUid: "BOOKING_TO_RESCHEDULE_UID",
routedTeamMemberIds: [102],
},
});
// expect only slots of IstEveningShift as this is the slots for the original host of the booking
expect(schedule).toHaveTimeSlots(
expectedSlotsForSchedule.IstMorningShift.interval["1hr"].allPossibleSlotsStartingAt430,
{
dateString: plus2DateString,
}
);
});
});
});
+26
View File
@@ -30,6 +30,32 @@ export const expectedSlotsForSchedule = {
},
},
},
IstMorningShift: {
interval: {
"1hr": {
allPossibleSlotsStartingAt430: [
"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",
],
allPossibleSlotsStartingAt4: [
"04:00:00.000Z",
"05:00:00.000Z",
"06:00:00.000Z",
"07:00:00.000Z",
"08:00:00.000Z",
"09:00:00.000Z",
"10:00:00.000Z",
"11:00:00.000Z",
],
},
},
},
};
declare global {
@@ -1283,6 +1283,9 @@ export function getOrganizer({
export function getScenarioData(
{
/**
* organizer has no special meaning. It is a regular user. It is supposed to be deprecated along with `usersApartFromOrganizer` and we should introduce a new `users` field instead
*/
organizer,
eventTypes,
usersApartFromOrganizer = [],