fix: add missing vi.mock() calls to prevent vitest worker shutdown flakiness (#28459)
* fix: add missing vi.mock() calls to prevent vitest worker shutdown flakiness
Add vi.mock() calls for modules that trigger background network requests
or database connections during import. These transitive imports can cause
the vitest worker RPC to shut down while pending fetch/network operations
are still in flight, resulting in flaky test failures with:
Error: [vitest-worker]: Closing rpc while "fetch" was pending
The primary modules mocked are:
- @calcom/app-store/delegationCredential (triggers credential lookups)
- @calcom/prisma (triggers database initialization)
- @calcom/features/calendars/lib/CalendarManager (triggers calendar API calls)
- @calcom/features/auth/lib/verifyEmail (triggers email service)
- @calcom/lib/domainManager/organization (triggers domain lookups)
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
* fix: remove conflicting empty prisma mocks from files with prismock/prismaMock setups
- Remove vi.mock('@calcom/prisma', () => ({ default: {}, prisma: {} })) from 28 files
that already have prismock/prismaMock test doubles. Vitest hoists all vi.mock() calls
and the last one wins, so these empty mocks were overriding the functional test doubles.
- Fix CalendarSubscriptionService.test.ts to reuse the shared mock from
__mocks__/delegationCredential instead of creating a new unconfigured vi.fn()
- Remove DelegationCredentialRepository.test.ts empty prisma mock (different pattern)
- Remove vi.mock from inside beforeEach in intentToCreateOrg.handler.test.ts
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
* fix: add comprehensive delegationCredential mock exports to prevent CI test failures
The vi.mock blocks for @calcom/app-store/delegationCredential were missing
exports that the code under test transitively imports (e.g.
enrichUsersWithDelegationCredentials, enrichUserWithDelegationCredentialsIncludeServiceAccountKey,
buildAllCredentials, getFirstDelegationConferencingCredentialAppLocation).
Added all exports with passthrough implementations so the booking flow
works correctly without triggering real network requests.
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
* fix: correct credential mock return shapes to match real module API
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
* fix: revert unintended yarn.lock changes
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
---------
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
353f71bdc6
commit
4291a59b2c
70 files changed
+561
-271
No files matched your search
@@ -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 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 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 { getTeamIdFromEventType } from "@calcom/lib/getTeamIdFromEventType";
|
||||
import type { TraceContext } from "@calcom/lib/tracing";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
describe("handlePaymentSuccess", () => {
|
||||
const mockBookingId = 1;
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
@@ -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();
|
||||
|
||||
+7
-4
@@ -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,
|
||||
|
||||
+5
@@ -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: {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
+3
-6
@@ -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({
|
||||
|
||||
@@ -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,
|
||||
|
||||
+23
-2
@@ -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",
|
||||
|
||||
+8
-5
@@ -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();
|
||||
|
||||
@@ -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", () => {
|
||||
|
||||
@@ -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", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
@@ -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");
|
||||
|
||||
|
||||
+9
@@ -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";
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 = {
|
||||
email: "[email protected]",
|
||||
username: "test-user",
|
||||
|
||||
+8
-9
@@ -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]",
|
||||
|
||||
+5
@@ -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: {
|
||||
|
||||
@@ -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: "" }];
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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";
|
||||
|
||||
|
||||
+19
-2
@@ -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";
|
||||
|
||||
|
||||
+2
-6
@@ -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) => {
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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 };
|
||||
|
||||
@@ -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 };
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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", () => {
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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";
|
||||
|
||||
+1
-4
@@ -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">;
|
||||
|
||||
+3
-7
@@ -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);
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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", () => {
|
||||
|
||||
+1
-5
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
+6
-3
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
+2
-7
@@ -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;
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
+6
-3
@@ -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> };
|
||||
|
||||
+7
-4
@@ -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: {
|
||||
|
||||
+6
-3
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user