Skip to content

Commit d04a16c

Browse files
committed
fix type errors
1 parent f69b542 commit d04a16c

File tree

3 files changed

+80
-44
lines changed

3 files changed

+80
-44
lines changed

packages/features/ee/round-robin/handleRescheduleEventManager.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,13 @@ export const handleRescheduleEventManager = async ({
7676
const calVideoResult = results.find(
7777
(result) => result.type.includes("_video") && result.type === "daily_video"
7878
);
79-
// Check if Cal Video Creation Failed - That is the fallback for Cal.com and must always work
79+
// Check if Cal Video Creation Failed - That is the fallback for Cal.com and is expected to always work
8080
if (calVideoResult && !calVideoResult.success) {
8181
handleRescheduleEventManager.error("Cal Video creation failed", {
8282
error: calVideoResult.error,
8383
bookingLocation,
8484
});
85+
// This happens only when Cal Video is down
8586
throw new Error("Failed to set video conferencing link, but the meeting has been rescheduled");
8687
}
8788

@@ -92,11 +93,6 @@ export const handleRescheduleEventManager = async ({
9293
let videoCallUrl = _videoCallUrl;
9394
let metadata: AdditionalInformation = {};
9495
metadata = videoMetadata;
95-
console.log("resultsOfHandleRescheduleEventManager", {
96-
results,
97-
bookingLocation,
98-
evt,
99-
});
10096
if (results.length) {
10197
// Handle Google Meet results
10298
if (bookingLocation === MeetLocationType) {
@@ -170,9 +166,7 @@ export const handleRescheduleEventManager = async ({
170166
? calendarResult?.updatedEvent[0]?.iCalUID
171167
: calendarResult?.updatedEvent?.iCalUID || undefined;
172168
}
173-
console.log("updateManager", {
174-
updateManager,
175-
});
169+
176170
const newReferencesToCreate = structuredClone(updateManager.referencesToCreate);
177171

178172
await BookingReferenceRepository.replaceBookingReferences({

packages/features/ee/round-robin/roundRobinManualReassignment.test.ts

Lines changed: 76 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,35 @@ vi.mock("@calcom/app-store/utils", () => ({
2727
getAppFromSlug: vi.fn(),
2828
}));
2929

30+
// Type definitions
31+
type TestUserMetadata = {
32+
defaultConferencingApp?: {
33+
appSlug: string;
34+
appLink?: string;
35+
};
36+
};
37+
38+
type TestUser = {
39+
id: number;
40+
name: string;
41+
timeZone: string;
42+
username: string;
43+
email: string;
44+
schedules: (typeof TestData.schedules.IstWorkHours)[];
45+
destinationCalendar?: { integration: string; externalId: string };
46+
metadata?: TestUserMetadata;
47+
};
48+
49+
type MockBookingAttendee = ReturnType<typeof getMockBookingAttendee>;
50+
3051
// Test Data Builders
3152
const createTestUser = (overrides?: {
3253
id?: number;
3354
name?: string;
3455
username?: string;
3556
email?: string;
3657
destinationCalendar?: { integration: string; externalId: string };
37-
metadata?: Record<string, any>;
58+
metadata?: TestUserMetadata;
3859
}) => ({
3960
id: overrides?.id ?? 1,
4061
name: overrides?.name ?? `user-${overrides?.id ?? 1}`,
@@ -44,6 +65,18 @@ const createTestUser = (overrides?: {
4465
schedules: [TestData.schedules.IstWorkHours],
4566
destinationCalendar: overrides?.destinationCalendar,
4667
metadata: overrides?.metadata,
68+
defaultScheduleId: 1,
69+
credentials: [],
70+
selectedCalendars: [],
71+
weekStart: "Monday" as const,
72+
teams: [],
73+
availability: [],
74+
profiles: [],
75+
outOfOffice: undefined,
76+
smsLockState: undefined,
77+
completedOnboarding: true,
78+
locked: false,
79+
organizationId: null,
4780
});
4881

4982
const createTestDestinationCalendar = (overrides?: { integration?: string; externalId?: string }) => ({
@@ -56,7 +89,7 @@ const createTestBooking = async (params: {
5689
userId: number;
5790
bookingId: number;
5891
bookingUid: string;
59-
attendees?: any[];
92+
attendees?: MockBookingAttendee[];
6093
location?: string;
6194
}) => {
6295
const { dateString: dateStringPlusOne } = getDate({ dateIncrement: 1 });
@@ -85,11 +118,12 @@ const createTestBooking = async (params: {
85118
const createRoundRobinEventType = (params: {
86119
id: number;
87120
slug: string;
88-
users: any[];
89-
hosts?: any[];
90-
locations?: any[];
121+
users: TestUser[];
122+
hosts?: { userId: number; isFixed: boolean }[];
123+
locations?: { type: string; credentialId?: number }[];
91124
teamId?: number;
92125
schedulingType?: SchedulingType;
126+
parentId?: number;
93127
}) => ({
94128
id: params.id,
95129
slug: params.slug,
@@ -99,16 +133,17 @@ const createRoundRobinEventType = (params: {
99133
hosts: params.hosts ?? params.users.map((user) => ({ userId: user.id, isFixed: false })),
100134
locations: params.locations,
101135
teamId: params.teamId,
136+
parentId: params.parentId,
102137
});
103138

104139
// Assertion Helpers
105140
const expectEventManagerCalledWith = (
106-
spy: any,
141+
spy: ReturnType<typeof vi.spyOn>,
107142
expectedParams: {
108143
location?: string;
109144
uid: string;
110145
changedOrganizer: boolean;
111-
destinationCalendars?: any[];
146+
destinationCalendars?: Array<{ integration: string; externalId: string }>;
112147
}
113148
) => {
114149
expect(spy).toHaveBeenCalledTimes(1);
@@ -128,13 +163,26 @@ type MockEventManagerConfig = {
128163
failConferencing?: boolean;
129164
};
130165

166+
type ConferenceResult = {
167+
type: string;
168+
success: boolean;
169+
uid: string;
170+
originalEvent: Record<string, unknown>;
171+
error?: string;
172+
updatedEvent?: {
173+
url: string;
174+
};
175+
};
176+
131177
const mockEventManagerReschedule = async (config?: MockEventManagerConfig) => {
132178
const EventManager = (await import("@calcom/lib/EventManager")).default;
179+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
133180
const spy = vi.spyOn(EventManager.prototype as any, "reschedule");
134181

182+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
135183
spy.mockImplementation(async (event: any) => {
136184
const location = event.location;
137-
const results: any[] = [];
185+
const results: ConferenceResult[] = [];
138186

139187
// Check if location is a static link (starts with http:// or https://)
140188
const isStaticLink = location?.startsWith("http://") || location?.startsWith("https://");
@@ -208,7 +256,7 @@ describe("roundRobinManualReassignment test", () => {
208256
trigger: "NEW_EVENT",
209257
action: "EMAIL_HOST",
210258
template: "REMINDER",
211-
activeEventTypeId: 1,
259+
activeOn: [1],
212260
},
213261
],
214262
eventTypes: [
@@ -235,7 +283,7 @@ describe("roundRobinManualReassignment test", () => {
235283
{
236284
bookingUid: bookingToReassignUid,
237285
method: WorkflowMethods.EMAIL,
238-
scheduledDate: dateStringPlusTwo,
286+
scheduledDate: new Date(dateStringPlusTwo),
239287
scheduled: true,
240288
workflowStepId: 1,
241289
workflowId: 1,
@@ -269,7 +317,7 @@ describe("roundRobinManualReassignment test", () => {
269317
expectWorkflowToBeTriggered({ emailsToReceive: [newHost.email], emails });
270318
});
271319

272-
test("should include conferenceCredentialId when reassigning booking with conference location", async () => {
320+
test("should include conferenceCredentialId when reassigning booking with with fixed host as organizer", async () => {
273321
const roundRobinManualReassignment = (await import("./roundRobinManualReassignment")).default;
274322
const eventManagerRescheduleSpy = await mockEventManagerReschedule();
275323

@@ -320,6 +368,7 @@ describe("roundRobinManualReassignment test", () => {
320368
// Verify that EventManager.reschedule was called with an event containing conferenceCredentialId
321369
expect(eventManagerRescheduleSpy).toHaveBeenCalledTimes(1);
322370
const calledEvent = eventManagerRescheduleSpy.mock.calls[0][0];
371+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
323372
expect((calledEvent as any).conferenceCredentialId).toBe(conferenceCredentialId);
324373
});
325374

@@ -402,16 +451,15 @@ describe("roundRobinManualReassignment test", () => {
402451
userId: fixedHost.id,
403452
});
404453

405-
const bookingRepo = new BookingRepository(prismaMock);
454+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
455+
const bookingRepo = new BookingRepository(prismaMock as any);
406456
const attendees = await bookingRepo.getBookingAttendees(123);
407457

408458
expect(attendees.some((attendee) => attendee.email === currentRRHost.email)).toBe(false);
409459
expect(attendees.some((attendee) => attendee.email === newHost.email)).toBe(true);
410460
});
411461

412-
test("should send cancellation email to previous round robin attendee when reassigning", async ({
413-
emails,
414-
}) => {
462+
test("should send cancellation email to previous round robin attendee when reassigning", async () => {
415463
const roundRobinManualReassignment = (await import("./roundRobinManualReassignment")).default;
416464
await mockEventManagerReschedule();
417465

@@ -528,6 +576,7 @@ describe("roundRobinManualReassignment - Location Changes", () => {
528576
type: "integrations:google:meet",
529577
},
530578
},
579+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
531580
} as any;
532581
}
533582
if (slug === "zoom" && config?.zoom !== false) {
@@ -537,6 +586,7 @@ describe("roundRobinManualReassignment - Location Changes", () => {
537586
type: "integrations:zoom",
538587
},
539588
},
589+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
540590
} as any;
541591
}
542592
if (slug === "custom-video" && config?.customVideo !== false) {
@@ -546,6 +596,7 @@ describe("roundRobinManualReassignment - Location Changes", () => {
546596
type: "integrations:custom-video",
547597
},
548598
},
599+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
549600
} as any;
550601
}
551602
return undefined;
@@ -568,19 +619,12 @@ describe("roundRobinManualReassignment - Location Changes", () => {
568619

569620
await createBookingScenario(
570621
getScenarioData({
571-
teams: [
572-
{
573-
id: 1,
574-
name: "Test Team",
575-
slug: "test-team",
576-
},
577-
],
578622
eventTypes: [
579623
createRoundRobinEventType({
580624
id: 1,
581625
slug: "round-robin-event",
582626
teamId: 1,
583-
users,
627+
users: Object.values(users),
584628
locations: [{ type: OrganizerDefaultConferencingAppType }, { type: "integrations:daily" }],
585629
}),
586630
],
@@ -642,7 +686,7 @@ describe("roundRobinManualReassignment - Location Changes", () => {
642686
createRoundRobinEventType({
643687
id: 2,
644688
slug: "round-robin-event-fallback",
645-
users,
689+
users: Object.values(users),
646690
locations: [
647691
{ type: OrganizerDefaultConferencingAppType },
648692
{ type: "integrations:first-available" },
@@ -672,6 +716,7 @@ describe("roundRobinManualReassignment - Location Changes", () => {
672716
});
673717

674718
const calledEvent = eventManagerRescheduleSpy.mock.calls[0][0];
719+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
675720
expect((calledEvent as any).location).toBe("integrations:first-available");
676721
});
677722

@@ -693,8 +738,9 @@ describe("roundRobinManualReassignment - Location Changes", () => {
693738
createRoundRobinEventType({
694739
id: 4,
695740
slug: "managed-event",
696-
schedulingType: "MANAGED" as SchedulingType,
697-
users,
741+
// This is a managed event type child which allows Organizer's Default Conferencing App
742+
parentId: 1,
743+
users: Object.values(users),
698744
locations: [{ type: OrganizerDefaultConferencingAppType }],
699745
}),
700746
],
@@ -721,6 +767,7 @@ describe("roundRobinManualReassignment - Location Changes", () => {
721767
});
722768

723769
const calledEvent = eventManagerRescheduleSpy.mock.calls[0][0];
770+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
724771
expect((calledEvent as any).location).toBe("https://custom-video.com/room123");
725772
});
726773

@@ -742,7 +789,7 @@ describe("roundRobinManualReassignment - Location Changes", () => {
742789
createRoundRobinEventType({
743790
id: 3,
744791
slug: "round-robin-event-error",
745-
users,
792+
users: Object.values(users),
746793
teamId: 1,
747794
locations: [{ type: OrganizerDefaultConferencingAppType }],
748795
}),
@@ -770,6 +817,7 @@ describe("roundRobinManualReassignment - Location Changes", () => {
770817
});
771818

772819
const calledEvent = eventManagerRescheduleSpy.mock.calls[0][0];
820+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
773821
expect((calledEvent as any).location).toBe("integrations:google:meet");
774822

775823
await expectBookingToBeInDatabase({
@@ -796,7 +844,7 @@ describe("roundRobinManualReassignment - Location Changes", () => {
796844
createRoundRobinEventType({
797845
id: 3,
798846
slug: "round-robin-event-error",
799-
users,
847+
users: Object.values(users),
800848
locations: [{ type: OrganizerDefaultConferencingAppType }],
801849
}),
802850
],

packages/features/ee/round-robin/roundRobinManualReassignment.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,6 @@ export const roundRobinManualReassignment = async ({
117117

118118
const originalOrganizer = booking.user;
119119
const hasOrganizerChanged = !fixedHost && booking.userId !== newUserId;
120-
console.log("hasOrganizerChanged", {
121-
hasOrganizerChanged,
122-
fixedHost,
123-
bookingUserId: booking.userId,
124-
newUserId,
125-
});
126120
const newUser = newUserHost.user;
127121
const newUserT = await getTranslation(newUser.locale || "en", "common");
128122
const originalOrganizerT = await getTranslation(originalOrganizer.locale || "en", "common");
@@ -162,7 +156,7 @@ export const roundRobinManualReassignment = async ({
162156
const responses = responseSafeParse.success ? responseSafeParse.data : undefined;
163157

164158
// Determine the location for the new host
165-
const isManagedEventType = eventType.schedulingType === "MANAGED";
159+
const isManagedEventType = !!eventType.parentId;
166160
const isTeamEventType = !!eventType.teamId;
167161

168162
const locationResult = BookingLocationService.getLocationForHost({

0 commit comments

Comments
 (0)