Skip to content

Scheduling infrastructure for absolutely everyone.

fix: add missing vi.mock() calls to prevent vitest worker shutdown flakiness (#28459)

Romit4291a59b2cc8
diff --git a/apps/api/v1/lib/helpers/rateLimitApiKey.test.ts b/apps/api/v1/lib/helpers/rateLimitApiKey.test.ts
index cad5fcf6337..656f69a7baa 100644
--- a/apps/api/v1/lib/helpers/rateLimitApiKey.test.ts
+++ b/apps/api/v1/lib/helpers/rateLimitApiKey.test.ts
@@ -1,13 +1,11 @@
-import type { RatelimitResponse } from "@unkey/ratelimit";
-import type { Request, Response } from "express";
-import type { NextApiResponse, NextApiRequest } from "next";
-import { createMocks } from "node-mocks-http";
-import { describe, it, expect, vi } from "vitest";
-
import { handleAutoLock } from "@calcom/features/ee/api-keys/lib/autoLock";
import { checkRateLimitAndThrowError } from "@calcom/lib/checkRateLimitAndThrowError";
import { HttpError } from "@calcom/lib/http-error";
-
+import type { RatelimitResponse } from "@unkey/ratelimit";
+import type { Request, Response } from "express";
+import type { NextApiRequest, NextApiResponse } from "next";
+import { createMocks } from "node-mocks-http";
+import { describe, expect, it, vi } from "vitest";
import { rateLimitApiKey } from "~/lib/helpers/rateLimitApiKey";
type CustomNextApiRequest = NextApiRequest & Request;
@@ -23,6 +21,11 @@ vi.mock("@calcom/features/ee/api-keys/lib/autoLock", () => ({
handleAutoLock: vi.fn(),
}));
+vi.mock("@calcom/prisma", () => ({
+ default: {},
+ prisma: {},
+}));
+
describe("rateLimitApiKey middleware", () => {
it("should return 401 if no apiKey is provided", async () => {
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
diff --git a/apps/api/v1/test/lib/bookings/[id]/recordings/_get.test.ts b/apps/api/v1/test/lib/bookings/[id]/recordings/_get.test.ts
index cf18112f70d..6a9caae21f4 100644
--- a/apps/api/v1/test/lib/bookings/[id]/recordings/_get.test.ts
+++ b/apps/api/v1/test/lib/bookings/[id]/recordings/_get.test.ts
@@ -1,18 +1,14 @@
import prismaMock from "@calcom/testing/lib/__mocks__/prismaMock";
-
-import type { Request, Response } from "express";
-import type { NextApiRequest, NextApiResponse } from "next";
-import { createMocks } from "node-mocks-http";
-import { describe, expect, test, vi, afterEach } from "vitest";
-
import {
- getRecordingsOfCalVideoByRoomName,
getDownloadLinkOfCalVideoByRecordingId,
+ getRecordingsOfCalVideoByRoomName,
} from "@calcom/features/conferencing/lib/videoClient";
import { buildBooking } from "@calcom/lib/test/builder";
-
+import type { Request, Response } from "express";
+import type { NextApiRequest, NextApiResponse } from "next";
+import { createMocks } from "node-mocks-http";
+import { afterEach, describe, expect, test, vi } from "vitest";
import { getAccessibleUsers } from "~/lib/utils/retrieveScopedAccessibleUsers";
-
import authMiddleware from "../../../../../pages/api/bookings/[id]/_auth-middleware";
import handler from "../../../../../pages/api/bookings/[id]/recordings/_get";
@@ -34,7 +30,6 @@ vi.mock("~/lib/utils/retrieveScopedAccessibleUsers", () => {
getAccessibleUsers: vi.fn(),
};
});
-
afterEach(() => {
vi.resetAllMocks();
});
diff --git a/apps/api/v1/test/lib/bookings/[id]/transcripts/[recordingId]/_get.test.ts b/apps/api/v1/test/lib/bookings/[id]/transcripts/[recordingId]/_get.test.ts
index 7eab2398e56..8b5da8904ae 100644
--- a/apps/api/v1/test/lib/bookings/[id]/transcripts/[recordingId]/_get.test.ts
+++ b/apps/api/v1/test/lib/bookings/[id]/transcripts/[recordingId]/_get.test.ts
@@ -1,18 +1,14 @@
import prismaMock from "@calcom/testing/lib/__mocks__/prismaMock";
-
-import type { Request, Response } from "express";
-import type { NextApiRequest, NextApiResponse } from "next";
-import { createMocks } from "node-mocks-http";
-import { describe, expect, test, vi, afterEach } from "vitest";
-
import {
- getTranscriptsAccessLinkFromRecordingId,
checkIfRoomNameMatchesInRecording,
+ getTranscriptsAccessLinkFromRecordingId,
} from "@calcom/features/conferencing/lib/videoClient";
import { buildBooking } from "@calcom/lib/test/builder";
-
+import type { Request, Response } from "express";
+import type { NextApiRequest, NextApiResponse } from "next";
+import { createMocks } from "node-mocks-http";
+import { afterEach, describe, expect, test, vi } from "vitest";
import { getAccessibleUsers } from "~/lib/utils/retrieveScopedAccessibleUsers";
-
import authMiddleware from "../../../../../../pages/api/bookings/[id]/_auth-middleware";
import handler from "../../../../../../pages/api/bookings/[id]/transcripts/[recordingId]/_get";
@@ -31,7 +27,6 @@ vi.mock("~/lib/utils/retrieveScopedAccessibleUsers", () => {
getAccessibleUsers: vi.fn(),
};
});
-
afterEach(() => {
vi.resetAllMocks();
});
diff --git a/apps/api/v1/test/lib/bookings/[id]/transcripts/_get.test.ts b/apps/api/v1/test/lib/bookings/[id]/transcripts/_get.test.ts
index e632b59d9e9..69b780f9c98 100644
--- a/apps/api/v1/test/lib/bookings/[id]/transcripts/_get.test.ts
+++ b/apps/api/v1/test/lib/bookings/[id]/transcripts/_get.test.ts
@@ -1,15 +1,11 @@
import prismaMock from "@calcom/testing/lib/__mocks__/prismaMock";
-
+import { getAllTranscriptsAccessLinkFromRoomName } from "@calcom/features/conferencing/lib/videoClient";
+import { buildBooking } from "@calcom/lib/test/builder";
import type { Request, Response } from "express";
import type { NextApiRequest, NextApiResponse } from "next";
import { createMocks } from "node-mocks-http";
-import { describe, expect, test, vi, afterEach } from "vitest";
-
-import { getAllTranscriptsAccessLinkFromRoomName } from "@calcom/features/conferencing/lib/videoClient";
-import { buildBooking } from "@calcom/lib/test/builder";
-
+import { afterEach, describe, expect, test, vi } from "vitest";
import { getAccessibleUsers } from "~/lib/utils/retrieveScopedAccessibleUsers";
-
import authMiddleware from "../../../../../pages/api/bookings/[id]/_auth-middleware";
import handler from "../../../../../pages/api/bookings/[id]/transcripts/_get";
@@ -27,7 +23,6 @@ vi.mock("~/lib/utils/retrieveScopedAccessibleUsers", () => {
getAccessibleUsers: vi.fn(),
};
});
-
afterEach(() => {
vi.resetAllMocks();
});
diff --git a/apps/api/v1/test/lib/bookings/_post.test.ts b/apps/api/v1/test/lib/bookings/_post.test.ts
index b22756bda44..224d11a4501 100644
--- a/apps/api/v1/test/lib/bookings/_post.test.ts
+++ b/apps/api/v1/test/lib/bookings/_post.test.ts
@@ -1,25 +1,62 @@
import prismaMock from "@calcom/testing/lib/__mocks__/prismaMock";
-
-import type { Request, Response } from "express";
-import type { NextApiRequest, NextApiResponse } from "next";
-import { createMocks } from "node-mocks-http";
-import { describe, expect, test, vi, beforeEach } from "vitest";
-
import dayjs from "@calcom/dayjs";
import { getEventTypesFromDB } from "@calcom/features/bookings/lib/handleNewBooking/getEventTypesFromDB";
import sendPayload from "@calcom/features/webhooks/lib/sendOrSchedulePayload";
import { ErrorCode } from "@calcom/lib/errorCodes";
-import { buildBooking, buildEventType, buildWebhook, buildUser } from "@calcom/lib/test/builder";
+import { buildBooking, buildEventType, buildUser, buildWebhook } from "@calcom/lib/test/builder";
import { prisma } from "@calcom/prisma";
import type { Booking } from "@calcom/prisma/client";
-import { CreationSource, BookingStatus } from "@calcom/prisma/enums";
-
+import { BookingStatus, CreationSource } from "@calcom/prisma/enums";
+import type { Request, Response } from "express";
+import type { NextApiRequest, NextApiResponse } from "next";
+import { createMocks } from "node-mocks-http";
+import { beforeEach, describe, expect, test, vi } from "vitest";
import handler from "../../../pages/api/bookings/_post";
vi.mock("@calcom/features/bookings/lib/handleNewBooking/getEventTypesFromDB", () => ({
getEventTypesFromDB: vi.fn(),
}));
+vi.mock("@calcom/app-store/delegationCredential", () => ({
+ enrichHostsWithDelegationCredentials: vi.fn().mockImplementation(({ hosts }) => hosts),
+ enrichUsersWithDelegationCredentials: vi.fn().mockImplementation(({ users }) => users),
+ enrichUserWithDelegationCredentialsIncludeServiceAccountKey: vi.fn().mockImplementation(({ user }) => user),
+ enrichUserWithDelegationCredentials: vi.fn().mockImplementation(({ user }) => user),
+ enrichUserWithDelegationConferencingCredentialsWithoutOrgId: vi.fn().mockImplementation(({ user }) => user),
+ getUsersCredentialsIncludeServiceAccountKey: vi.fn().mockResolvedValue([]),
+ getUsersCredentials: vi.fn().mockResolvedValue([]),
+ getCredentialForSelectedCalendar: vi.fn(),
+ getAllDelegationCredentialsForUserIncludeServiceAccountKey: vi.fn().mockResolvedValue([]),
+ getAllDelegationCredentialsForUser: vi.fn().mockResolvedValue([]),
+ getAllDelegatedCalendarCredentialsForUser: vi.fn().mockResolvedValue([]),
+ getAllDelegationCredentialsForUserByAppType: vi.fn().mockResolvedValue([]),
+ getAllDelegationCredentialsForUserByAppSlug: vi.fn().mockResolvedValue([]),
+ buildAllCredentials: vi.fn().mockImplementation(({ existingCredentials }) => existingCredentials || []),
+ getDelegationCredentialOrFindRegularCredential: vi.fn(),
+ getDelegationCredentialOrRegularCredential: vi.fn(),
+ getFirstDelegationConferencingCredential: vi.fn(),
+ getFirstDelegationConferencingCredentialAppLocation: vi.fn(),
+ findUniqueDelegationCalendarCredential: vi.fn(),
+ assertSuccessfullyConfiguredInWorkspace: vi.fn(),
+}));
+
+vi.mock("@calcom/features/calendars/lib/CalendarManager", () => ({
+ createEvent: vi.fn(),
+ updateEvent: vi.fn(),
+ deleteEvent: vi.fn(),
+ getBusyCalendarTimes: vi.fn(),
+}));
+
+vi.mock("@calcom/features/auth/lib/verifyEmail", () => ({
+ checkIfEmailIsBlockedInWatchlist: vi.fn(),
+ isEmailVerified: vi.fn(),
+}));
+
+vi.mock("@calcom/lib/domainManager/organization", () => ({
+ getOrgDomainConfigFromHostname: vi.fn(),
+ subdomainSuffix: vi.fn(),
+}));
+
const mockEventTypeData = {
eventType: {
id: 1,
@@ -66,9 +103,11 @@ vi.mock("@calcom/features/webhooks/lib/sendOrSchedulePayload", () => ({
const mockFindOriginalRescheduledBooking = vi.fn();
vi.mock("@calcom/features/bookings/repositories/BookingRepository", () => ({
- BookingRepository: vi.fn().mockImplementation(function() { return {
- findOriginalRescheduledBooking: mockFindOriginalRescheduledBooking,
- }; }),
+ BookingRepository: vi.fn().mockImplementation(function () {
+ return {
+ findOriginalRescheduledBooking: mockFindOriginalRescheduledBooking,
+ };
+ }),
}));
vi.mock("@calcom/features/watchlist/operations/check-if-users-are-blocked.controller", () => ({
@@ -93,7 +132,7 @@ vi.mock("@calcom/features/di/containers/QualifiedHosts", () => ({
}));
vi.mock("@calcom/features/bookings/lib/EventManager", () => ({
- default: vi.fn().mockImplementation(function() {
+ default: vi.fn().mockImplementation(function () {
return {
reschedule: vi.fn().mockResolvedValue({
results: [],
@@ -154,10 +193,12 @@ vi.mock("@calcom/features/profile/repositories/ProfileRepository", () => ({
},
}));
vi.mock("@calcom/features/flags/features.repository", () => ({
- FeaturesRepository: vi.fn().mockImplementation(function() { return {
- checkIfFeatureIsEnabledGlobally: vi.fn().mockResolvedValue(false),
- checkIfTeamHasFeature: vi.fn().mockResolvedValue(false),
- }; }),
+ FeaturesRepository: vi.fn().mockImplementation(function () {
+ return {
+ checkIfFeatureIsEnabledGlobally: vi.fn().mockResolvedValue(false),
+ checkIfTeamHasFeature: vi.fn().mockResolvedValue(false),
+ };
+ }),
}));
vi.mock("@calcom/features/webhooks/lib/getWebhooks", () => ({
diff --git a/apps/api/v1/test/lib/utils/isLockedOrBlocked.test.ts b/apps/api/v1/test/lib/utils/isLockedOrBlocked.test.ts
index 935073d6529..5b7549be7b2 100644
--- a/apps/api/v1/test/lib/utils/isLockedOrBlocked.test.ts
+++ b/apps/api/v1/test/lib/utils/isLockedOrBlocked.test.ts
@@ -1,15 +1,23 @@
-import type { NextApiRequest } from "next";
-import { describe, expect, it, beforeEach, vi, afterEach } from "vitest";
-
import { getWatchlistFeature } from "@calcom/features/di/watchlist/containers/watchlist";
import type { WatchlistFeature } from "@calcom/features/watchlist/lib/facade/WatchlistFeature";
-
+import type { NextApiRequest } from "next";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { isLockedOrBlocked } from "../../../lib/utils/isLockedOrBlocked";
vi.mock("@calcom/features/di/watchlist/containers/watchlist", () => ({
getWatchlistFeature: vi.fn(),
}));
+vi.mock("@calcom/features/auth/lib/verifyEmail", () => ({
+ sendEmailVerification: vi.fn(),
+ verifyEmail: vi.fn(),
+}));
+
+vi.mock("@calcom/prisma", () => ({
+ default: {},
+ prisma: {},
+}));
+
describe("isLockedOrBlocked", () => {
let mockWatchlistFeature: WatchlistFeature;
diff --git a/apps/web/app/(use-page-wrapper)/settings/(settings-layout)/organizations/actions/validateUserHasOrg.test.ts b/apps/web/app/(use-page-wrapper)/settings/(settings-layout)/organizations/actions/validateUserHasOrg.test.ts
index 2fc5361f77f..0ade018b00c 100644
--- a/apps/web/app/(use-page-wrapper)/settings/(settings-layout)/organizations/actions/validateUserHasOrg.test.ts
+++ b/apps/web/app/(use-page-wrapper)/settings/(settings-layout)/organizations/actions/validateUserHasOrg.test.ts
@@ -1,11 +1,9 @@
-import type { Session } from "next-auth";
-import { redirect } from "next/navigation";
-import { describe, it, vi, expect, beforeEach, type MockedFunction } from "vitest";
-
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
import { MembershipRole } from "@calcom/prisma/enums";
-
-import { validateUserHasOrg, type ValidatedOrgSession } from "./validateUserHasOrg";
+import { redirect } from "next/navigation";
+import type { Session } from "next-auth";
+import { beforeEach, describe, expect, it, type MockedFunction, vi } from "vitest";
+import { type ValidatedOrgSession, validateUserHasOrg } from "./validateUserHasOrg";
// Mock the dependencies
vi.mock("next/navigation", () => ({
@@ -25,6 +23,11 @@ vi.mock("@lib/buildLegacyCtx", () => ({
buildLegacyRequest: vi.fn(() => ({})),
}));
+vi.mock("@calcom/prisma", () => ({
+ default: {},
+ prisma: {},
+}));
+
const mockedGetServerSession = getServerSession as MockedFunction<typeof getServerSession>;
const mockedRedirect = vi.mocked(redirect);
diff --git a/apps/web/app/(use-page-wrapper)/settings/(settings-layout)/organizations/actions/validateUserHasOrgAdmin.test.ts b/apps/web/app/(use-page-wrapper)/settings/(settings-layout)/organizations/actions/validateUserHasOrgAdmin.test.ts
index 65e523ff037..4b445919145 100644
--- a/apps/web/app/(use-page-wrapper)/settings/(settings-layout)/organizations/actions/validateUserHasOrgAdmin.test.ts
+++ b/apps/web/app/(use-page-wrapper)/settings/(settings-layout)/organizations/actions/validateUserHasOrgAdmin.test.ts
@@ -1,12 +1,10 @@
-import type { Session } from "next-auth";
-import { redirect } from "next/navigation";
-import { describe, it, vi, expect, beforeEach, type MockedFunction } from "vitest";
-
import { checkAdminOrOwner } from "@calcom/features/auth/lib/checkAdminOrOwner";
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
import { MembershipRole } from "@calcom/prisma/enums";
-
-import { validateUserHasOrgAdmin, type ValidatedOrgAdminSession } from "./validateUserHasOrgAdmin";
+import { redirect } from "next/navigation";
+import type { Session } from "next-auth";
+import { beforeEach, describe, expect, it, type MockedFunction, vi } from "vitest";
+import { type ValidatedOrgAdminSession, validateUserHasOrgAdmin } from "./validateUserHasOrgAdmin";
// Mock the dependencies
vi.mock("next/navigation", () => ({
@@ -30,6 +28,11 @@ vi.mock("@lib/buildLegacyCtx", () => ({
buildLegacyRequest: vi.fn(() => ({})),
}));
+vi.mock("@calcom/prisma", () => ({
+ default: {},
+ prisma: {},
+}));
+
const mockedGetServerSession = getServerSession as MockedFunction<typeof getServerSession>;
const mockedCheckAdminOrOwner = vi.mocked(checkAdminOrOwner);
const mockedRedirect = vi.mocked(redirect);
diff --git a/apps/web/app/api/routing-forms/queued-response/__tests__/queued-response.test.ts b/apps/web/app/api/routing-forms/queued-response/__tests__/queued-response.test.ts
index 613e9e99bab..11c092858c9 100644
--- a/apps/web/app/api/routing-forms/queued-response/__tests__/queued-response.test.ts
+++ b/apps/web/app/api/routing-forms/queued-response/__tests__/queued-response.test.ts
@@ -1,11 +1,9 @@
import "@calcom/testing/lib/__mocks__/prisma";
-import { beforeEach, describe, it, expect, vi } from "vitest";
-
import { onSubmissionOfFormResponse } from "@calcom/app-store/routing-forms/lib/formSubmissionUtils";
import { getResponseToStore } from "@calcom/app-store/routing-forms/lib/getResponseToStore";
import { getSerializableForm } from "@calcom/app-store/routing-forms/lib/getSerializableForm";
import { RoutingFormResponseRepository } from "@calcom/features/routing-forms/repositories/RoutingFormResponseRepository";
-
+import { beforeEach, describe, expect, it, vi } from "vitest";
import { queuedResponseHandler } from "../route";
vi.mock("@calcom/features/routing-forms/repositories/RoutingFormResponseRepository");
@@ -17,7 +15,6 @@ const mockRoutingFormResponseRepository = {
vi.mock("@calcom/app-store/routing-forms/lib/getSerializableForm");
vi.mock("@calcom/app-store/routing-forms/lib/getResponseToStore");
vi.mock("@calcom/app-store/routing-forms/lib/formSubmissionUtils");
-
const mockQueuedFormResponse = {
id: "1",
formId: "mock-form-id",
@@ -157,9 +154,9 @@ describe("queuedResponseHandler", () => {
vi.mocked(getResponseToStore).mockReturnValue({} as ReturnType<typeof getResponseToStore>);
- vi.mocked(onSubmissionOfFormResponse).mockResolvedValue(undefined as unknown as Awaited<
- ReturnType<typeof onSubmissionOfFormResponse>
- >);
+ vi.mocked(onSubmissionOfFormResponse).mockResolvedValue(
+ undefined as unknown as Awaited<ReturnType<typeof onSubmissionOfFormResponse>>
+ );
vi.mocked(mockRoutingFormResponseRepository.recordFormResponse).mockResolvedValue({
id: 1,
diff --git a/apps/web/app/api/video/recording/__tests__/route.test.ts b/apps/web/app/api/video/recording/__tests__/route.test.ts
index 5dfe1acbc22..e0ef1547d17 100644
--- a/apps/web/app/api/video/recording/__tests__/route.test.ts
+++ b/apps/web/app/api/video/recording/__tests__/route.test.ts
@@ -1,9 +1,7 @@
-import { NextResponse } from "next/server";
-import { describe, expect, test, vi, afterEach } from "vitest";
-
import { getDownloadLinkOfCalVideoByRecordingId } from "@calcom/features/conferencing/lib/videoClient";
import { verifyVideoToken } from "@calcom/lib/videoTokens";
-
+import { NextResponse } from "next/server";
+import { afterEach, describe, expect, test, vi } from "vitest";
import { GET } from "../route";
vi.mock("@calcom/features/conferencing/lib/videoClient", () => ({
@@ -14,6 +12,11 @@ vi.mock("@calcom/lib/videoTokens", () => ({
verifyVideoToken: vi.fn(),
}));
+vi.mock("@calcom/prisma", () => ({
+ default: {},
+ prisma: {},
+}));
+
describe("GET /api/video/recording", () => {
afterEach(() => {
vi.resetAllMocks();
diff --git a/apps/web/lib/daily-webhook/tests/recorded-daily-video.test.ts b/apps/web/lib/daily-webhook/tests/recorded-daily-video.test.ts
index 2bdc07a976b..e72ed07d29e 100644
--- a/apps/web/lib/daily-webhook/tests/recorded-daily-video.test.ts
+++ b/apps/web/lib/daily-webhook/tests/recorded-daily-video.test.ts
@@ -1,25 +1,23 @@
import {
createBookingScenario,
- getScenarioData,
- TestData,
+ getBooker,
getDate,
getMockBookingAttendee,
getOrganizer,
- getBooker,
+ getScenarioData,
+ TestData,
} from "@calcom/testing/lib/bookingScenario/bookingScenario";
-import { expectWebhookToHaveBeenCalledWith } from "@calcom/testing/lib/bookingScenario/expects";
-
-import { NextRequest } from "next/server";
-import { createMocks } from "node-mocks-http";
-import { describe, afterEach, test, vi, beforeEach, beforeAll, expect } from "vitest";
-
+import process from "node:process";
import { appStoreMetadata } from "@calcom/app-store/apps.metadata.generated";
-import { getRoomNameFromRecordingId, getBatchProcessorJobAccessLink } from "@calcom/app-store/dailyvideo/lib";
+import { getBatchProcessorJobAccessLink, getRoomNameFromRecordingId } from "@calcom/app-store/dailyvideo/lib";
import { WEBAPP_URL } from "@calcom/lib/constants";
import prisma from "@calcom/prisma";
-import { WebhookTriggerEvents } from "@calcom/prisma/enums";
-import { BookingStatus } from "@calcom/prisma/enums";
+import { BookingStatus, WebhookTriggerEvents } from "@calcom/prisma/enums";
+import { expectWebhookToHaveBeenCalledWith } from "@calcom/testing/lib/bookingScenario/expects";
import * as recordedDailyVideoRoute from "@calcom/web/app/api/recorded-daily-video/route";
+import { NextRequest } from "next/server";
+import { createMocks } from "node-mocks-http";
+import { afterEach, beforeAll, beforeEach, describe, expect, test, vi } from "vitest";
// Mock the next/headers module before importing the handler
vi.mock("next/headers", () => ({
@@ -81,7 +79,6 @@ vi.mock("app/api/defaultResponderForAppDir", () => {
defaultResponderForAppDir: vi.fn(),
};
});
-
const BATCH_PROCESSOR_JOB_FINSISHED_PAYLOAD = {
version: "1.1.0",
type: "batch-processor.job-finished",
diff --git a/apps/web/modules/event-types/components/tabs/advanced/FormBuilder.test.tsx b/apps/web/modules/event-types/components/tabs/advanced/FormBuilder.test.tsx
index 5c650736e29..b1503ffbe22 100644
--- a/apps/web/modules/event-types/components/tabs/advanced/FormBuilder.test.tsx
+++ b/apps/web/modules/event-types/components/tabs/advanced/FormBuilder.test.tsx
@@ -1,22 +1,20 @@
+import {
+ expectScenario,
+ getLocationBookingField,
+ mockProps as mockPropsBase,
+ pageObject,
+ setMockIntersectionObserver,
+ setMockMatchMedia,
+ verifier,
+} from "@calcom/features/form-builder/testUtils";
+import { showToast } from "@calcom/ui/components/toast";
import { TooltipProvider } from "@radix-ui/react-tooltip";
import { render, screen, waitFor } from "@testing-library/react";
import type { ReactNode } from "react";
import * as React from "react";
import { FormProvider, useForm } from "react-hook-form";
import { vi } from "vitest";
-
-import { showToast } from "@calcom/ui/components/toast";
-
import { FormBuilder } from "./FormBuilder";
-import {
- mockProps as mockPropsBase,
- verifier,
- setMockIntersectionObserver,
- setMockMatchMedia,
- pageObject,
- expectScenario,
- getLocationBookingField,
-} from "@calcom/features/form-builder/testUtils";
// Re-type mockProps to ensure LockedIcon is typed as `false` instead of `boolean`
const mockProps = { ...mockPropsBase, LockedIcon: false as const };
@@ -41,9 +39,14 @@ vi.mock("@calcom/ui/components/toast", () => ({
showToast: vi.fn(),
}));
+vi.mock("@calcom/prisma", () => ({
+ default: {},
+ prisma: {},
+}));
+
const renderComponent = ({
- formBuilderProps: formBuilderProps,
- formDefaultValues: formDefaultValues,
+ formBuilderProps,
+ formDefaultValues,
}: {
formBuilderProps: Parameters<typeof FormBuilder>[0];
formDefaultValues: { [x: string]: {} | undefined };
diff --git a/apps/web/test/lib/checkBookingLimits.test.ts b/apps/web/test/lib/checkBookingLimits.test.ts
index e748973cd17..e4fbe1735e4 100644
--- a/apps/web/test/lib/checkBookingLimits.test.ts
+++ b/apps/web/test/lib/checkBookingLimits.test.ts
@@ -1,9 +1,8 @@
-import { describe, expect, it, vi } from "vitest";
-
import dayjs from "@calcom/dayjs";
import { getCheckBookingLimitsService } from "@calcom/features/di/containers/BookingLimits";
import type { IntervalLimit } from "@calcom/lib/intervalLimits/intervalLimitSchema";
import { validateIntervalLimitOrder } from "@calcom/lib/intervalLimits/validateIntervalLimitOrder";
+import { describe, expect, it, vi } from "vitest";
const mockCountBookingsByEventTypeAndDateRange = vi.fn();
vi.mock("@calcom/features/bookings/repositories/BookingRepository", () => ({
@@ -14,6 +13,11 @@ vi.mock("@calcom/features/bookings/repositories/BookingRepository", () => ({
}),
}));
+vi.mock("@calcom/prisma", () => ({
+ default: {},
+ prisma: {},
+}));
+
type Mockdata = {
id: number;
startDate: Date;
diff --git a/apps/web/test/lib/checkDurationLimits.test.ts b/apps/web/test/lib/checkDurationLimits.test.ts
index 2625626e6a0..b8594d03666 100644
--- a/apps/web/test/lib/checkDurationLimits.test.ts
+++ b/apps/web/test/lib/checkDurationLimits.test.ts
@@ -1,8 +1,7 @@
-import { describe, expect, it, vi } from "vitest";
-
import dayjs from "@calcom/dayjs";
import { checkDurationLimit, checkDurationLimits } from "@calcom/features/bookings/lib/checkDurationLimits";
import { validateIntervalLimitOrder } from "@calcom/lib/intervalLimits/validateIntervalLimitOrder";
+import { describe, expect, it, vi } from "vitest";
const mockGetTotalBookingDuration = vi.fn();
vi.mock("@calcom/features/bookings/repositories/BookingRepository", () => ({
@@ -13,6 +12,11 @@ vi.mock("@calcom/features/bookings/repositories/BookingRepository", () => ({
}),
}));
+vi.mock("@calcom/prisma", () => ({
+ default: {},
+ prisma: {},
+}));
+
type MockData = {
id: number;
startDate: Date;
diff --git a/apps/web/test/lib/confirm.handler.test.ts b/apps/web/test/lib/confirm.handler.test.ts
index fc2ea6723a9..2d5f8c927d5 100644
--- a/apps/web/test/lib/confirm.handler.test.ts
+++ b/apps/web/test/lib/confirm.handler.test.ts
@@ -2,19 +2,61 @@ import {
createBookingScenario,
getOrganizer,
getScenarioData,
- TestData,
mockSuccessfulVideoMeetingCreation,
+ TestData,
} from "@calcom/testing/lib/bookingScenario/bookingScenario";
-
-import { describe, it, beforeEach, vi, expect } from "vitest";
-
+import { makeUserActor } from "@calcom/features/booking-audit/lib/makeActor";
+import { getBookingEventHandlerService } from "@calcom/features/bookings/di/BookingEventHandlerService.container";
import * as handleConfirmationModule from "@calcom/features/bookings/lib/handleConfirmation";
import { distributedTracing } from "@calcom/lib/tracing/factory";
import { BookingStatus } from "@calcom/prisma/enums";
import { confirmHandler } from "@calcom/trpc/server/routers/viewer/bookings/confirm.handler";
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
-import { makeUserActor } from "@calcom/features/booking-audit/lib/makeActor";
-import { getBookingEventHandlerService } from "@calcom/features/bookings/di/BookingEventHandlerService.container";
+import { beforeEach, describe, expect, it, vi } from "vitest";
+
+vi.mock("@calcom/app-store/delegationCredential", () => ({
+ enrichHostsWithDelegationCredentials: vi.fn().mockImplementation(({ hosts }) => hosts),
+ enrichUsersWithDelegationCredentials: vi.fn().mockImplementation(({ users }) => users),
+ enrichUserWithDelegationCredentialsIncludeServiceAccountKey: vi.fn().mockImplementation(({ user }) => user),
+ enrichUserWithDelegationCredentials: vi.fn().mockImplementation(({ user }) => user),
+ enrichUserWithDelegationConferencingCredentialsWithoutOrgId: vi.fn().mockImplementation(({ user }) => user),
+ getUsersCredentialsIncludeServiceAccountKey: vi.fn().mockResolvedValue([]),
+ getUsersCredentials: vi.fn().mockResolvedValue([]),
+ getCredentialForSelectedCalendar: vi.fn(),
+ getAllDelegationCredentialsForUserIncludeServiceAccountKey: vi.fn().mockResolvedValue([]),
+ getAllDelegationCredentialsForUser: vi.fn().mockResolvedValue([]),
+ getAllDelegatedCalendarCredentialsForUser: vi.fn().mockResolvedValue([]),
+ getAllDelegationCredentialsForUserByAppType: vi.fn().mockResolvedValue([]),
+ getAllDelegationCredentialsForUserByAppSlug: vi.fn().mockResolvedValue([]),
+ buildAllCredentials: vi.fn().mockImplementation(({ existingCredentials }) => existingCredentials || []),
+ getDelegationCredentialOrFindRegularCredential: vi.fn(),
+ getDelegationCredentialOrRegularCredential: vi.fn(),
+ getFirstDelegationConferencingCredential: vi.fn(),
+ getFirstDelegationConferencingCredentialAppLocation: vi.fn(),
+ findUniqueDelegationCalendarCredential: vi.fn(),
+ assertSuccessfullyConfiguredInWorkspace: vi.fn(),
+}));
+
+vi.mock("@calcom/features/calendars/lib/CalendarManager", () => ({
+ createEvent: vi.fn(),
+ updateEvent: vi.fn(),
+ deleteEvent: vi.fn(),
+ getBusyCalendarTimes: vi.fn(),
+}));
+
+vi.mock("@calcom/features/auth/lib/verifyEmail", () => ({
+ checkIfEmailIsBlockedInWatchlist: vi.fn(),
+ isEmailVerified: vi.fn(),
+}));
+
+vi.mock("@calcom/lib/domainManager/organization", () => ({
+ getOrgDomainConfigFromHostname: vi.fn(),
+ subdomainSuffix: vi.fn(),
+}));
+
+vi.mock("@calcom/emails/organization-email-service", () => ({
+ OrganizationEmailService: vi.fn(),
+}));
vi.mock("@calcom/features/bookings/di/BookingEventHandlerService.container", () => {
const onBookingAccepted = vi.fn().mockResolvedValue(undefined);
diff --git a/apps/web/test/lib/handleChildrenEventTypes.test.ts b/apps/web/test/lib/handleChildrenEventTypes.test.ts
index f519bbb911a..ea7e9b3c2cb 100644
--- a/apps/web/test/lib/handleChildrenEventTypes.test.ts
+++ b/apps/web/test/lib/handleChildrenEventTypes.test.ts
@@ -57,7 +57,6 @@ vi.mock("@calcom/i18n/server", () => {
},
};
});
-
describe("handleChildrenEventTypes", () => {
describe("Shortcircuits", () => {
it("Returns message 'No managed event type'", async () => {
diff --git a/packages/app-store/_utils/payments/handlePaymentSuccess.test.ts b/packages/app-store/_utils/payments/handlePaymentSuccess.test.ts
index c7af2e04ffd..69b7a1b5902 100644
--- a/packages/app-store/_utils/payments/handlePaymentSuccess.test.ts
+++ b/packages/app-store/_utils/payments/handlePaymentSuccess.test.ts
@@ -1,8 +1,9 @@
/**
* @vitest-environment node
*/
-import { describe, it, expect, vi, beforeEach } from "vitest";
+
import { BookingStatus, WebhookTriggerEvents, WorkflowTriggerEvents } from "@calcom/prisma/enums";
+import { beforeEach, describe, expect, it, vi } from "vitest";
import { handlePaymentSuccess } from "./handlePaymentSuccess";
// Mock dependencies
@@ -71,19 +72,39 @@ vi.mock("@calcom/app-store/routing-forms/lib/findFieldValueByIdentifier", () =>
findFieldValueByIdentifier: vi.fn(),
}));
+vi.mock("@calcom/app-store/_utils/getCalendar", () => ({
+ getCalendar: vi.fn().mockReturnValue(null),
+}));
+
+vi.mock("@calcom/app-store/delegationCredential", () => ({
+ enrichHostsWithDelegationCredentials: vi.fn(),
+ getUsersCredentialsIncludeServiceAccountKey: vi.fn(),
+ getCredentialForSelectedCalendar: vi.fn(),
+ findUniqueDelegationCalendarCredential: vi.fn(),
+ getAllDelegationCredentialsForUserIncludeServiceAccountKey: vi.fn(),
+ getDelegationCredentialOrFindRegularCredential: vi.fn(),
+}));
+
+vi.mock("@calcom/features/calendars/lib/CalendarManager", () => ({
+ getBusyCalendarTimes: vi.fn().mockResolvedValue([]),
+ createEvent: vi.fn().mockResolvedValue({}),
+ updateEvent: vi.fn().mockResolvedValue({}),
+ deleteEvent: vi.fn().mockResolvedValue({}),
+}));
+
import { getBooking } from "@calcom/features/bookings/lib/payment/getBooking";
-import getWebhooks from "@calcom/features/webhooks/lib/getWebhooks";
-import sendPayload from "@calcom/features/webhooks/lib/sendOrSchedulePayload";
+import { CreditService } from "@calcom/features/ee/billing/credit-service";
+import { getBookerBaseUrl } from "@calcom/features/ee/organizations/lib/getBookerUrlServer";
import { getAllWorkflowsFromEventType } from "@calcom/features/ee/workflows/lib/getAllWorkflowsFromEventType";
import { WorkflowService } from "@calcom/features/ee/workflows/lib/service/WorkflowService";
-import prisma from "@calcom/prisma";
+import getWebhooks from "@calcom/features/webhooks/lib/getWebhooks";
+import { WebhookVersion } from "@calcom/features/webhooks/lib/interface/IWebhookRepository";
+import sendPayload from "@calcom/features/webhooks/lib/sendOrSchedulePayload";
+import { getVideoCallUrlFromCalEvent } from "@calcom/lib/CalEventParser";
import getOrgIdFromMemberOrTeamId from "@calcom/lib/getOrgIdFromMemberOrTeamId";
-import { getBookerBaseUrl } from "@calcom/features/ee/organizations/lib/getBookerUrlServer";
import { getTeamIdFromEventType } from "@calcom/lib/getTeamIdFromEventType";
-import { getVideoCallUrlFromCalEvent } from "@calcom/lib/CalEventParser";
-import { CreditService } from "@calcom/features/ee/billing/credit-service";
import type { TraceContext } from "@calcom/lib/tracing";
-import { WebhookVersion } from "@calcom/features/webhooks/lib/interface/IWebhookRepository";
+import prisma from "@calcom/prisma";
describe("handlePaymentSuccess", () => {
const mockBookingId = 1;
diff --git a/packages/app-store/closecom/test/lib/CalendarService.test.ts b/packages/app-store/closecom/test/lib/CalendarService.test.ts
index 9425d9f9b05..4e29235bd89 100644
--- a/packages/app-store/closecom/test/lib/CalendarService.test.ts
+++ b/packages/app-store/closecom/test/lib/CalendarService.test.ts
@@ -1,14 +1,14 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
-import { expect, vi, afterEach, test } from "vitest";
import CloseCom from "@calcom/lib/CloseCom";
import {
getCloseComContactIds,
- getCustomActivityTypeInstanceData,
getCloseComCustomActivityTypeFieldsIds,
getCloseComLeadId,
+ getCustomActivityTypeInstanceData,
} from "@calcom/lib/CloseComeUtils";
import type { CalendarEvent } from "@calcom/types/Calendar";
+import { afterEach, expect, test, vi } from "vitest";
vi.mock("@calcom/lib/CloseCom", () => ({
default: class {
@@ -18,6 +18,11 @@ vi.mock("@calcom/lib/CloseCom", () => ({
},
}));
+vi.mock("@calcom/prisma", () => ({
+ default: {},
+ prisma: {},
+}));
+
afterEach(() => {
vi.resetAllMocks();
});
diff --git a/packages/features/CalendarEventBuilder.test.ts b/packages/features/CalendarEventBuilder.test.ts
index 66269005156..8b71336eed3 100644
--- a/packages/features/CalendarEventBuilder.test.ts
+++ b/packages/features/CalendarEventBuilder.test.ts
@@ -1,10 +1,9 @@
-import type { TFunction } from "i18next";
-import { describe, expect, it, vi } from "vitest";
-
import dayjs from "@calcom/dayjs";
-import { BookingForCalEventBuilder, CalendarEventBuilder } from "@calcom/features/CalendarEventBuilder";
+import { type BookingForCalEventBuilder, CalendarEventBuilder } from "@calcom/features/CalendarEventBuilder";
import { TimeFormat } from "@calcom/lib/timeFormat";
import type { Person } from "@calcom/types/Calendar";
+import type { TFunction } from "i18next";
+import { describe, expect, it, vi } from "vitest";
vi.mock("@calcom/features/ee/organizations/lib/getBookerUrlServer", () => ({
getBookerBaseUrl: vi.fn(async () => "https://cal.com"),
@@ -24,6 +23,11 @@ vi.mock("@calcom/features/bookings/lib/getCalEventResponses", () => ({
})),
}));
+vi.mock("@calcom/prisma", () => ({
+ default: {},
+ prisma: {},
+}));
+
describe("CalendarEventBuilder", () => {
const mockTranslate = vi.fn(() => "foo") as TFunction;
const mockStartTime = dayjs().add(1, "day").format();
diff --git a/packages/features/booking-audit/lib/service/__tests__/BookingAuditAccessService.test.ts b/packages/features/booking-audit/lib/service/__tests__/BookingAuditAccessService.test.ts
index 1c3c465f08e..ba0e67d9593 100644
--- a/packages/features/booking-audit/lib/service/__tests__/BookingAuditAccessService.test.ts
+++ b/packages/features/booking-audit/lib/service/__tests__/BookingAuditAccessService.test.ts
@@ -1,10 +1,8 @@
-import { describe, it, expect, beforeEach, vi, type Mock } from "vitest";
-
-import { PermissionCheckService } from "@calcom/features/pbac/services/permission-check.service";
import { BookingRepository } from "@calcom/features/bookings/repositories/BookingRepository";
import { MembershipRepository } from "@calcom/features/membership/repositories/MembershipRepository";
+import { PermissionCheckService } from "@calcom/features/pbac/services/permission-check.service";
import { MembershipRole } from "@calcom/prisma/enums";
-
+import { beforeEach, describe, expect, it, type Mock, vi } from "vitest";
import {
BookingAuditAccessService,
BookingAuditErrorCode,
@@ -14,6 +12,11 @@ import {
vi.mock("@calcom/features/pbac/services/permission-check.service");
vi.mock("@calcom/features/bookings/repositories/BookingRepository");
vi.mock("@calcom/features/membership/repositories/MembershipRepository");
+
+vi.mock("@calcom/prisma", () => ({
+ default: {},
+ prisma: {},
+}));
const DB = {
bookings: {} as Record<
string,
diff --git a/packages/features/booking-audit/lib/service/__tests__/BookingAuditViewerService.test.ts b/packages/features/booking-audit/lib/service/__tests__/BookingAuditViewerService.test.ts
index 8879e7a76df..559b3e299c2 100644
--- a/packages/features/booking-audit/lib/service/__tests__/BookingAuditViewerService.test.ts
+++ b/packages/features/booking-audit/lib/service/__tests__/BookingAuditViewerService.test.ts
@@ -23,6 +23,11 @@ vi.mock("@calcom/features/bookings/repositories/BookingRepository");
vi.mock("@calcom/features/membership/repositories/MembershipRepository");
vi.mock("@calcom/features/credentials/repositories/CredentialRepository");
+vi.mock("@calcom/prisma", () => ({
+ default: {},
+ prisma: {},
+}));
+
type MockBooking = {
userId: number;
user: {
diff --git a/packages/features/bookings/lib/EventManager.test.ts b/packages/features/bookings/lib/EventManager.test.ts
index 46f83d2b1dc..516a5e7b478 100644
--- a/packages/features/bookings/lib/EventManager.test.ts
+++ b/packages/features/bookings/lib/EventManager.test.ts
@@ -1,6 +1,5 @@
import { prisma } from "@calcom/prisma/__mocks__/prisma";
-
-import { describe, expect, it, vi, beforeEach } from "vitest";
+import { beforeEach, describe, expect, it, vi } from "vitest";
vi.mock("@calcom/features/watchlist/lib/utils/normalization", () => ({
normalizeEmail: vi.fn(),
@@ -20,11 +19,11 @@ vi.mock("@calcom/features/watchlist/lib/telemetry", () => ({
sentrySpan: vi.fn(),
}));
+import process from "node:process";
import { CredentialRepository } from "@calcom/features/credentials/repositories/CredentialRepository";
import { symmetricDecrypt } from "@calcom/lib/crypto";
import type { DestinationCalendar } from "@calcom/prisma/client";
import type { CredentialForCalendarService } from "@calcom/types/Credential";
-
import EventManager from "./EventManager";
vi.mock("@calcom/prisma", () => ({
@@ -41,6 +40,12 @@ vi.mock("@calcom/features/credentials/repositories/CredentialRepository", () =>
},
}));
+vi.mock("@calcom/app-store/delegationCredential", () => ({
+ enrichHostsWithDelegationCredentials: vi.fn(),
+ getUsersCredentialsIncludeServiceAccountKey: vi.fn(),
+ getCredentialForSelectedCalendar: vi.fn(),
+}));
+
const mockedSymmetricDecrypt = vi.mocked(symmetricDecrypt);
const mockedCredentialRepository = vi.mocked(CredentialRepository);
diff --git a/packages/features/bookings/lib/buildEventUrlFromBooking.test.ts b/packages/features/bookings/lib/buildEventUrlFromBooking.test.ts
index a2091c51db7..e10689a7dbd 100644
--- a/packages/features/bookings/lib/buildEventUrlFromBooking.test.ts
+++ b/packages/features/bookings/lib/buildEventUrlFromBooking.test.ts
@@ -1,15 +1,17 @@
import { constantsScenarios } from "@calcom/lib/__mocks__/constants";
-
-import { describe, it, vi, expect, beforeEach } from "vitest";
-
import { getBrand } from "@calcom/features/ee/organizations/lib/getBrand";
-
+import { beforeEach, describe, expect, it, vi } from "vitest";
import { buildEventUrlFromBooking } from "./buildEventUrlFromBooking";
vi.mock("@calcom/features/ee/organizations/lib/getBrand", () => ({
getBrand: vi.fn(),
}));
+vi.mock("@calcom/prisma", () => ({
+ default: {},
+ prisma: {},
+}));
+
const WEBSITE_URL = "https://buildEventTest.example";
beforeEach(() => {
constantsScenarios.setWebsiteUrl(WEBSITE_URL);
diff --git a/packages/features/bookings/lib/getAllCredentialsForUsersOnEvent/getAllCredentials.test.ts b/packages/features/bookings/lib/getAllCredentialsForUsersOnEvent/getAllCredentials.test.ts
index 3d6e48722b4..371b5ebb524 100644
--- a/packages/features/bookings/lib/getAllCredentialsForUsersOnEvent/getAllCredentials.test.ts
+++ b/packages/features/bookings/lib/getAllCredentialsForUsersOnEvent/getAllCredentials.test.ts
@@ -1,13 +1,11 @@
import {
- createCredentials,
- addTeamsToDb,
addEventTypesToDb,
+ addTeamsToDb,
addUsersToDb,
+ createCredentials,
} from "@calcom/testing/lib/bookingScenario/bookingScenario";
-
-import { describe, test, expect, vi } from "vitest";
-
import { UserRepository } from "@calcom/features/users/repositories/UserRepository";
+import { describe, expect, test, vi } from "vitest";
vi.mock("@calcom/features/users/repositories/UserRepository", () => {
return {
@@ -18,7 +16,6 @@ vi.mock("@calcom/features/users/repositories/UserRepository", () => {
}),
};
});
-
describe("getAllCredentialsIncludeServiceAccountKey", () => {
test("Get an individual's credentials", async () => {
const mockEnrichUserWithItsProfile = vi.fn().mockReturnValue({
diff --git a/packages/features/bookings/lib/handleNewBooking/test/buildDryRunBooking.test.ts b/packages/features/bookings/lib/handleNewBooking/test/buildDryRunBooking.test.ts
index 3a7ff736901..1dbfaccc940 100644
--- a/packages/features/bookings/lib/handleNewBooking/test/buildDryRunBooking.test.ts
+++ b/packages/features/bookings/lib/handleNewBooking/test/buildDryRunBooking.test.ts
@@ -1,7 +1,5 @@
-import { describe, it, expect, vi } from "vitest";
-
import { BookingStatus, CreationSource } from "@calcom/prisma/enums";
-
+import { describe, expect, it, vi } from "vitest";
import { buildDryRunBooking } from "../../service/RegularBookingService";
vi.mock("@calcom/prisma", () => ({
@@ -9,6 +7,28 @@ vi.mock("@calcom/prisma", () => ({
prisma: {},
}));
+vi.mock("@calcom/app-store/delegationCredential", () => ({
+ enrichHostsWithDelegationCredentials: vi.fn(),
+ getUsersCredentialsIncludeServiceAccountKey: vi.fn(),
+ getCredentialForSelectedCalendar: vi.fn(),
+}));
+
+vi.mock("@calcom/features/abuse-scoring/lib/hooks", () => ({
+ onEventTypeChange: vi.fn(),
+ onSignup: vi.fn(),
+ onBookingCreated: vi.fn(),
+}));
+
+vi.mock("@calcom/features/di/watchlist/containers/SpamCheckService.container", () => ({
+ getSpamCheckService: vi.fn().mockReturnValue({
+ checkForSpam: vi.fn().mockResolvedValue({ isSpam: false }),
+ }),
+}));
+
+vi.mock("@calcom/features/watchlist/lib/freeEmailDomainCheck/checkIfFreeEmailDomain", () => ({
+ checkIfFreeEmailDomain: vi.fn().mockResolvedValue(false),
+}));
+
describe("buildDryRunBooking", () => {
const baseOrganizerUser = {
id: 1,
diff --git a/packages/features/bookings/lib/handleNewBooking/test/buildEventForTeamEventType.test.ts b/packages/features/bookings/lib/handleNewBooking/test/buildEventForTeamEventType.test.ts
index efb5445b62b..f15b01fe03a 100644
--- a/packages/features/bookings/lib/handleNewBooking/test/buildEventForTeamEventType.test.ts
+++ b/packages/features/bookings/lib/handleNewBooking/test/buildEventForTeamEventType.test.ts
@@ -1,8 +1,7 @@
// or wherever it's from
-import { vi, describe, it, expect, beforeEach } from "vitest";
import { SchedulingType } from "@calcom/prisma/enums";
-
+import { beforeEach, describe, expect, it, vi } from "vitest";
import { buildEventForTeamEventType } from "../../service/RegularBookingService";
vi.mock("@calcom/i18n/server", () => ({
@@ -40,6 +39,28 @@ vi.mock("@calcom/app-store/_utils/calendars/processExternalId", () => ({
default: vi.fn((dc) => `external-${dc?.externalId ?? "id"}`),
}));
+vi.mock("@calcom/app-store/delegationCredential", () => ({
+ enrichHostsWithDelegationCredentials: vi.fn(),
+ getUsersCredentialsIncludeServiceAccountKey: vi.fn(),
+ getCredentialForSelectedCalendar: vi.fn(),
+}));
+
+vi.mock("@calcom/features/abuse-scoring/lib/hooks", () => ({
+ onEventTypeChange: vi.fn(),
+ onSignup: vi.fn(),
+ onBookingCreated: vi.fn(),
+}));
+
+vi.mock("@calcom/features/di/watchlist/containers/SpamCheckService.container", () => ({
+ getSpamCheckService: vi.fn().mockReturnValue({
+ checkForSpam: vi.fn().mockResolvedValue({ isSpam: false }),
+ }),
+}));
+
+vi.mock("@calcom/features/watchlist/lib/freeEmailDomainCheck/checkIfFreeEmailDomain", () => ({
+ checkIfFreeEmailDomain: vi.fn().mockResolvedValue(false),
+}));
+
const baseUser = (overrides: Record<string, unknown> = {}) => ({
id: 1,
name: "Alice",
diff --git a/packages/features/bookings/lib/host-filtering/findQualifiedHostsWithDelegationCredentials.test.ts b/packages/features/bookings/lib/host-filtering/findQualifiedHostsWithDelegationCredentials.test.ts
index b8a0f53f579..ac110886fe9 100644
--- a/packages/features/bookings/lib/host-filtering/findQualifiedHostsWithDelegationCredentials.test.ts
+++ b/packages/features/bookings/lib/host-filtering/findQualifiedHostsWithDelegationCredentials.test.ts
@@ -1,12 +1,9 @@
import prismaMock from "@calcom/testing/lib/__mocks__/prismaMock";
-
-import { vi, it, describe, expect, afterEach } from "vitest";
-import type { Mock } from "vitest";
-
import { getQualifiedHostsService } from "@calcom/features/di/containers/QualifiedHosts";
import * as getRoutedUsers from "@calcom/features/users/lib/getRoutedUsers";
import { RRResetInterval, SchedulingType } from "@calcom/prisma/enums";
-
+import type { Mock } from "vitest";
+import { afterEach, describe, expect, it, vi } from "vitest";
import { filterHostsByLeadThreshold } from "./filterHostsByLeadThreshold";
// Mock the filterHostsByLeadThreshold function
@@ -16,6 +13,12 @@ vi.mock("./filterHostsByLeadThreshold", () => {
};
});
+vi.mock("@calcom/app-store/delegationCredential", () => ({
+ enrichHostsWithDelegationCredentials: vi.fn().mockImplementation(({ hosts }) => hosts),
+ getUsersCredentialsIncludeServiceAccountKey: vi.fn(),
+ getCredentialForSelectedCalendar: vi.fn(),
+}));
+
// Clear call history after each test
afterEach(() => {
(filterHostsByLeadThreshold as Mock).mockClear();
diff --git a/packages/features/bookings/lib/payment/processPaymentRefund.test.ts b/packages/features/bookings/lib/payment/processPaymentRefund.test.ts
index 1fe17dd5bdb..d144f9406fc 100644
--- a/packages/features/bookings/lib/payment/processPaymentRefund.test.ts
+++ b/packages/features/bookings/lib/payment/processPaymentRefund.test.ts
@@ -16,7 +16,6 @@ vi.mock("@calcom/app-store/_utils/payments/getPaymentAppData", () => ({
vi.mock("./handlePaymentRefund", () => ({
handlePaymentRefund: vi.fn(),
}));
-
const mockedGetPaymentAppData = vi.mocked(getPaymentAppData);
describe("processPaymentRefund", () => {
diff --git a/packages/features/bookings/services/BookingAccessService.test.ts b/packages/features/bookings/services/BookingAccessService.test.ts
index ffa8358d143..32a764afa1d 100644
--- a/packages/features/bookings/services/BookingAccessService.test.ts
+++ b/packages/features/bookings/services/BookingAccessService.test.ts
@@ -8,6 +8,11 @@ import { BookingAccessService } from "./BookingAccessService";
vi.mock("../repositories/BookingRepository");
vi.mock("@calcom/features/users/repositories/UserRepository");
+vi.mock("@calcom/prisma", () => ({
+ default: {},
+ prisma: {},
+}));
+
describe("BookingAccessService", () => {
let service: BookingAccessService;
let mockPrismaClient: PrismaClient;
@@ -339,5 +344,4 @@ describe("BookingAccessService", () => {
});
});
});
-
});
diff --git a/packages/features/busyTimes/services/getBusyTimes.test.ts b/packages/features/busyTimes/services/getBusyTimes.test.ts
index 91fdfc76bdc..6153c171180 100644
--- a/packages/features/busyTimes/services/getBusyTimes.test.ts
+++ b/packages/features/busyTimes/services/getBusyTimes.test.ts
@@ -8,6 +8,22 @@ vi.mock("@calcom/prisma", () => ({
prisma,
}));
+vi.mock("@calcom/features/calendars/lib/CalendarManager", () => ({
+ getBusyCalendarTimes: vi.fn().mockResolvedValue([]),
+ createEvent: vi.fn().mockResolvedValue({}),
+ updateEvent: vi.fn().mockResolvedValue({}),
+ deleteEvent: vi.fn().mockResolvedValue({}),
+}));
+
+vi.mock("@calcom/app-store/delegationCredential", () => ({
+ enrichHostsWithDelegationCredentials: vi.fn(),
+ getUsersCredentialsIncludeServiceAccountKey: vi.fn(),
+ getCredentialForSelectedCalendar: vi.fn(),
+ findUniqueDelegationCalendarCredential: vi.fn(),
+ getAllDelegationCredentialsForUserIncludeServiceAccountKey: vi.fn(),
+ getDelegationCredentialOrFindRegularCredential: vi.fn(),
+}));
+
const startOfTomorrow = dayjs().add(1, "day").startOf("day");
const tomorrowDate = startOfTomorrow.format("YYYY-MM-DD");
diff --git a/packages/features/calendar-subscription/lib/__tests__/CalendarSubscriptionService.test.ts b/packages/features/calendar-subscription/lib/__tests__/CalendarSubscriptionService.test.ts
index 353242a5ab1..63a77374247 100644
--- a/packages/features/calendar-subscription/lib/__tests__/CalendarSubscriptionService.test.ts
+++ b/packages/features/calendar-subscription/lib/__tests__/CalendarSubscriptionService.test.ts
@@ -9,6 +9,15 @@ vi.mock("@sentry/nextjs", () => ({
},
}));
+vi.mock("@calcom/app-store/delegationCredential", async () => {
+ const { getCredentialForSelectedCalendar } = await import("../__mocks__/delegationCredential");
+ return {
+ enrichHostsWithDelegationCredentials: vi.fn(),
+ getUsersCredentialsIncludeServiceAccountKey: vi.fn(),
+ getCredentialForSelectedCalendar,
+ };
+});
+
import type { AdapterFactory } from "@calcom/features/calendar-subscription/adapters/AdaptersFactory";
import type { CalendarCacheEventService } from "@calcom/features/calendar-subscription/lib/cache/CalendarCacheEventService";
import type { CalendarSyncService } from "@calcom/features/calendar-subscription/lib/sync/CalendarSyncService";
diff --git a/packages/features/calendars/lib/CalendarManager.test.ts b/packages/features/calendars/lib/CalendarManager.test.ts
index a9f7b637d77..b72b7c96a11 100644
--- a/packages/features/calendars/lib/CalendarManager.test.ts
+++ b/packages/features/calendars/lib/CalendarManager.test.ts
@@ -1,4 +1,5 @@
import { prisma } from "@calcom/prisma/__mocks__/prisma";
+import { getCalendar } from "@calcom/app-store/_utils/getCalendar";
import type { CalendarEvent } from "@calcom/types/Calendar";
import { beforeEach, describe, expect, it, vi } from "vitest";
import {
@@ -7,7 +8,6 @@ import {
getCalendarCredentials,
processEvent,
} from "./CalendarManager";
-import { getCalendar } from "@calcom/app-store/_utils/getCalendar";
vi.mock("@calcom/prisma", () => ({
prisma,
@@ -30,6 +30,15 @@ vi.mock("@calcom/lib/CalEventParser", () => ({
getRichDescription: vi.fn(() => "Test description"),
}));
+vi.mock("@calcom/app-store/delegationCredential", () => ({
+ enrichHostsWithDelegationCredentials: vi.fn(),
+ getUsersCredentialsIncludeServiceAccountKey: vi.fn(),
+ getCredentialForSelectedCalendar: vi.fn(),
+ findUniqueDelegationCalendarCredential: vi.fn(),
+ getAllDelegationCredentialsForUserIncludeServiceAccountKey: vi.fn(),
+ getDelegationCredentialOrFindRegularCredential: vi.fn(),
+}));
+
function buildCredential(data: {
type: string;
appId: string;
diff --git a/packages/features/credentials/deleteCredential.test.ts b/packages/features/credentials/deleteCredential.test.ts
index a38295b84a9..31d2571db20 100644
--- a/packages/features/credentials/deleteCredential.test.ts
+++ b/packages/features/credentials/deleteCredential.test.ts
@@ -1,14 +1,11 @@
import { addEventTypesToDb, mockNoTranslations } from "@calcom/testing/lib/bookingScenario/bookingScenario";
-
-import { describe, test, expect, beforeEach } from "vitest";
-
import { PrismaAppRepository } from "@calcom/features/apps/repository/PrismaAppRepository";
import { DestinationCalendarRepository } from "@calcom/features/calendars/repositories/DestinationCalendarRepository";
import { CredentialRepository } from "@calcom/features/credentials/repositories/CredentialRepository";
import { EventTypeRepository } from "@calcom/features/eventtypes/repositories/eventTypeRepository";
import { UserRepository } from "@calcom/features/users/repositories/UserRepository";
import { prisma } from "@calcom/prisma";
-
+import { beforeEach, describe, expect, test } from "vitest";
const testUser = {
username: "test-user",
diff --git a/packages/features/delegation-credentials/repositories/DelegationCredentialRepository.test.ts b/packages/features/delegation-credentials/repositories/DelegationCredentialRepository.test.ts
index 9a99d85aef6..987a29ac732 100644
--- a/packages/features/delegation-credentials/repositories/DelegationCredentialRepository.test.ts
+++ b/packages/features/delegation-credentials/repositories/DelegationCredentialRepository.test.ts
@@ -1,9 +1,6 @@
import prismock from "@calcom/testing/lib/__mocks__/prisma";
-
-import { describe, expect, it, beforeEach, vi } from "vitest";
-
import { encryptServiceAccountKey } from "@calcom/lib/server/serviceAccountKey";
-
+import { beforeEach, describe, expect, it, vi } from "vitest";
import { DelegationCredentialRepository } from "./DelegationCredentialRepository";
const mockOrganizationRepository = {
@@ -14,14 +11,10 @@ vi.mock("@calcom/features/ee/organizations/di/OrganizationRepository.container",
getOrganizationRepository: () => mockOrganizationRepository,
}));
-vi.mock("@calcom/prisma", () => ({
- prisma: {},
-}));
-
// Mock service account key functions
vi.mock("@calcom/lib/crypto", async (importOriginal) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
- // @ts-ignore
+ // @ts-expect-error
const actual = await importOriginal<typeof import("@calcom/lib/crypto")>();
return {
...actual,
@@ -34,6 +27,12 @@ vi.mock("@calcom/lib/crypto", async (importOriginal) => {
}),
};
});
+
+vi.mock("@calcom/app-store/delegationCredential", () => ({
+ enrichHostsWithDelegationCredentials: vi.fn(),
+ getUsersCredentialsIncludeServiceAccountKey: vi.fn(),
+ getCredentialForSelectedCalendar: vi.fn(),
+}));
// Test Data Helpers
const buildMockServiceAccountKey = () => ({
client_email: "[email protected]",
diff --git a/packages/features/ee/billing/repository/highWaterMark/__tests__/HighWaterMarkRepository.test.ts b/packages/features/ee/billing/repository/highWaterMark/__tests__/HighWaterMarkRepository.test.ts
index e31519be8f6..fd119397693 100644
--- a/packages/features/ee/billing/repository/highWaterMark/__tests__/HighWaterMarkRepository.test.ts
+++ b/packages/features/ee/billing/repository/highWaterMark/__tests__/HighWaterMarkRepository.test.ts
@@ -2,6 +2,11 @@ import { describe, it, expect, vi, beforeEach } from "vitest";
import { HighWaterMarkRepository } from "../HighWaterMarkRepository";
+vi.mock("@calcom/prisma", () => ({
+ default: {},
+ prisma: {},
+}));
+
// Create mock Prisma client
const createMockPrisma = () => ({
team: {
diff --git a/packages/features/ee/billing/service/teams/TeamBillingFactory.test.ts b/packages/features/ee/billing/service/teams/TeamBillingFactory.test.ts
index 8f75505a931..d9078c00825 100644
--- a/packages/features/ee/billing/service/teams/TeamBillingFactory.test.ts
+++ b/packages/features/ee/billing/service/teams/TeamBillingFactory.test.ts
@@ -7,6 +7,11 @@ import { StubTeamBillingService } from "./StubTeamBillingService";
import { TeamBillingService } from "./TeamBillingService";
import { TeamBillingServiceFactory } from "./TeamBillingServiceFactory";
+vi.mock("@calcom/prisma", () => ({
+ default: {},
+ prisma: {},
+}));
+
describe("TeamBilling", () => {
const mockTeam = { id: 1, metadata: null, isOrganization: true, parentId: null, name: "" };
const mockTeams = [mockTeam, { id: 2, metadata: null, isOrganization: false, parentId: 1, name: "" }];
diff --git a/packages/features/ee/billing/service/teams/TeamBillingService.test.ts b/packages/features/ee/billing/service/teams/TeamBillingService.test.ts
index 41e66ef3a47..2e57119821c 100644
--- a/packages/features/ee/billing/service/teams/TeamBillingService.test.ts
+++ b/packages/features/ee/billing/service/teams/TeamBillingService.test.ts
@@ -22,7 +22,6 @@ vi.mock("@calcom/lib/constants", async () => {
vi.mock("@calcom/features/ee/teams/lib/payments", () => ({
purchaseTeamOrOrgSubscription: vi.fn(),
}));
-
const mockTeam = {
id: 1,
metadata: {
diff --git a/packages/features/ee/billing/teams/internal-team-billing.test.ts b/packages/features/ee/billing/teams/internal-team-billing.test.ts
index 45769af5aab..bd9a24a8903 100644
--- a/packages/features/ee/billing/teams/internal-team-billing.test.ts
+++ b/packages/features/ee/billing/teams/internal-team-billing.test.ts
@@ -22,7 +22,6 @@ vi.mock("@calcom/lib/constants", async () => {
vi.mock("@calcom/features/ee/teams/lib/payments", () => ({
purchaseTeamOrOrgSubscription: vi.fn(),
}));
-
function createMockStrategy(): ISeatBillingStrategy {
return { onSeatChange: vi.fn() } as unknown as ISeatBillingStrategy;
}
diff --git a/packages/features/ee/dsync/lib/handleUserEvents.test.ts b/packages/features/ee/dsync/lib/handleUserEvents.test.ts
index f5346076594..846dbc4690c 100644
--- a/packages/features/ee/dsync/lib/handleUserEvents.test.ts
+++ b/packages/features/ee/dsync/lib/handleUserEvents.test.ts
@@ -54,7 +54,6 @@ vi.mock("@calcom/features/users/repositories/UserRepository", () => ({
};
}),
}));
-
async function createMockOrganization({ id, name, slug }: { id: number; name: string; slug: string }) {
return prismock.team.create({
data: {
diff --git a/packages/features/ee/organizations/lib/server/orgCreationUtils.test.ts b/packages/features/ee/organizations/lib/server/orgCreationUtils.test.ts
index edae287df2f..a48317f659d 100644
--- a/packages/features/ee/organizations/lib/server/orgCreationUtils.test.ts
+++ b/packages/features/ee/organizations/lib/server/orgCreationUtils.test.ts
@@ -1,4 +1,18 @@
-import { describe, expect, it } from "vitest";
+import { describe, expect, it, vi } from "vitest";
+
+vi.mock("@calcom/lib/domainManager/organization", () => ({
+ createDomain: vi.fn().mockResolvedValue(true),
+ deleteDomain: vi.fn().mockResolvedValue(true),
+}));
+
+vi.mock("@calcom/emails/organization-email-service", () => ({
+ sendAdminOrganizationNotification: vi.fn().mockResolvedValue(undefined),
+}));
+
+vi.mock("@calcom/prisma", () => ({
+ default: {},
+ prisma: {},
+}));
import { isNotACompanyEmail } from "./orgCreationUtils";
diff --git a/packages/features/ee/organizations/lib/service/onboarding/__tests__/BaseOnboardingService.test.ts b/packages/features/ee/organizations/lib/service/onboarding/__tests__/BaseOnboardingService.test.ts
index e0b0aa6c5da..54d354aa2e1 100644
--- a/packages/features/ee/organizations/lib/service/onboarding/__tests__/BaseOnboardingService.test.ts
+++ b/packages/features/ee/organizations/lib/service/onboarding/__tests__/BaseOnboardingService.test.ts
@@ -1,7 +1,6 @@
-import { describe, expect, it, vi } from "vitest";
-
import type { User } from "@calcom/prisma/client";
import { UserPermissionRole } from "@calcom/prisma/enums";
+import { describe, expect, it, vi } from "vitest";
vi.mock("@calcom/features/ee/teams/repositories/TeamRepository", () => ({
TeamRepository: class {
@@ -12,6 +11,24 @@ vi.mock("@calcom/features/ee/teams/repositories/TeamRepository", () => ({
},
}));
+vi.mock("@calcom/prisma", () => ({
+ default: {},
+ prisma: {},
+}));
+
+vi.mock("@calcom/features/auth/lib/verifyEmail", () => ({
+ sendEmailVerification: vi.fn().mockResolvedValue(undefined),
+}));
+
+vi.mock("@calcom/emails/organization-email-service", () => ({
+ sendOrganizationCreationEmail: vi.fn().mockResolvedValue(undefined),
+}));
+
+vi.mock("@calcom/lib/domainManager/organization", () => ({
+ createDomain: vi.fn().mockResolvedValue(true),
+ deleteDomain: vi.fn().mockResolvedValue(true),
+}));
+
import { BaseOnboardingService } from "../BaseOnboardingService";
import type { CreateOnboardingIntentInput, OnboardingIntentResult } from "../types";
diff --git a/packages/features/ee/organizations/lib/service/onboarding/__tests__/SelfHostedOnboardingService.test.ts b/packages/features/ee/organizations/lib/service/onboarding/__tests__/SelfHostedOnboardingService.test.ts
index 54dce512b95..b801ccb6e6b 100644
--- a/packages/features/ee/organizations/lib/service/onboarding/__tests__/SelfHostedOnboardingService.test.ts
+++ b/packages/features/ee/organizations/lib/service/onboarding/__tests__/SelfHostedOnboardingService.test.ts
@@ -1,14 +1,11 @@
import prismock from "@calcom/testing/lib/__mocks__/prisma";
-
-import { describe, expect, it, vi, beforeEach } from "vitest";
-
import { LicenseKeySingleton } from "@calcom/ee/common/server/LicenseKeyService";
import { OrganizationOnboardingRepository } from "@calcom/features/organizations/repositories/OrganizationOnboardingRepository";
import * as constants from "@calcom/lib/constants";
-import { UserPermissionRole, CreationSource, MembershipRole, BillingPeriod } from "@calcom/prisma/enums";
+import { BillingPeriod, CreationSource, MembershipRole, UserPermissionRole } from "@calcom/prisma/enums";
import { createTeamsHandler } from "@calcom/trpc/server/routers/viewer/organizations/createTeams.handler";
import { inviteMembersWithNoInviterPermissionCheck } from "@calcom/trpc/server/routers/viewer/teams/inviteMember/inviteMember.handler";
-
+import { beforeEach, describe, expect, it, vi } from "vitest";
import { SelfHostedOrganizationOnboardingService } from "../SelfHostedOnboardingService";
import type { CreateOnboardingIntentInput, OrganizationOnboardingData } from "../types";
@@ -39,7 +36,6 @@ vi.mock("@calcom/trpc/server/routers/viewer/organizations/createTeams.handler",
vi.mock("@calcom/lib/domainManager/organization", () => ({
createDomain: vi.fn(),
}));
-
vi.mock("@calcom/i18n/server", () => {
return {
getTranslation: async (locale: string, namespace: string) => {
diff --git a/packages/features/ee/teams/services/teamService.test.ts b/packages/features/ee/teams/services/teamService.test.ts
index ca215b75da8..925dd6c2c9a 100644
--- a/packages/features/ee/teams/services/teamService.test.ts
+++ b/packages/features/ee/teams/services/teamService.test.ts
@@ -1,3 +1,4 @@
+import prismaMock from "@calcom/testing/lib/__mocks__/prismaMock";
import { updateNewTeamMemberEventTypes } from "@calcom/features/ee/teams/lib/queries";
import { TeamRepository } from "@calcom/features/ee/teams/repositories/TeamRepository";
import { WorkflowService } from "@calcom/features/ee/workflows/lib/service/WorkflowService";
@@ -7,9 +8,7 @@ import { ErrorCode } from "@calcom/lib/errorCodes";
import { ErrorWithCode } from "@calcom/lib/errors";
import type { Membership, Profile, Team, User, VerificationToken } from "@calcom/prisma/client";
import { MembershipRole } from "@calcom/prisma/enums";
-import prismaMock from "@calcom/testing/lib/__mocks__/prismaMock";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
-
import { TeamService } from "./teamService";
const { MockSeatChangeTrackingService } = vi.hoisted(() => {
@@ -30,7 +29,6 @@ vi.mock("@calcom/features/ee/teams/lib/queries");
vi.mock("@calcom/features/ee/billing/service/seatTracking/SeatChangeTrackingService", () => ({
SeatChangeTrackingService: MockSeatChangeTrackingService,
}));
-
const mockTeamBilling = {
cancel: vi.fn(),
updateQuantity: vi.fn(),
diff --git a/packages/features/profile/repositories/ProfileRepository.test.ts b/packages/features/profile/repositories/ProfileRepository.test.ts
index 723c68fdb26..380e7a7bff5 100644
--- a/packages/features/profile/repositories/ProfileRepository.test.ts
+++ b/packages/features/profile/repositories/ProfileRepository.test.ts
@@ -20,7 +20,6 @@ vi.mock("@calcom/lib/logger", () => ({
}),
},
}));
-
describe("ProfileRepository.findByUpIdWithAuth - IDOR Security Fix", () => {
let user1: { id: number; email: string; username: string };
let user2: { id: number; email: string; username: string };
diff --git a/packages/features/routing-forms/lib/getRoutedUrl.test.ts b/packages/features/routing-forms/lib/getRoutedUrl.test.ts
index 48dfe81262c..0bc9cc6a427 100644
--- a/packages/features/routing-forms/lib/getRoutedUrl.test.ts
+++ b/packages/features/routing-forms/lib/getRoutedUrl.test.ts
@@ -54,6 +54,11 @@ vi.mock("@calcom/features/routing-trace/di/RoutingTraceService.container", () =>
})),
}));
+vi.mock("@calcom/prisma", () => ({
+ default: {},
+ prisma: {},
+}));
+
const mockForm: {
id: string;
user: { id: number; name: string };
diff --git a/packages/features/schedules/repositories/ScheduleRepository.test.ts b/packages/features/schedules/repositories/ScheduleRepository.test.ts
index 6a2db4fb4b4..bd7dc43618c 100644
--- a/packages/features/schedules/repositories/ScheduleRepository.test.ts
+++ b/packages/features/schedules/repositories/ScheduleRepository.test.ts
@@ -1,15 +1,11 @@
import prismaMock from "@calcom/testing/lib/__mocks__/prismaMock";
-
-import { describe, expect, it, vi, beforeEach } from "vitest";
-
import type { Schedule, User } from "@calcom/prisma/client";
-
+import { beforeEach, describe, expect, it, vi } from "vitest";
import { ScheduleRepository } from "./ScheduleRepository";
vi.mock("@calcom/lib/hasEditPermissionForUser", () => ({
hasReadPermissionsForUserId: vi.fn(),
}));
-
import { hasReadPermissionsForUserId } from "@calcom/lib/hasEditPermissionForUser";
const mockHasReadPermissions = vi.mocked(hasReadPermissionsForUserId);
diff --git a/packages/features/selectedCalendar/repositories/SelectedCalendarRepository.test.ts b/packages/features/selectedCalendar/repositories/SelectedCalendarRepository.test.ts
index 8fe1c4b27d6..0d7b54fbb89 100644
--- a/packages/features/selectedCalendar/repositories/SelectedCalendarRepository.test.ts
+++ b/packages/features/selectedCalendar/repositories/SelectedCalendarRepository.test.ts
@@ -6,7 +6,12 @@ import type { PrismaClient } from "@calcom/prisma";
import prisma from "@calcom/prisma";
import type { Prisma, SelectedCalendar } from "@calcom/prisma/client";
import { MembershipRole } from "@calcom/prisma/enums";
-import { beforeEach, describe, expect, test, vi, it } from "vitest";
+import { beforeEach, describe, expect, it, test, vi } from "vitest";
+vi.mock("@calcom/app-store/delegationCredential", () => ({
+ enrichHostsWithDelegationCredentials: vi.fn(),
+ getUsersCredentialsIncludeServiceAccountKey: vi.fn(),
+ getCredentialForSelectedCalendar: vi.fn(),
+}));
const mockPrismaClient = {
selectedCalendar: {
diff --git a/packages/features/slots/handleNotificationWhenNoSlots.test.ts b/packages/features/slots/handleNotificationWhenNoSlots.test.ts
index d2c6d86b444..2ca7195ff4c 100644
--- a/packages/features/slots/handleNotificationWhenNoSlots.test.ts
+++ b/packages/features/slots/handleNotificationWhenNoSlots.test.ts
@@ -1,12 +1,10 @@
import i18nMock from "@calcom/testing/lib/__mocks__/libServerI18n";
import prismaMock from "@calcom/testing/lib/__mocks__/prismaMock";
-
-import { vi, describe, it, beforeAll, afterAll, expect, beforeEach, afterEach } from "vitest";
-
import dayjs from "@calcom/dayjs";
import * as CalcomEmails from "@calcom/emails/organization-email-service";
import { getNoSlotsNotificationService } from "@calcom/features/di/containers/NoSlotsNotification";
import { RedisService } from "@calcom/features/redis/RedisService";
+import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
vi.mock("@calcom/features/redis/RedisService", () => {
const mockedRedis = vi.fn();
@@ -26,6 +24,12 @@ vi.mock("@calcom/features/flags/features.repository", () => ({
}),
}));
+vi.mock("@calcom/emails/organization-email-service", () => ({
+ OrganizationEmailService: vi.fn().mockImplementation(() => ({
+ sendOrganizationCreationEmail: vi.fn(),
+ })),
+ sendOrganizationAdminNoSlotsNotification: vi.fn(),
+}));
vi.spyOn(CalcomEmails, "sendOrganizationAdminNoSlotsNotification");
describe("(Orgs) Send admin notifications when a user has no availability", () => {
diff --git a/packages/features/tasker/tasks/executeAIPhoneCall.test.ts b/packages/features/tasker/tasks/executeAIPhoneCall.test.ts
index df1f8a1370e..1df8d5d56db 100644
--- a/packages/features/tasker/tasks/executeAIPhoneCall.test.ts
+++ b/packages/features/tasker/tasks/executeAIPhoneCall.test.ts
@@ -1,6 +1,11 @@
import { convertResponsesToVariableFormats } from "@calcom/features/tasker/tasks/executeAIPhoneCall";
import { describe, expect, it } from "vitest";
+vi.mock("@calcom/prisma", () => ({
+ default: {},
+ prisma: {},
+}));
+
describe("executeAIPhoneCall - convertResponsesToVariableFormats", () => {
it("should generate both variable formats for identifiers with underscores", () => {
const responses = {
diff --git a/packages/features/tasker/tasks/scanWorkflowBody.test.ts b/packages/features/tasker/tasks/scanWorkflowBody.test.ts
index 5a2d20d9d53..4c256d95d81 100644
--- a/packages/features/tasker/tasks/scanWorkflowBody.test.ts
+++ b/packages/features/tasker/tasks/scanWorkflowBody.test.ts
@@ -1,11 +1,8 @@
import prismaMock from "@calcom/testing/lib/__mocks__/prismaMock";
-
-import { describe, expect, it, vi, beforeEach } from "vitest";
-
-import { lockUser, LockReason } from "@calcom/features/ee/api-keys/lib/autoLock";
+import { LockReason, lockUser } from "@calcom/features/ee/api-keys/lib/autoLock";
import { scheduleWorkflowNotifications } from "@calcom/features/ee/workflows/lib/scheduleWorkflowNotifications";
-
-import { scanWorkflowBody, iffyScanBody } from "./scanWorkflowBody";
+import { beforeEach, describe, expect, it, vi } from "vitest";
+import { iffyScanBody, scanWorkflowBody } from "./scanWorkflowBody";
vi.mock("@calcom/features/ee/api-keys/lib/autoLock", async (importActual) => {
const actual = await importActual<typeof import("@calcom/features/ee/api-keys/lib/autoLock")>();
@@ -26,7 +23,6 @@ vi.mock("./scanWorkflowBody", async (importActual) => {
iffyScanBody: vi.fn(),
};
});
-
const mockWorkflowStep = {
id: 1,
reminderBody: "Test reminder body",
diff --git a/packages/features/tasker/tasks/test/scanWorkflowBody.test.ts b/packages/features/tasker/tasks/test/scanWorkflowBody.test.ts
index 9107c8ab0e5..d730b99a31b 100644
--- a/packages/features/tasker/tasks/test/scanWorkflowBody.test.ts
+++ b/packages/features/tasker/tasks/test/scanWorkflowBody.test.ts
@@ -53,7 +53,6 @@ vi.mock("@calcom/lib/constants", async () => {
URL_SCANNING_ENABLED: true,
};
});
-
// Import mocked modules for assertions
import { submitWorkflowStepForUrlScanning } from "../scanWorkflowUrls";
import { scheduleWorkflowNotifications } from "@calcom/features/ee/workflows/lib/scheduleWorkflowNotifications";
diff --git a/packages/features/tasker/tasks/triggerFormSubmittedNoEvent/triggerFormSubmittedNoEventWebhook.test.ts b/packages/features/tasker/tasks/triggerFormSubmittedNoEvent/triggerFormSubmittedNoEventWebhook.test.ts
index 8761f287998..203dd1d0d5f 100644
--- a/packages/features/tasker/tasks/triggerFormSubmittedNoEvent/triggerFormSubmittedNoEventWebhook.test.ts
+++ b/packages/features/tasker/tasks/triggerFormSubmittedNoEvent/triggerFormSubmittedNoEventWebhook.test.ts
@@ -1,12 +1,9 @@
import prismaMock from "@calcom/testing/lib/__mocks__/prismaMock";
-
-import { describe, expect, it, beforeEach, vi } from "vitest";
-
import type { ResponseData } from "@calcom/features/tasker/tasks/triggerFormSubmittedNoEvent/triggerFormSubmittedNoEventWebhook";
import { triggerFormSubmittedNoEventWebhook } from "@calcom/features/tasker/tasks/triggerFormSubmittedNoEvent/triggerFormSubmittedNoEventWebhook";
import type { Webhook } from "@calcom/prisma/client";
import { WebhookTriggerEvents } from "@calcom/prisma/enums";
-
+import { beforeEach, describe, expect, it, vi } from "vitest";
function expectFormSubmittedNoEventWebhookToBeCalled(
payload: ResponseData & {
webhook: Pick<Webhook, "subscriberUrl" | "appId" | "payloadTemplate" | "secret">;
diff --git a/packages/features/tasker/tasks/triggerFormSubmittedNoEvent/triggerFormSubmittedNoEventWorkflow.test.ts b/packages/features/tasker/tasks/triggerFormSubmittedNoEvent/triggerFormSubmittedNoEventWorkflow.test.ts
index 2f2949d6eec..bd9aff71cb7 100644
--- a/packages/features/tasker/tasks/triggerFormSubmittedNoEvent/triggerFormSubmittedNoEventWorkflow.test.ts
+++ b/packages/features/tasker/tasks/triggerFormSubmittedNoEvent/triggerFormSubmittedNoEventWorkflow.test.ts
@@ -1,13 +1,10 @@
import prismaMock from "@calcom/testing/lib/__mocks__/prismaMock";
-
-import { describe, expect, it, beforeEach, vi } from "vitest";
-import type { z } from "zod";
-
import { scheduleWorkflowReminders } from "@calcom/ee/workflows/lib/reminders/reminderScheduler";
import type { ZTriggerFormSubmittedNoEventWorkflowPayloadSchema } from "@calcom/features/tasker/tasks/triggerFormSubmittedNoEvent/triggerFormSubmittedNoEventWorkflow";
import { triggerFormSubmittedNoEventWorkflow } from "@calcom/features/tasker/tasks/triggerFormSubmittedNoEvent/triggerFormSubmittedNoEventWorkflow";
-import { WorkflowTriggerEvents, WorkflowActions, WorkflowTemplates, TimeUnit } from "@calcom/prisma/enums";
-
+import { TimeUnit, WorkflowActions, WorkflowTemplates, WorkflowTriggerEvents } from "@calcom/prisma/enums";
+import { beforeEach, describe, expect, it, vi } from "vitest";
+import type { z } from "zod";
import { shouldTriggerFormSubmittedNoEvent } from "./formSubmissionValidation";
// Mock the scheduleWorkflowReminders function
@@ -27,7 +24,6 @@ vi.mock("@calcom/lib/logger", () => ({
error: vi.fn(),
},
}));
-
const mockScheduleWorkflowReminders = vi.mocked(scheduleWorkflowReminders);
const mockShouldTriggerFormSubmittedNoEvent = vi.mocked(shouldTriggerFormSubmittedNoEvent);
diff --git a/packages/features/users/repositories/UserRepository.test.ts b/packages/features/users/repositories/UserRepository.test.ts
index 76eee679256..44e7001c968 100644
--- a/packages/features/users/repositories/UserRepository.test.ts
+++ b/packages/features/users/repositories/UserRepository.test.ts
@@ -1,9 +1,12 @@
import prismock from "@calcom/testing/lib/__mocks__/prisma";
-
-import { describe, test, vi, expect, beforeEach } from "vitest";
-
import { UserRepository } from "@calcom/features/users/repositories/UserRepository";
import { CreationSource } from "@calcom/prisma/enums";
+import { beforeEach, describe, expect, test, vi } from "vitest";
+vi.mock("@calcom/app-store/delegationCredential", () => ({
+ enrichHostsWithDelegationCredentials: vi.fn(),
+ getUsersCredentialsIncludeServiceAccountKey: vi.fn(),
+ getCredentialForSelectedCalendar: vi.fn(),
+}));
vi.mock("@calcom/i18n/server", () => {
return {
diff --git a/packages/features/watchlist/lib/service/AdminWatchlistOperationsService.test.ts b/packages/features/watchlist/lib/service/AdminWatchlistOperationsService.test.ts
index 44dd0519593..fb05ed0cbd6 100644
--- a/packages/features/watchlist/lib/service/AdminWatchlistOperationsService.test.ts
+++ b/packages/features/watchlist/lib/service/AdminWatchlistOperationsService.test.ts
@@ -6,6 +6,11 @@ vi.mock("@calcom/features/auth/lib/verifyEmail", () => ({
sendEmailVerification: vi.fn().mockResolvedValue(undefined),
}));
+vi.mock("@calcom/prisma", () => ({
+ default: {},
+ prisma: {},
+}));
+
import { sendEmailVerification } from "@calcom/features/auth/lib/verifyEmail";
function createMockWatchlistRepo() {
diff --git a/packages/trpc/server/routers/viewer/apps/appById.handler.test.ts b/packages/trpc/server/routers/viewer/apps/appById.handler.test.ts
index 9c4d9297501..e2ff468bd20 100644
--- a/packages/trpc/server/routers/viewer/apps/appById.handler.test.ts
+++ b/packages/trpc/server/routers/viewer/apps/appById.handler.test.ts
@@ -1,9 +1,6 @@
-import { describe, it, expect, vi, beforeEach } from "vitest";
-
-import { TRPCError } from "@trpc/server";
-
import type { CredentialForCalendarService } from "@calcom/types/Credential";
-
+import { TRPCError } from "@trpc/server";
+import { beforeEach, describe, expect, it, vi } from "vitest";
import { appByIdHandler } from "./appById.handler";
import type { TAppByIdInputSchema } from "./appById.schema";
@@ -20,10 +17,18 @@ vi.mock("@calcom/app-store/utils", () => ({
}),
}));
-import { getUsersCredentialsIncludeServiceAccountKey } from "@calcom/app-store/delegationCredential";
-import getApps, { sanitizeAppForViewer } from "@calcom/app-store/utils";
+vi.mock("@calcom/app-store/_utils/getCalendar", () => ({
+ getCalendar: vi.fn().mockReturnValue(null),
+}));
+
+vi.mock("@calcom/prisma", () => ({
+ default: {},
+ prisma: {},
+}));
+import { getUsersCredentialsIncludeServiceAccountKey } from "@calcom/app-store/delegationCredential";
import type { CredentialDataWithTeamName, LocationOption } from "@calcom/app-store/utils";
+import getApps, { sanitizeAppForViewer } from "@calcom/app-store/utils";
import type { App } from "@calcom/types/App";
describe("appByIdHandler", () => {
diff --git a/packages/trpc/server/routers/viewer/availability/schedule/getAllSchedulesByUserId.handler.test.ts b/packages/trpc/server/routers/viewer/availability/schedule/getAllSchedulesByUserId.handler.test.ts
index 680a2c3c47a..91e51711b42 100644
--- a/packages/trpc/server/routers/viewer/availability/schedule/getAllSchedulesByUserId.handler.test.ts
+++ b/packages/trpc/server/routers/viewer/availability/schedule/getAllSchedulesByUserId.handler.test.ts
@@ -1,9 +1,6 @@
import prismaMock from "@calcom/testing/lib/__mocks__/prismaMock";
-
-import { describe, it, beforeEach, vi, expect } from "vitest";
-
import type { Schedule } from "@calcom/prisma/client";
-
+import { beforeEach, describe, expect, it, vi } from "vitest";
import type { TrpcSessionUser } from "../../../../types";
import { getAllSchedulesByUserIdHandler } from "./getAllSchedulesByUserId.handler";
@@ -20,7 +17,6 @@ vi.mock("@calcom/features/schedules/repositories/ScheduleRepository", () => ({
};
}),
}));
-
import { hasReadPermissionsForUserId } from "@calcom/lib/hasEditPermissionForUser";
const mockHasReadPermissions = vi.mocked(hasReadPermissionsForUserId);
diff --git a/packages/trpc/server/routers/viewer/bookings/reportBooking.handler.test.ts b/packages/trpc/server/routers/viewer/bookings/reportBooking.handler.test.ts
index 8bfe861b953..b194df865c9 100644
--- a/packages/trpc/server/routers/viewer/bookings/reportBooking.handler.test.ts
+++ b/packages/trpc/server/routers/viewer/bookings/reportBooking.handler.test.ts
@@ -1,13 +1,10 @@
-import { describe, it, expect, vi, beforeEach } from "vitest";
-
import { PrismaBookingReportRepository } from "@calcom/features/bookingReport/repositories/PrismaBookingReportRepository";
import handleCancelBooking from "@calcom/features/bookings/lib/handleCancelBooking";
import { BookingRepository } from "@calcom/features/bookings/repositories/BookingRepository";
import { BookingAccessService } from "@calcom/features/bookings/services/BookingAccessService";
-import { BookingStatus, BookingReportReason } from "@calcom/prisma/enums";
-
+import { BookingReportReason, BookingStatus } from "@calcom/prisma/enums";
import { TRPCError } from "@trpc/server";
-
+import { beforeEach, describe, expect, it, vi } from "vitest";
import { reportBookingHandler } from "./reportBooking.handler";
vi.mock("@calcom/features/bookingReport/repositories/PrismaBookingReportRepository");
@@ -23,6 +20,11 @@ vi.mock("@calcom/lib/logger", () => ({
},
}));
+vi.mock("@calcom/prisma", () => ({
+ default: {},
+ prisma: {},
+}));
+
describe("reportBookingHandler", () => {
const mockUser = {
id: 1,
diff --git a/packages/trpc/server/routers/viewer/delegationCredential/toggleEnabled.handler.test.ts b/packages/trpc/server/routers/viewer/delegationCredential/toggleEnabled.handler.test.ts
index 24f6470cd06..7739c27a422 100644
--- a/packages/trpc/server/routers/viewer/delegationCredential/toggleEnabled.handler.test.ts
+++ b/packages/trpc/server/routers/viewer/delegationCredential/toggleEnabled.handler.test.ts
@@ -1,7 +1,5 @@
-import { describe, it, beforeEach, vi, expect } from "vitest";
-
import { DelegationCredentialRepository } from "@calcom/features/delegation-credentials/repositories/DelegationCredentialRepository";
-
+import { beforeEach, describe, expect, it, vi } from "vitest";
import { toggleDelegationCredentialEnabled } from "./toggleEnabled.handler";
// Mock the repository
@@ -30,6 +28,11 @@ vi.mock("./utils", () => ({
ensureNoServiceAccountKey: vi.fn((credential) => credential),
}));
+vi.mock("@calcom/prisma", () => ({
+ default: {},
+ prisma: {},
+}));
+
describe("toggleDelegationCredentialEnabled - Security Fix", () => {
beforeEach(() => {
vi.clearAllMocks();
diff --git a/packages/trpc/server/routers/viewer/eventTypes/__tests__/util.test.ts b/packages/trpc/server/routers/viewer/eventTypes/__tests__/util.test.ts
index 005769679db..33f52bb18c4 100644
--- a/packages/trpc/server/routers/viewer/eventTypes/__tests__/util.test.ts
+++ b/packages/trpc/server/routers/viewer/eventTypes/__tests__/util.test.ts
@@ -12,6 +12,11 @@ import { createEventPbacProcedure, ensureEmailOrPhoneNumberIsPresent } from "../
// Mock dependencies
vi.mock("@calcom/features/pbac/services/permission-check.service");
+vi.mock("@calcom/prisma", () => ({
+ default: {},
+ prisma: {},
+}));
+
describe("createEventPbacProcedure", () => {
let mockPermissionCheckService: {
checkPermission: Mock;
diff --git a/packages/trpc/server/routers/viewer/organizations/__tests__/createTeams.handler.test.ts b/packages/trpc/server/routers/viewer/organizations/__tests__/createTeams.handler.test.ts
index d877f6810ce..4a51ecaf35b 100644
--- a/packages/trpc/server/routers/viewer/organizations/__tests__/createTeams.handler.test.ts
+++ b/packages/trpc/server/routers/viewer/organizations/__tests__/createTeams.handler.test.ts
@@ -1,14 +1,9 @@
import prismock from "@calcom/testing/lib/__mocks__/prisma";
-
-import { describe, expect, it, beforeEach, vi } from "vitest";
-
import slugify from "@calcom/lib/slugify";
-import { MembershipRole, UserPermissionRole, CreationSource, RedirectType } from "@calcom/prisma/enums";
-
+import { CreationSource, MembershipRole, RedirectType, UserPermissionRole } from "@calcom/prisma/enums";
import { TRPCError } from "@trpc/server";
-
+import { beforeEach, describe, expect, it, vi } from "vitest";
import { createTeamsHandler } from "../createTeams.handler";
-
// Helper functions for creating test data
async function createTestUser(data: {
email: string;
diff --git a/packages/trpc/server/routers/viewer/organizations/create.handler.test.ts b/packages/trpc/server/routers/viewer/organizations/create.handler.test.ts
index bbcd7d871cf..2b6cb8e85a8 100644
--- a/packages/trpc/server/routers/viewer/organizations/create.handler.test.ts
+++ b/packages/trpc/server/routers/viewer/organizations/create.handler.test.ts
@@ -1,7 +1,6 @@
import prismock from "@calcom/testing/lib/__mocks__/prisma";
-
-import { describe, expect, it, vi, beforeEach } from "vitest";
import { UserPermissionRole } from "@calcom/prisma/enums";
+import { beforeEach, describe, expect, it, vi } from "vitest";
import { createHandler } from "./create.handler";
vi.mock("@calcom/lib/constants", async (importOriginal) => {
@@ -21,6 +20,9 @@ vi.mock("@calcom/lib/domainManager/organization", () => ({
vi.mock("@calcom/i18n/server", () => ({
getTranslation: vi.fn().mockResolvedValue((key: string) => key),
}));
+vi.mock("@calcom/features/auth/lib/verifyEmail", () => ({
+ sendEmailVerification: vi.fn().mockResolvedValue(undefined),
+}));
const createTestUser = async (overrides: { email: string; role?: UserPermissionRole }) => {
return prismock.user.create({
diff --git a/packages/trpc/server/routers/viewer/organizations/deleteWatchlistEntry.handler.test.ts b/packages/trpc/server/routers/viewer/organizations/deleteWatchlistEntry.handler.test.ts
index 9783408951d..63b595b9bf7 100644
--- a/packages/trpc/server/routers/viewer/organizations/deleteWatchlistEntry.handler.test.ts
+++ b/packages/trpc/server/routers/viewer/organizations/deleteWatchlistEntry.handler.test.ts
@@ -8,6 +8,11 @@ import { deleteWatchlistEntryHandler } from "./deleteWatchlistEntry.handler";
vi.mock("@calcom/features/di/watchlist/containers/watchlist");
vi.mock("@calcom/features/watchlist/lib/repository/WatchlistRepository");
+vi.mock("@calcom/prisma", () => ({
+ default: {},
+ prisma: {},
+}));
+
describe("deleteWatchlistEntryHandler", () => {
const mockUser = {
id: 1,
diff --git a/packages/trpc/server/routers/viewer/organizations/handleBannerUpdate.test.ts b/packages/trpc/server/routers/viewer/organizations/handleBannerUpdate.test.ts
index 1aa2588f657..3399c909815 100644
--- a/packages/trpc/server/routers/viewer/organizations/handleBannerUpdate.test.ts
+++ b/packages/trpc/server/routers/viewer/organizations/handleBannerUpdate.test.ts
@@ -10,6 +10,11 @@ vi.mock("@calcom/lib/server/resizeBase64Image", () => ({
resizeBase64Image: vi.fn((input) => input),
}));
+vi.mock("@calcom/prisma", () => ({
+ default: {},
+ prisma: {},
+}));
+
const { uploadLogo } = await import("@calcom/lib/server/avatar");
const { resizeBase64Image } = await import("@calcom/lib/server/resizeBase64Image");
diff --git a/packages/trpc/server/routers/viewer/organizations/listBookingReports.handler.test.ts b/packages/trpc/server/routers/viewer/organizations/listBookingReports.handler.test.ts
index 8a8f326d31a..8eccada8fdd 100644
--- a/packages/trpc/server/routers/viewer/organizations/listBookingReports.handler.test.ts
+++ b/packages/trpc/server/routers/viewer/organizations/listBookingReports.handler.test.ts
@@ -14,6 +14,11 @@ import { listBookingReportsHandler } from "./listBookingReports.handler";
vi.mock("@calcom/features/pbac/services/permission-check.service");
vi.mock("@calcom/features/bookingReport/repositories/PrismaBookingReportRepository");
+vi.mock("@calcom/prisma", () => ({
+ default: {},
+ prisma: {},
+}));
+
describe("listBookingReportsHandler (Organization)", () => {
const mockUser = {
id: 1,
diff --git a/packages/trpc/server/routers/viewer/teams/get.handler.test.ts b/packages/trpc/server/routers/viewer/teams/get.handler.test.ts
index 85fd64dfa5c..ec94f339da1 100644
--- a/packages/trpc/server/routers/viewer/teams/get.handler.test.ts
+++ b/packages/trpc/server/routers/viewer/teams/get.handler.test.ts
@@ -1,7 +1,5 @@
-import { describe, it, beforeEach, vi, expect } from "vitest";
-
import { getTeamWithoutMembers } from "@calcom/features/ee/teams/lib/queries";
-
+import { beforeEach, describe, expect, it, vi } from "vitest";
import type { TrpcSessionUser } from "../../../types";
import getTeam from "./get.handler";
@@ -23,6 +21,11 @@ vi.mock("@calcom/features/ee/teams/lib/queries", () => ({
getTeamWithoutMembers: vi.fn(),
}));
+vi.mock("@calcom/prisma", () => ({
+ default: {},
+ prisma: {},
+}));
+
describe("getTeam", () => {
const user = {
id: 1,
diff --git a/packages/trpc/server/routers/viewer/teams/removeMember/__tests__/LegacyRemoveMemberService.test.ts b/packages/trpc/server/routers/viewer/teams/removeMember/__tests__/LegacyRemoveMemberService.test.ts
index 00b5be5cf2d..47f390c41b1 100644
--- a/packages/trpc/server/routers/viewer/teams/removeMember/__tests__/LegacyRemoveMemberService.test.ts
+++ b/packages/trpc/server/routers/viewer/teams/removeMember/__tests__/LegacyRemoveMemberService.test.ts
@@ -1,11 +1,9 @@
-import { describe, expect, it, vi, beforeEach } from "vitest";
-
import * as teamQueries from "@calcom/features/ee/teams/lib/queries";
import type { TeamRepository } from "@calcom/features/ee/teams/repositories/TeamRepository";
import { TeamService } from "@calcom/features/ee/teams/services/teamService";
import { prisma } from "@calcom/prisma";
import { MembershipRole } from "@calcom/prisma/enums";
-
+import { beforeEach, describe, expect, it, vi } from "vitest";
import { LegacyRemoveMemberService } from "../LegacyRemoveMemberService";
vi.mock("@calcom/prisma", () => ({
@@ -19,6 +17,11 @@ vi.mock("@calcom/prisma", () => ({
vi.mock("@calcom/features/ee/teams/services/teamService");
vi.mock("@calcom/features/ee/teams/lib/queries");
+vi.mock("@calcom/lib/domainManager/organization", () => ({
+ createDomain: vi.fn(),
+ deleteDomain: vi.fn(),
+}));
+
describe("LegacyRemoveMemberService", () => {
let service: LegacyRemoveMemberService;
let mockTeamRepository: { findByIdsAndOrgId: ReturnType<typeof vi.fn> };
diff --git a/packages/trpc/server/routers/viewer/teams/removeMember/__tests__/PBACRemoveMemberService.test.ts b/packages/trpc/server/routers/viewer/teams/removeMember/__tests__/PBACRemoveMemberService.test.ts
index 33dbd7b6df1..0a296f7adaa 100644
--- a/packages/trpc/server/routers/viewer/teams/removeMember/__tests__/PBACRemoveMemberService.test.ts
+++ b/packages/trpc/server/routers/viewer/teams/removeMember/__tests__/PBACRemoveMemberService.test.ts
@@ -1,13 +1,11 @@
-import { describe, expect, it, vi, beforeEach, type Mock } from "vitest";
-
import * as teamQueries from "@calcom/features/ee/teams/lib/queries";
import { TeamService } from "@calcom/features/ee/teams/services/teamService";
import { PermissionMapper } from "@calcom/features/pbac/domain/mappers/PermissionMapper";
-import { Resource, CustomAction } from "@calcom/features/pbac/domain/types/permission-registry";
+import { CustomAction, Resource } from "@calcom/features/pbac/domain/types/permission-registry";
import { PermissionCheckService } from "@calcom/features/pbac/services/permission-check.service";
import { prisma } from "@calcom/prisma";
import { MembershipRole } from "@calcom/prisma/enums";
-
+import { beforeEach, describe, expect, it, type Mock, vi } from "vitest";
import { PBACRemoveMemberService } from "../PBACRemoveMemberService";
vi.mock("@calcom/prisma", () => ({
@@ -23,6 +21,11 @@ vi.mock("@calcom/features/ee/teams/lib/queries");
vi.mock("@calcom/features/pbac/services/permission-check.service");
vi.mock("@calcom/features/pbac/domain/mappers/PermissionMapper");
+vi.mock("@calcom/lib/domainManager/organization", () => ({
+ createDomain: vi.fn(),
+ deleteDomain: vi.fn(),
+}));
+
describe("PBACRemoveMemberService", () => {
let service: PBACRemoveMemberService;
let mockPermissionCheckService: {
diff --git a/packages/trpc/server/routers/viewer/teams/removeMember/__tests__/RemoveMemberServiceFactory.test.ts b/packages/trpc/server/routers/viewer/teams/removeMember/__tests__/RemoveMemberServiceFactory.test.ts
index 3e92501fa5c..d088d7d0ed0 100644
--- a/packages/trpc/server/routers/viewer/teams/removeMember/__tests__/RemoveMemberServiceFactory.test.ts
+++ b/packages/trpc/server/routers/viewer/teams/removeMember/__tests__/RemoveMemberServiceFactory.test.ts
@@ -1,7 +1,5 @@
-import { describe, expect, it, vi, beforeEach } from "vitest";
-
import { FeaturesRepository } from "@calcom/features/flags/features.repository";
-
+import { beforeEach, describe, expect, it, vi } from "vitest";
import { LegacyRemoveMemberService } from "../LegacyRemoveMemberService";
import { PBACRemoveMemberService } from "../PBACRemoveMemberService";
import { RemoveMemberServiceFactory } from "../RemoveMemberServiceFactory";
@@ -10,6 +8,11 @@ vi.mock("@calcom/features/flags/features.repository");
vi.mock("../LegacyRemoveMemberService");
vi.mock("../PBACRemoveMemberService");
+vi.mock("@calcom/prisma", () => ({
+ default: {},
+ prisma: {},
+}));
+
describe("RemoveMemberServiceFactory", () => {
let mockFeaturesRepository: {
checkIfTeamHasFeature: vi.Mock;
diff --git a/packages/trpc/server/routers/viewer/workflows/sendVerificationCode.handler.test.ts b/packages/trpc/server/routers/viewer/workflows/sendVerificationCode.handler.test.ts
index 2dc7f06b826..457b9e29a90 100644
--- a/packages/trpc/server/routers/viewer/workflows/sendVerificationCode.handler.test.ts
+++ b/packages/trpc/server/routers/viewer/workflows/sendVerificationCode.handler.test.ts
@@ -1,11 +1,8 @@
-import { describe, it, expect, vi, beforeEach } from "vitest";
-
import { CreditsRepository } from "@calcom/features/credits/repositories/CreditsRepository";
import { sendVerificationCode } from "@calcom/features/ee/workflows/lib/reminders/verifyPhoneNumber";
import { checkRateLimitAndThrowError } from "@calcom/lib/checkRateLimitAndThrowError";
-
import { TRPCError } from "@trpc/server";
-
+import { beforeEach, describe, expect, it, vi } from "vitest";
import { hasTeamPlanHandler } from "../teams/hasTeamPlan.handler";
import { sendVerificationCodeHandler } from "./sendVerificationCode.handler";
@@ -14,6 +11,11 @@ vi.mock("@calcom/features/credits/repositories/CreditsRepository");
vi.mock("@calcom/features/ee/workflows/lib/reminders/verifyPhoneNumber");
vi.mock("../teams/hasTeamPlan.handler");
+vi.mock("@calcom/prisma", () => ({
+ default: {},
+ prisma: {},
+}));
+
describe("sendVerificationCodeHandler", () => {
const mockUser = {
id: 123,