refactor: replace shouldServeCache with mode parameter for calendar cache control (#26539)
* refactor: replace shouldServeCache with mode parameter for calendar cache control Replace the boolean shouldServeCache parameter with a new CalendarFetchMode type that can have values 'slots', 'overlay', and 'booking'. This provides better control over when to serve cache vs relay on calendar providers. - 'slots' mode: Check feature flags and use cache when available (for getting actual calendar availability) - 'overlay' mode: Don't use cache (for overlay calendar availability) - 'booking' mode: Don't use cache (for booking confirmation) - undefined: Same as 'slots' for backwards compatibility The cache decision logic is now centralized in getCalendar.ts based on the mode parameter. Co-Authored-By: Volnei Munhoz <[email protected]> * fix: update CalendarService.test.ts to use mode parameter Co-Authored-By: Volnei Munhoz <[email protected]> * refactor: use shared GetAvailabilityParams type across all calendar services - Import GetAvailabilityParams and GetAvailabilityWithTimeZonesParams from @calcom/types/Calendar - Replace inline type definitions with shared types in all calendar service implementations - Update BaseCalendarService, CalendarCacheWrapper, and CalendarTelemetryWrapper - Ensures consistent typing and follows DRY principles Co-Authored-By: Volnei Munhoz <[email protected]> * fix: add missing IntegrationCalendar import and update mock getAvailability signature - Add IntegrationCalendar back to sendgrid CalendarService imports - Update bookingScenario mock getAvailability to use typed params object - Add listCalendars method to mock Calendar object Co-Authored-By: Volnei Munhoz <[email protected]> * fix: update test files to use typed params object for getAvailability methods - Update CalendarCacheWrapper.test.ts to call getAvailability/getAvailabilityWithTimeZones with params object - Update getCalendarsEvents.test.ts toHaveBeenCalledWith assertions to expect params object - All 32 tests now pass Co-Authored-By: Volnei Munhoz <[email protected]> * refactor: consolidate to single GetAvailabilityParams type for both getAvailability methods - Remove GetAvailabilityWithTimeZonesParams, use GetAvailabilityParams for both methods - Add mode parameter to getAvailabilityWithTimeZones calls - Update wrapper classes to pass mode through to underlying calendar - Update test files to include mode in getAvailabilityWithTimeZones calls and assertions Co-Authored-By: Volnei Munhoz <[email protected]> * refactor: use EventBusyDate with optional timeZone for getAvailabilityWithTimeZones - Add optional timeZone field to EventBusyDate type - Update getAvailabilityWithTimeZones return type to use EventBusyDate[] - Update Google Calendar service and wrapper classes to use the new type Co-Authored-By: Volnei Munhoz <[email protected]> * fix: type errors and remove unused calendar watching methods - Fix type errors in CalendarCacheWrapper.ts (convert null to undefined for timeZone) - Fix type errors in getCalendarsEvents.ts (ensure timeZone is always present) - Remove unused watchCalendar/unwatchCalendar from Calendar interface - Remove unused startWatchingCalendarsInGoogle/stopWatchingCalendarsInGoogle from GoogleCalendarService - Remove unused imports (uuid, uniqueBy, GOOGLE_WEBHOOK_URL, ONE_MONTH_IN_MS) Co-Authored-By: Volnei Munhoz <[email protected]> * fix: remove watchCalendar/unwatchCalendar from CalendarTelemetryWrapper Co-Authored-By: Volnei Munhoz <[email protected]> * refactor: remove verbose JSDoc param comments from wrapper classes Co-Authored-By: Volnei Munhoz <[email protected]> * refactor: make mode parameter required in getCalendar Co-Authored-By: Volnei Munhoz <[email protected]> * fix: add required mode parameter to all getCalendar callers Co-Authored-By: Volnei Munhoz <[email protected]> * fix: provide default mode value in getBusyCalendarTimes Co-Authored-By: Volnei Munhoz <[email protected]> * fix: add mode parameter to remaining getCalendar callers Co-Authored-By: Volnei Munhoz <[email protected]> * fix: add mode parameter to vital and wipemycalother reschedule Co-Authored-By: Volnei Munhoz <[email protected]> * fix: add mode parameter to credential-sync API endpoint Co-Authored-By: Volnei Munhoz <[email protected]> * refactor: add 'none' mode to CalendarFetchMode and use as default Co-Authored-By: Volnei Munhoz <[email protected]> * test: add mode parameter to getCalendarsEvents test calls Co-Authored-By: Volnei Munhoz <[email protected]> * Update packages/app-store/delegationCredential.ts Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
This commit is contained in:
37 files changed
+356
-369
No files matched your search
@@ -1740,7 +1740,7 @@ type GetAvailabilityMethodMockCall = CalendarServiceMethodMockCallBase & {
|
||||
dateFrom: string;
|
||||
dateTo: string;
|
||||
selectedCalendars: IntegrationCalendar[];
|
||||
shouldServeCache?: boolean;
|
||||
mode: "slots" | "overlay" | "booking";
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1941,12 +1941,14 @@ export async function mockCalendar(
|
||||
},
|
||||
});
|
||||
},
|
||||
getAvailability: async (
|
||||
dateFrom: string,
|
||||
dateTo: string,
|
||||
selectedCalendars: IntegrationCalendar[],
|
||||
shouldServeCache?: boolean
|
||||
): Promise<EventBusyDate[]> => {
|
||||
getAvailability: async (params: {
|
||||
dateFrom: string;
|
||||
dateTo: string;
|
||||
selectedCalendars: IntegrationCalendar[];
|
||||
mode: "slots" | "overlay" | "booking";
|
||||
fallbackToPrimary?: boolean;
|
||||
}): Promise<EventBusyDate[]> => {
|
||||
const { dateFrom, dateTo, selectedCalendars, mode } = params;
|
||||
if (calendarData?.getAvailabilityCrash) {
|
||||
throw new Error("MockCalendarService.getAvailability fake error");
|
||||
}
|
||||
@@ -1955,7 +1957,7 @@ export async function mockCalendar(
|
||||
dateFrom,
|
||||
dateTo,
|
||||
selectedCalendars,
|
||||
shouldServeCache,
|
||||
mode,
|
||||
},
|
||||
calendarServiceConstructorArgs: {
|
||||
credential,
|
||||
@@ -1965,6 +1967,9 @@ export async function mockCalendar(
|
||||
resolve(calendarData?.busySlots || []);
|
||||
});
|
||||
},
|
||||
listCalendars: async function (): Promise<IntegrationCalendar[]> {
|
||||
return Promise.resolve([]);
|
||||
},
|
||||
} as Calendar;
|
||||
}
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user