fix: recurring round robin events (#13471)

* use same lucky user + check availability

* add tests for recurring round robin events

* only use luckyUsers for recurring bookings

* don't check availability for all recurring dates

* code clean up

* pass schedulingType

* fix type error

* add availability check for fixed hosts + test

* fix type error

* implement feedback

---------

Co-authored-by: CarinaWolli <[email protected]>
Co-authored-by: Udit Takkar <[email protected]>
This commit is contained in:
authored and GitHub committed 2024-02-06 18:18:42 +00:00
1 parent 684f4a795c
commit 271f31730d
9 files changed
+1271 -547

No files matched your search

+2 -2
View File
@@ -798,10 +798,10 @@ describe("getSchedule", () => {
schedulingType: "COLLECTIVE",
hosts: [
{
id: 101,
userId: 101,
},
{
id: 102,
userId: 102,
},
],
},
@@ -49,11 +49,15 @@ type InputWorkflow = {
action: WorkflowActions;
template: WorkflowTemplates;
};
type InputHost = {
userId: number;
isFixed?: boolean;
};
/**
* Data to be mocked
*/
export type ScenarioData = {
// hosts: { id: number; eventTypeId?: number; userId?: number; isFixed?: boolean }[];
/**
* Prisma would return these eventTypes
*/
@@ -119,7 +123,7 @@ export type InputEventType = {
* These user ids are `ScenarioData["users"]["id"]`
*/
users?: { id: number }[];
hosts?: { id: number }[];
hosts?: InputHost[];
schedulingType?: SchedulingType;
beforeEventBuffer?: number;
afterEventBuffer?: number;
@@ -161,6 +165,20 @@ export const Timezones = {
"+6:00": "Asia/Dhaka",
};
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,
})),
});
}
}
}
async function addEventTypesToDb(
eventTypes: (Omit<
Prisma.EventTypeCreateInput,
@@ -283,6 +301,7 @@ async function addEventTypes(eventTypes: InputEventType[], usersStore: InputUser
}
: eventType.schedule,
owner: eventType.owner ? { connect: { id: eventType.owner } } : undefined,
schedulingType: eventType.schedulingType,
};
});
log.silly("TestData: Creating EventType", JSON.stringify(eventTypesWithUsers));
@@ -586,6 +605,7 @@ export async function createBookingScenario(data: ScenarioData) {
);
}
const eventTypes = await addEventTypes(data.eventTypes, data.users);
await addHostsToDb(data.eventTypes);
data.bookings = data.bookings || [];
// allowSuccessfulBookingCreation();
@@ -963,8 +983,7 @@ export function getScenarioData(
webhooks,
workflows,
bookings,
}: // hosts = [],
{
}: {
organizer: ReturnType<typeof getOrganizer>;
eventTypes: ScenarioData["eventTypes"];
apps?: ScenarioData["apps"];
@@ -972,7 +991,6 @@ export function getScenarioData(
webhooks?: ScenarioData["webhooks"];
workflows?: ScenarioData["workflows"];
bookings?: ScenarioData["bookings"];
// hosts?: ScenarioData["hosts"];
},
org?: { id: number | null } | undefined | null
) {
@@ -1003,7 +1021,6 @@ export function getScenarioData(
}
});
return {
// hosts: [...hosts],
eventTypes: eventTypes.map((eventType, index) => {
return {
...eventType,
@@ -1,3 +1,4 @@
import type { SchedulingType } from "@calcom/prisma/client";
import { getDate } from "@calcom/web/test/utils/bookingScenario/bookingScenario";
export const DEFAULT_TIMEZONE_BOOKER = "Asia/Kolkata";
@@ -24,6 +25,7 @@ export function getMockRequestDataForBooking({
bookingUid?: string;
recurringEventId?: string;
recurringCount?: number;
schedulingType?: SchedulingType;
responses: {
email: string;
name: string;