refactor: apply biome formatting to several packages (#27439)
* refactor: apply biome formatting to Phase 1 packages Packages formatted: - packages/app-store-cli - packages/config - packages/dayjs - packages/debugging - packages/embeds/embed-react - packages/embeds/embed-snippet - packages/kysely - packages/platform/constants - packages/platform/utils - packages/testing - packages/tsconfig Co-Authored-By: [email protected] <[email protected]> * fix: restore non-null assertions in embed-snippet to fix type error Co-Authored-By: [email protected] <[email protected]> * fix: remove ESM import from CommonJS config file Biome incorrectly added 'import process from node:process' to a CommonJS file that uses require(). This breaks Jest which expects CommonJS syntax. The process global is already available in Node.js without explicit import. Co-Authored-By: [email protected] <[email protected]> * refactor: exclude packages/embeds from Phase 1 formatting Per user request, reverting all biome formatting changes in packages/embeds to handle separately. Co-Authored-By: [email protected] <[email protected]> * fix: restore const enum for BookingLocations Biome changed 'const enum' to 'enum' which is a semantic change. Reverting to keep the PR purely formatting-only. Co-Authored-By: [email protected] <[email protected]> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
c652c61e0c
commit
357c2882ad
50 files changed
+349
-452
No files matched your search
@@ -1,5 +1,4 @@
|
||||
import { sleep } from "k6";
|
||||
|
||||
import { THRESHOLDS } from "../utils/config.js";
|
||||
import { viewBookingPage } from "../utils/helpers.js";
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { sleep } from "k6";
|
||||
|
||||
import { THRESHOLDS } from "../utils/config.js";
|
||||
import { viewBookingPage } from "../utils/helpers.js";
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { sleep } from "k6";
|
||||
|
||||
import { THRESHOLDS } from "../utils/config.js";
|
||||
import { viewBookingPage } from "../utils/helpers.js";
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { sleep } from "k6";
|
||||
|
||||
import { THRESHOLDS } from "../utils/config.js";
|
||||
import { viewBookingPage } from "../utils/helpers.js";
|
||||
|
||||
|
||||
@@ -35,12 +35,10 @@ export const THRESHOLDS = {
|
||||
},
|
||||
};
|
||||
|
||||
export const TEST_USERS = new SharedArray("users", function () {
|
||||
return [
|
||||
{ username: __ENV.TEST_USER_FREE || "free", password: __ENV.TEST_PASSWORD_FREE || "free" },
|
||||
{ username: __ENV.TEST_USER_PRO || "pro", password: __ENV.TEST_PASSWORD_PRO || "pro" },
|
||||
];
|
||||
});
|
||||
export const TEST_USERS = new SharedArray("users", () => [
|
||||
{ username: __ENV.TEST_USER_FREE || "free", password: __ENV.TEST_PASSWORD_FREE || "free" },
|
||||
{ username: __ENV.TEST_USER_PRO || "pro", password: __ENV.TEST_PASSWORD_PRO || "pro" },
|
||||
]);
|
||||
|
||||
export function getRandomUser() {
|
||||
return TEST_USERS[Math.floor(Math.random() * TEST_USERS.length)];
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { check, group } from "k6";
|
||||
import http from "k6/http";
|
||||
|
||||
import { randomSleep, BASE_URL, randomQueryParam } from "./config.js";
|
||||
import { BASE_URL, randomQueryParam, randomSleep } from "./config.js";
|
||||
|
||||
export function viewBookingPage(username, eventSlug) {
|
||||
return group("View Booking Page", () => {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { beforeEach, vi } from "vitest";
|
||||
import { mockReset, mockDeep } from "vitest-mock-extended";
|
||||
|
||||
import type * as i18n from "@calcom/lib/server/i18n";
|
||||
import { beforeEach, vi } from "vitest";
|
||||
import { mockDeep, mockReset } from "vitest-mock-extended";
|
||||
|
||||
vi.mock("@calcom/lib/server/i18n", () => i18nMock);
|
||||
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { type DMMF } from "@prisma/client/runtime/client";
|
||||
import { getDMMF } from "@prisma/internals";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { beforeEach, vi } from "vitest";
|
||||
import { createPrismock } from "prismock/build/main/lib/client";
|
||||
|
||||
import logger from "@calcom/lib/logger";
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
import * as selects from "@calcom/prisma/selects";
|
||||
import type { DMMF } from "@prisma/client/runtime/client";
|
||||
import { getDMMF } from "@prisma/internals";
|
||||
import { createPrismock } from "prismock/build/main/lib/client";
|
||||
import { beforeEach, vi } from "vitest";
|
||||
|
||||
vi.stubEnv("DATABASE_URL", "postgresql://user:password@localhost:5432/testdb");
|
||||
|
||||
@@ -56,7 +55,7 @@ const prismaMockProxy = new Proxy(proxyTarget, {
|
||||
}
|
||||
return prop in prismockInstance;
|
||||
},
|
||||
ownKeys(target) {
|
||||
ownKeys(_target) {
|
||||
if (!prismockInstance) {
|
||||
return [];
|
||||
}
|
||||
@@ -68,7 +67,7 @@ const prismaMockProxy = new Proxy(proxyTarget, {
|
||||
}
|
||||
(target as any)[prop] = value;
|
||||
return true;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
vi.mock("@calcom/prisma", async (importOriginal) => {
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
import { beforeEach, vi } from "vitest";
|
||||
import { type DeepMockProxy, mockDeep, mockReset } from "vitest-mock-extended";
|
||||
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
|
||||
const prisma = mockDeep<PrismaClient>() as unknown as DeepMockProxy<PrismaClient>;
|
||||
|
||||
vi.mock("@calcom/prisma", () => ({
|
||||
|
||||
@@ -4,7 +4,7 @@ import "vitest-fetch-mock";
|
||||
|
||||
import { sendAwaitingPaymentEmailAndSMS } from "@calcom/emails/email-manager";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import type { Payment, Prisma, PaymentOption, Booking } from "@calcom/prisma/client";
|
||||
import type { Booking, Payment, PaymentOption, Prisma } from "@calcom/prisma/client";
|
||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
import type { IAbstractPaymentService } from "@calcom/types/PaymentService";
|
||||
|
||||
@@ -23,10 +23,10 @@ export function getMockPaymentService() {
|
||||
async create(
|
||||
payment: Pick<Prisma.PaymentUncheckedCreateInput, "amount" | "currency">,
|
||||
bookingId: Booking["id"],
|
||||
userId: Booking["userId"],
|
||||
username: string | null,
|
||||
bookerName: string | null,
|
||||
bookerEmail: string,
|
||||
_userId: Booking["userId"],
|
||||
_username: string | null,
|
||||
_bookerName: string | null,
|
||||
_bookerEmail: string,
|
||||
paymentOption: PaymentOption
|
||||
) {
|
||||
const paymentCreateData = {
|
||||
@@ -59,7 +59,7 @@ export function getMockPaymentService() {
|
||||
}
|
||||
async afterPayment(
|
||||
event: CalendarEvent,
|
||||
booking: {
|
||||
_booking: {
|
||||
user: { email: string | null; name: string | null; timeZone: string } | null;
|
||||
id: number;
|
||||
startTime: { toISOString: () => string };
|
||||
@@ -71,12 +71,14 @@ export function getMockPaymentService() {
|
||||
await sendAwaitingPaymentEmailAndSMS({
|
||||
...event,
|
||||
paymentInfo: {
|
||||
link: createPaymentLink(/*{
|
||||
link: createPaymentLink(
|
||||
/*{
|
||||
paymentUid: paymentData.uid,
|
||||
name: booking.user?.name,
|
||||
email: booking.user?.email,
|
||||
date: booking.startTime.toISOString(),
|
||||
}*/),
|
||||
}*/
|
||||
),
|
||||
paymentOption: paymentData.paymentOption || "ON_BOOKING",
|
||||
amount: paymentData.amount,
|
||||
currency: paymentData.currency,
|
||||
|
||||
@@ -1,45 +1,52 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import i18nMock from "../__mocks__/libServerI18n";
|
||||
import prismock from "../__mocks__/prisma";
|
||||
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { vi } from "vitest";
|
||||
import "vitest-fetch-mock";
|
||||
import type { z } from "zod";
|
||||
|
||||
import { appStoreMetadata } from "@calcom/app-store/appStoreMetaData";
|
||||
import { weekdayToWeekIndex, type WeekDays } from "@calcom/lib/dayjs";
|
||||
import { type WeekDays, weekdayToWeekIndex } from "@calcom/lib/dayjs";
|
||||
import type { IntervalLimit } from "@calcom/lib/intervalLimits/intervalLimitSchema";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import type { BookingReference, Attendee, Booking, Membership } from "@calcom/prisma/client";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
import type { WebhookTriggerEvents } from "@calcom/prisma/client";
|
||||
import type {
|
||||
Attendee,
|
||||
Booking,
|
||||
BookingReference,
|
||||
Membership,
|
||||
Prisma,
|
||||
WebhookTriggerEvents,
|
||||
WorkflowActions,
|
||||
WorkflowMethods,
|
||||
WorkflowTemplates,
|
||||
WorkflowTriggerEvents,
|
||||
WorkflowMethods,
|
||||
} from "@calcom/prisma/client";
|
||||
import type { PaymentOption, SchedulingType, SMSLockState, TimeUnit } from "@calcom/prisma/enums";
|
||||
import type { BookingStatus } from "@calcom/prisma/enums";
|
||||
import type { teamMetadataSchema } from "@calcom/prisma/zod-utils";
|
||||
import type { userMetadataType } from "@calcom/prisma/zod-utils";
|
||||
import type { eventTypeBookingFields } from "@calcom/prisma/zod-utils";
|
||||
import type { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
||||
import type {
|
||||
BookingStatus,
|
||||
PaymentOption,
|
||||
SchedulingType,
|
||||
SMSLockState,
|
||||
TimeUnit,
|
||||
} from "@calcom/prisma/enums";
|
||||
import type {
|
||||
EventTypeMetaDataSchema,
|
||||
eventTypeBookingFields,
|
||||
teamMetadataSchema,
|
||||
userMetadataType,
|
||||
} from "@calcom/prisma/zod-utils";
|
||||
import type { AppMeta } from "@calcom/types/App";
|
||||
import type {
|
||||
Calendar,
|
||||
CalendarEvent,
|
||||
EventBusyDate,
|
||||
IntegrationCalendar,
|
||||
NewCalendarEventType,
|
||||
EventBusyDate,
|
||||
} from "@calcom/types/Calendar";
|
||||
import type { CredentialPayload } from "@calcom/types/Credential";
|
||||
import type { VideoApiAdapter } from "@calcom/types/VideoApiAdapter";
|
||||
|
||||
import { getMockPaymentService } from "./MockPaymentService";
|
||||
import type { z } from "zod";
|
||||
import type { getMockRequestDataForBooking } from "./getMockRequestDataForBooking";
|
||||
import { getMockPaymentService } from "./MockPaymentService";
|
||||
|
||||
type NonNullableVideoApiAdapter = NonNullable<VideoApiAdapter>;
|
||||
vi.mock("@calcom/app-store/calendar.services.generated", () => ({
|
||||
@@ -57,7 +64,7 @@ vi.mock("@calcom/app-store/video.adapters.generated", () => ({
|
||||
VideoApiAdapterMap: new Proxy(
|
||||
{},
|
||||
{
|
||||
get(target, prop) {
|
||||
get(_target, prop) {
|
||||
if (typeof prop === "string" && mockVideoAdapterRegistry[prop]) {
|
||||
return mockVideoAdapterRegistry[prop];
|
||||
}
|
||||
@@ -578,7 +585,7 @@ export async function addEventTypes(eventTypes: InputEventType[], usersStore: In
|
||||
data: eventType.restrictionSchedule.create.availability.createMany.data,
|
||||
},
|
||||
},
|
||||
user: { connect: { id: eventType.userId || (eventType.users && eventType.users[0]?.id) || 1 } },
|
||||
user: { connect: { id: eventType.userId || eventType.users?.[0]?.id || 1 } },
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
@@ -1131,12 +1138,7 @@ export async function createCredentials(
|
||||
* use vi.setSystemTime to fix the date and time and then use hardcoded days instead of dynamic date calculation.
|
||||
*/
|
||||
export const getDate = (
|
||||
param: {
|
||||
dateIncrement?: number;
|
||||
monthIncrement?: number;
|
||||
yearIncrement?: number;
|
||||
fromDate?: Date;
|
||||
} = {}
|
||||
param: { dateIncrement?: number; monthIncrement?: number; yearIncrement?: number; fromDate?: Date } = {}
|
||||
) => {
|
||||
let { dateIncrement, monthIncrement, yearIncrement, fromDate } = param;
|
||||
|
||||
@@ -1837,163 +1839,154 @@ export async function mockCalendar(
|
||||
if (calendarServicePromise) {
|
||||
const resolvedService = await calendarServicePromise;
|
||||
vi.mocked(resolvedService.default).mockImplementation(function MockCalendarService(credential) {
|
||||
return {
|
||||
createEvent: async function (
|
||||
...rest: Parameters<Calendar["createEvent"]>
|
||||
): Promise<NewCalendarEventType> {
|
||||
if (calendarData?.creationCrash) {
|
||||
throw new Error("MockCalendarService.createEvent fake error");
|
||||
}
|
||||
const [calEvent, credentialId, externalCalendarId] = rest;
|
||||
log.debug(
|
||||
"mockCalendar.createEvent",
|
||||
JSON.stringify({ calEvent, credentialId, externalCalendarId })
|
||||
);
|
||||
createEventCalls.push({
|
||||
args: {
|
||||
calEvent,
|
||||
credentialId,
|
||||
externalCalendarId,
|
||||
},
|
||||
calendarServiceConstructorArgs: {
|
||||
credential,
|
||||
},
|
||||
});
|
||||
const isGoogleMeetLocation = calEvent?.location === BookingLocations.GoogleMeet;
|
||||
if (app.type === "google_calendar") {
|
||||
return Promise.resolve({
|
||||
type: app.type,
|
||||
additionalInfo: {
|
||||
hangoutLink:
|
||||
normalizedCalendarData.create?.appSpecificData?.googleCalendar?.hangoutLink ||
|
||||
"https://GOOGLE_MEET_URL_IN_CALENDAR_EVENT",
|
||||
},
|
||||
return {
|
||||
createEvent: async (...rest: Parameters<Calendar["createEvent"]>): Promise<NewCalendarEventType> => {
|
||||
if (calendarData?.creationCrash) {
|
||||
throw new Error("MockCalendarService.createEvent fake error");
|
||||
}
|
||||
const [calEvent, credentialId, externalCalendarId] = rest;
|
||||
log.debug(
|
||||
"mockCalendar.createEvent",
|
||||
JSON.stringify({ calEvent, credentialId, externalCalendarId })
|
||||
);
|
||||
createEventCalls.push({
|
||||
args: {
|
||||
calEvent,
|
||||
credentialId,
|
||||
externalCalendarId,
|
||||
},
|
||||
calendarServiceConstructorArgs: {
|
||||
credential,
|
||||
},
|
||||
});
|
||||
const isGoogleMeetLocation = calEvent?.location === BookingLocations.GoogleMeet;
|
||||
if (app.type === "google_calendar") {
|
||||
return Promise.resolve({
|
||||
type: app.type,
|
||||
additionalInfo: {
|
||||
hangoutLink:
|
||||
normalizedCalendarData.create?.appSpecificData?.googleCalendar?.hangoutLink ||
|
||||
"https://GOOGLE_MEET_URL_IN_CALENDAR_EVENT",
|
||||
uid: normalizedCalendarData.create?.uid || "GOOGLE_CALENDAR_EVENT_ID",
|
||||
id: normalizedCalendarData.create?.id || "GOOGLE_CALENDAR_EVENT_ID",
|
||||
iCalUID:
|
||||
normalizedCalendarData.create?.iCalUID || calEvent.iCalUID || "GOOGLE_CALENDAR_EVENT_ID",
|
||||
password: "MOCK_PASSWORD",
|
||||
url:
|
||||
normalizedCalendarData.create?.appSpecificData?.googleCalendar?.hangoutLink ||
|
||||
"https://GOOGLE_MEET_URL_IN_CALENDAR_EVENT",
|
||||
});
|
||||
} else if (app.type === "office365_calendar") {
|
||||
return Promise.resolve({
|
||||
type: app.type,
|
||||
additionalInfo: {},
|
||||
uid: normalizedCalendarData.create?.uid || "OFFICE_365_CALENDAR_EVENT_ID",
|
||||
id: normalizedCalendarData.create?.id || "OFFICE_365_CALENDAR_EVENT_ID",
|
||||
iCalUID:
|
||||
normalizedCalendarData.create?.iCalUID ||
|
||||
calEvent.iCalUID ||
|
||||
"OFFICE_365_CALENDAR_EVENT_ID",
|
||||
password: "MOCK_PASSWORD",
|
||||
url:
|
||||
normalizedCalendarData.create?.appSpecificData?.office365Calendar?.url ||
|
||||
"https://UNUSED_URL",
|
||||
});
|
||||
} else {
|
||||
return Promise.resolve({
|
||||
type: app.type,
|
||||
additionalInfo: {},
|
||||
uid: "PROBABLY_UNUSED_UID",
|
||||
hangoutLink:
|
||||
(isGoogleMeetLocation
|
||||
? normalizedCalendarData.create?.appSpecificData?.googleCalendar?.hangoutLink
|
||||
: null) || "https://UNUSED_URL",
|
||||
// A Calendar is always expected to return an id.
|
||||
id: normalizedCalendarData.create?.id || "FALLBACK_MOCK_CALENDAR_EVENT_ID",
|
||||
iCalUID: normalizedCalendarData.create?.iCalUID,
|
||||
// Password and URL seems useless for CalendarService, plan to remove them if that's the case
|
||||
password: "MOCK_PASSWORD",
|
||||
url: "https://UNUSED_URL",
|
||||
});
|
||||
}
|
||||
},
|
||||
updateEvent: async function (
|
||||
...rest: Parameters<Calendar["updateEvent"]>
|
||||
): Promise<NewCalendarEventType> {
|
||||
if (calendarData?.updationCrash) {
|
||||
throw new Error("MockCalendarService.updateEvent fake error");
|
||||
}
|
||||
const [uid, event, externalCalendarId] = rest;
|
||||
log.silly("mockCalendar.updateEvent", JSON.stringify({ uid, event, externalCalendarId }));
|
||||
updateEventCalls.push({
|
||||
args: {
|
||||
uid,
|
||||
event,
|
||||
externalCalendarId,
|
||||
},
|
||||
calendarServiceConstructorArgs: {
|
||||
credential,
|
||||
},
|
||||
hangoutLink:
|
||||
normalizedCalendarData.create?.appSpecificData?.googleCalendar?.hangoutLink ||
|
||||
"https://GOOGLE_MEET_URL_IN_CALENDAR_EVENT",
|
||||
uid: normalizedCalendarData.create?.uid || "GOOGLE_CALENDAR_EVENT_ID",
|
||||
id: normalizedCalendarData.create?.id || "GOOGLE_CALENDAR_EVENT_ID",
|
||||
iCalUID:
|
||||
normalizedCalendarData.create?.iCalUID || calEvent.iCalUID || "GOOGLE_CALENDAR_EVENT_ID",
|
||||
password: "MOCK_PASSWORD",
|
||||
url:
|
||||
normalizedCalendarData.create?.appSpecificData?.googleCalendar?.hangoutLink ||
|
||||
"https://GOOGLE_MEET_URL_IN_CALENDAR_EVENT",
|
||||
});
|
||||
const isGoogleMeetLocation = event.location === BookingLocations.GoogleMeet;
|
||||
} else if (app.type === "office365_calendar") {
|
||||
return Promise.resolve({
|
||||
type: app.type,
|
||||
additionalInfo: {},
|
||||
uid: normalizedCalendarData.create?.uid || "OFFICE_365_CALENDAR_EVENT_ID",
|
||||
id: normalizedCalendarData.create?.id || "OFFICE_365_CALENDAR_EVENT_ID",
|
||||
iCalUID:
|
||||
normalizedCalendarData.create?.iCalUID || calEvent.iCalUID || "OFFICE_365_CALENDAR_EVENT_ID",
|
||||
password: "MOCK_PASSWORD",
|
||||
url:
|
||||
normalizedCalendarData.create?.appSpecificData?.office365Calendar?.url ||
|
||||
"https://UNUSED_URL",
|
||||
});
|
||||
} else {
|
||||
return Promise.resolve({
|
||||
type: app.type,
|
||||
additionalInfo: {},
|
||||
uid: "PROBABLY_UNUSED_UID",
|
||||
iCalUID: normalizedCalendarData.update?.iCalUID,
|
||||
id: normalizedCalendarData.update?.uid || "FALLBACK_MOCK_ID",
|
||||
hangoutLink:
|
||||
(isGoogleMeetLocation
|
||||
? normalizedCalendarData.create?.appSpecificData?.googleCalendar?.hangoutLink
|
||||
: null) || "https://UNUSED_URL",
|
||||
// A Calendar is always expected to return an id.
|
||||
id: normalizedCalendarData.create?.id || "FALLBACK_MOCK_CALENDAR_EVENT_ID",
|
||||
iCalUID: normalizedCalendarData.create?.iCalUID,
|
||||
// Password and URL seems useless for CalendarService, plan to remove them if that's the case
|
||||
password: "MOCK_PASSWORD",
|
||||
url: "https://UNUSED_URL",
|
||||
location: isGoogleMeetLocation ? "https://UNUSED_URL" : undefined,
|
||||
hangoutLink:
|
||||
(isGoogleMeetLocation
|
||||
? normalizedCalendarData.update?.appSpecificData?.googleCalendar?.hangoutLink
|
||||
: null) || "https://UNUSED_URL",
|
||||
conferenceData: isGoogleMeetLocation ? event.conferenceData : undefined,
|
||||
});
|
||||
},
|
||||
deleteEvent: async (...rest: Parameters<Calendar["deleteEvent"]>) => {
|
||||
log.silly("mockCalendar.deleteEvent", JSON.stringify({ rest }));
|
||||
deleteEventCalls.push({
|
||||
args: {
|
||||
uid: rest[0],
|
||||
event: rest[1],
|
||||
externalCalendarId: rest[2],
|
||||
},
|
||||
calendarServiceConstructorArgs: {
|
||||
credential,
|
||||
},
|
||||
});
|
||||
},
|
||||
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");
|
||||
}
|
||||
getAvailabilityCalls.push({
|
||||
args: {
|
||||
dateFrom,
|
||||
dateTo,
|
||||
selectedCalendars,
|
||||
mode,
|
||||
},
|
||||
calendarServiceConstructorArgs: {
|
||||
credential,
|
||||
},
|
||||
});
|
||||
return new Promise((resolve) => {
|
||||
resolve(calendarData?.busySlots || []);
|
||||
});
|
||||
},
|
||||
listCalendars: async function (): Promise<IntegrationCalendar[]> {
|
||||
return Promise.resolve([]);
|
||||
},
|
||||
} as Calendar;
|
||||
}
|
||||
);
|
||||
}
|
||||
},
|
||||
updateEvent: async (...rest: Parameters<Calendar["updateEvent"]>): Promise<NewCalendarEventType> => {
|
||||
if (calendarData?.updationCrash) {
|
||||
throw new Error("MockCalendarService.updateEvent fake error");
|
||||
}
|
||||
const [uid, event, externalCalendarId] = rest;
|
||||
log.silly("mockCalendar.updateEvent", JSON.stringify({ uid, event, externalCalendarId }));
|
||||
updateEventCalls.push({
|
||||
args: {
|
||||
uid,
|
||||
event,
|
||||
externalCalendarId,
|
||||
},
|
||||
calendarServiceConstructorArgs: {
|
||||
credential,
|
||||
},
|
||||
});
|
||||
const isGoogleMeetLocation = event.location === BookingLocations.GoogleMeet;
|
||||
return Promise.resolve({
|
||||
type: app.type,
|
||||
additionalInfo: {},
|
||||
uid: "PROBABLY_UNUSED_UID",
|
||||
iCalUID: normalizedCalendarData.update?.iCalUID,
|
||||
id: normalizedCalendarData.update?.uid || "FALLBACK_MOCK_ID",
|
||||
// Password and URL seems useless for CalendarService, plan to remove them if that's the case
|
||||
password: "MOCK_PASSWORD",
|
||||
url: "https://UNUSED_URL",
|
||||
location: isGoogleMeetLocation ? "https://UNUSED_URL" : undefined,
|
||||
hangoutLink:
|
||||
(isGoogleMeetLocation
|
||||
? normalizedCalendarData.update?.appSpecificData?.googleCalendar?.hangoutLink
|
||||
: null) || "https://UNUSED_URL",
|
||||
conferenceData: isGoogleMeetLocation ? event.conferenceData : undefined,
|
||||
});
|
||||
},
|
||||
deleteEvent: async (...rest: Parameters<Calendar["deleteEvent"]>) => {
|
||||
log.silly("mockCalendar.deleteEvent", JSON.stringify({ rest }));
|
||||
deleteEventCalls.push({
|
||||
args: {
|
||||
uid: rest[0],
|
||||
event: rest[1],
|
||||
externalCalendarId: rest[2],
|
||||
},
|
||||
calendarServiceConstructorArgs: {
|
||||
credential,
|
||||
},
|
||||
});
|
||||
},
|
||||
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");
|
||||
}
|
||||
getAvailabilityCalls.push({
|
||||
args: {
|
||||
dateFrom,
|
||||
dateTo,
|
||||
selectedCalendars,
|
||||
mode,
|
||||
},
|
||||
calendarServiceConstructorArgs: {
|
||||
credential,
|
||||
},
|
||||
});
|
||||
return new Promise((resolve) => {
|
||||
resolve(calendarData?.busySlots || []);
|
||||
});
|
||||
},
|
||||
listCalendars: async (): Promise<IntegrationCalendar[]> => Promise.resolve([]),
|
||||
} as Calendar;
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { createMocks } from "node-mocks-http";
|
||||
|
||||
import type { CustomNextApiRequest, CustomNextApiResponse } from "./types";
|
||||
|
||||
export function createMockNextJsRequest(...args: Parameters<typeof createMocks>) {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import prismaMock from "../__mocks__/prisma";
|
||||
|
||||
import type { InputEventType, getOrganizer, CalendarServiceMethodMock } from "./bookingScenario";
|
||||
|
||||
import type { CalendarServiceMethodMock, getOrganizer, InputEventType } from "./bookingScenario";
|
||||
import { parse } from "node-html-parser";
|
||||
import type { VEvent } from "node-ical";
|
||||
import ical from "node-ical";
|
||||
@@ -9,22 +7,20 @@ import { expect, vi } from "vitest";
|
||||
import "vitest-fetch-mock";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import type { Tracking } from "../types";
|
||||
import { WEBSITE_URL } from "@calcom/lib/constants";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import type {
|
||||
WebhookTriggerEvents,
|
||||
Booking,
|
||||
BookingReference,
|
||||
DestinationCalendar,
|
||||
WebhookTriggerEvents,
|
||||
} from "@calcom/prisma/client";
|
||||
import { BookingStatus } from "@calcom/prisma/enums";
|
||||
import type { AppsStatus } from "@calcom/types/Calendar";
|
||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
import type { AppsStatus, CalendarEvent } from "@calcom/types/Calendar";
|
||||
import type { CredentialForCalendarService } from "@calcom/types/Credential";
|
||||
import type { Fixtures } from "../fixtures/fixtures";
|
||||
|
||||
import type { Tracking } from "../types";
|
||||
import { DEFAULT_TIMEZONE_BOOKER } from "./getMockRequestDataForBooking";
|
||||
|
||||
// This is too complex at the moment, I really need to simplify this.
|
||||
@@ -123,10 +119,9 @@ expect.extend({
|
||||
|
||||
let isToAddressExpected = true;
|
||||
const isIcsFilenameExpected = expectedEmail.ics ? ics?.filename === expectedEmail.ics.filename : true;
|
||||
const isIcsUIDExpected =
|
||||
expectedEmail.ics && expectedEmail.ics.iCalUID
|
||||
? !!(icsObject ? icsObject[expectedEmail.ics.iCalUID] : null)
|
||||
: true;
|
||||
const isIcsUIDExpected = expectedEmail.ics?.iCalUID
|
||||
? !!(icsObject ? icsObject[expectedEmail.ics.iCalUID] : null)
|
||||
: true;
|
||||
const emailDom = parse(testEmail.html);
|
||||
|
||||
const actualEmailContent = {
|
||||
@@ -1242,7 +1237,7 @@ export function expectSuccessfulCalendarEventCreationInCalendar(
|
||||
| ExpectedForSuccessfulCalendarEventCreationInCalendar
|
||||
| ExpectedForSuccessfulCalendarEventCreationInCalendar[]
|
||||
) {
|
||||
const expecteds = expected instanceof Array ? expected : [expected];
|
||||
const expecteds = Array.isArray(expected) ? expected : [expected];
|
||||
expect(calendarMock.createEventCalls.length).toBe(expecteds.length);
|
||||
|
||||
for (let i = 0; i < calendarMock.createEventCalls.length; i++) {
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { getDate } from "./bookingScenario";
|
||||
|
||||
import type { Tracking } from "../types";
|
||||
import type { SchedulingType } from "@calcom/prisma/client";
|
||||
import type { CreationSource } from "@calcom/prisma/enums";
|
||||
import type { Tracking } from "../types";
|
||||
|
||||
export const DEFAULT_TIMEZONE_BOOKER = "Asia/Kolkata";
|
||||
export function getBasicMockRequestDataForBooking() {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import type z from "zod";
|
||||
|
||||
import type { bookingCancelSchema } from "@calcom/prisma/zod-utils";
|
||||
import type z from "zod";
|
||||
|
||||
export function getMockRequestDataForCancelBooking(data: z.infer<typeof bookingCancelSchema>) {
|
||||
return data;
|
||||
|
||||
@@ -1,45 +1,43 @@
|
||||
import { IdentityProvider, UserPermissionRole } from "@calcom/prisma/enums";
|
||||
|
||||
export const getSampleUserInSession = function () {
|
||||
return {
|
||||
locale: "",
|
||||
avatar: "",
|
||||
organization: {
|
||||
isOrgAdmin: false,
|
||||
metadata: null,
|
||||
id: 1,
|
||||
requestedSlug: null,
|
||||
},
|
||||
profile: null,
|
||||
defaultScheduleId: null,
|
||||
name: "",
|
||||
defaultBookerLayouts: null,
|
||||
timeZone: "Asia/Kolkata",
|
||||
selectedCalendars: [],
|
||||
destinationCalendar: null,
|
||||
emailVerified: new Date(),
|
||||
allowDynamicBooking: false,
|
||||
bio: "",
|
||||
weekStart: "",
|
||||
startTime: 0,
|
||||
endTime: 0,
|
||||
bufferTime: 0,
|
||||
hideBranding: false,
|
||||
timeFormat: 12,
|
||||
twoFactorEnabled: false,
|
||||
identityProvider: IdentityProvider.CAL,
|
||||
brandColor: "#292929",
|
||||
darkBrandColor: "#fafafa",
|
||||
export const getSampleUserInSession = () => ({
|
||||
locale: "",
|
||||
avatar: "",
|
||||
organization: {
|
||||
isOrgAdmin: false,
|
||||
metadata: null,
|
||||
role: UserPermissionRole.USER,
|
||||
disableImpersonation: false,
|
||||
organizationId: null,
|
||||
theme: "",
|
||||
appTheme: "",
|
||||
createdDate: new Date(),
|
||||
trialEndsAt: new Date(),
|
||||
completedOnboarding: false,
|
||||
allowSEOIndexing: false,
|
||||
receiveMonthlyDigestEmail: false,
|
||||
};
|
||||
};
|
||||
id: 1,
|
||||
requestedSlug: null,
|
||||
},
|
||||
profile: null,
|
||||
defaultScheduleId: null,
|
||||
name: "",
|
||||
defaultBookerLayouts: null,
|
||||
timeZone: "Asia/Kolkata",
|
||||
selectedCalendars: [],
|
||||
destinationCalendar: null,
|
||||
emailVerified: new Date(),
|
||||
allowDynamicBooking: false,
|
||||
bio: "",
|
||||
weekStart: "",
|
||||
startTime: 0,
|
||||
endTime: 0,
|
||||
bufferTime: 0,
|
||||
hideBranding: false,
|
||||
timeFormat: 12,
|
||||
twoFactorEnabled: false,
|
||||
identityProvider: IdentityProvider.CAL,
|
||||
brandColor: "#292929",
|
||||
darkBrandColor: "#fafafa",
|
||||
metadata: null,
|
||||
role: UserPermissionRole.USER,
|
||||
disableImpersonation: false,
|
||||
organizationId: null,
|
||||
theme: "",
|
||||
appTheme: "",
|
||||
createdDate: new Date(),
|
||||
trialEndsAt: new Date(),
|
||||
completedOnboarding: false,
|
||||
allowSEOIndexing: false,
|
||||
receiveMonthlyDigestEmail: false,
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
import { enableEmailFeature, mockNoTranslations } from "./bookingScenario";
|
||||
|
||||
import { beforeEach, afterEach } from "vitest";
|
||||
import process from "node:process";
|
||||
import { afterEach, beforeEach } from "vitest";
|
||||
|
||||
export function setupAndTeardown() {
|
||||
beforeEach(() => {
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { createOrganization } from "./bookingScenario";
|
||||
|
||||
import { WEBSITE_URL } from "@calcom/lib/constants";
|
||||
import { test } from "../fixtures/fixtures";
|
||||
import type { Fixtures } from "../fixtures/fixtures";
|
||||
import { test } from "../fixtures/fixtures";
|
||||
|
||||
type OrgContext = {
|
||||
org: {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// my-test.ts
|
||||
import { test as base } from "vitest";
|
||||
|
||||
import { getTestEmails } from "@calcom/lib/testEmails";
|
||||
import { getTestSMS } from "@calcom/lib/testSMS";
|
||||
import { test as base } from "vitest";
|
||||
|
||||
export interface Fixtures {
|
||||
emails: ReturnType<typeof getEmailsFixture>;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import process from "node:process";
|
||||
import type { CalendarService } from "@calcom/types/Calendar";
|
||||
import matchers from "@testing-library/jest-dom/matchers";
|
||||
import ResizeObserver from "resize-observer-polyfill";
|
||||
import { vi, expect } from "vitest";
|
||||
import { expect, vi } from "vitest";
|
||||
import createFetchMock from "vitest-fetch-mock";
|
||||
|
||||
import type { CalendarService } from "@calcom/types/Calendar";
|
||||
|
||||
global.ResizeObserver = ResizeObserver;
|
||||
|
||||
if (typeof window !== "undefined") {
|
||||
@@ -32,7 +32,6 @@ fetchMocker.enableMocks();
|
||||
expect.extend(matchers);
|
||||
|
||||
class MockExchangeCalendarService implements CalendarService {
|
||||
constructor() {}
|
||||
async createEvent() {
|
||||
return {
|
||||
uid: "mock",
|
||||
@@ -181,7 +180,6 @@ vi.mock("@calcom/app-store/payment.services.generated", () => ({
|
||||
}));
|
||||
|
||||
class MockCrmService {
|
||||
constructor() {}
|
||||
async createEvent() {
|
||||
return [];
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user