chore: upgrade Vitest to 4.0.16 and Vite to 6.4.1 (#26351)
* chore: upgrade Vitest to 4.0.16 and Vite to 6.4.1 - Update vitest from 2.1.9 to 4.0.16 - Update @vitest/ui from 2.1.9 to 4.0.16 - Update vitest-fetch-mock from 0.3.0 to 0.4.5 - Update vitest-mock-extended from 2.0.2 to 3.1.0 - Update vite from 4.5.14/5.4.21 to 6.4.1 across all packages - Update @vitejs/plugin-react to 5.1.2 - Update @vitejs/plugin-react-swc to 4.2.2 - Update @vitejs/plugin-basic-ssl to 2.1.0 - Update vite-plugin-dts to 4.5.4 - Rename vitest.config.ts to vitest.config.mts for ESM compatibility - Add globals: true to vitest config Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * fix: address Vitest 4.0 and Vite 6 breaking changes - Convert arrow function mockImplementation patterns to regular functions (Vitest 4.0 breaking change: arrow functions can't be constructor mocks) - Fix CSS imports with ?inline suffix for Vite 6 compatibility - Add biome override to disable useArrowFunction rule for test files - Fix syntax errors in test files introduced by regex replacements Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * fix: fix remaining Vitest 4.0 constructor mock patterns Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * fix: fix more Vitest 4.0 constructor mock patterns and exclude API v2 spec files Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * fix: convert more arrow function mocks to regular functions for Vitest 4.0 Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * fix: convert more arrow function mocks to regular functions for Vitest 4.0 - Fix CrmService.integration.test.ts jsforce.Connection mock - Fix RetellSDKClient.test.ts Retell mock - Fix RetellAIService.test.ts CreditService mocks - Fix GoogleCalendarSubscriptionAdapter.test.ts CalendarAuth mock Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * fix: convert Google Calendar and OAuthManager arrow function mocks for Vitest 4.0 - Fix googleapis.ts Calendar, OAuth2Client, and JWT mocks - Fix utils.ts JWT mock - Fix OAuthManager.ts defaultMockOAuthManager mock Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * fix: add React plugin, jsdom environment, and fix more constructor mocks for Vitest 4.0 Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * fix: convert HostRepository PrismaClient mock to regular function for Vitest 4.0 Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * fix: add useOrgBranding mock to React component tests for Vitest 4.0 Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * fix: update TestFunction type for Vitest 4.0 compatibility Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * fix: convert listBookingReports constructor mocks to regular functions for Vitest 4.0 Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * fix: convert UserRepository constructor mock to regular function for Vitest 4.0 Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * fix: convert OrganizationPaymentService constructor mock to regular function for Vitest 4.0 Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * fix: convert more constructor mocks to regular functions for Vitest 4.0 Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * fix: add apps/web path aliases to vitest config Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * fix: fix test issues for Vitest 4.0 compatibility - Fix Response constructor 204 status code issue in testUtils.ts - Fix FeaturesRepository mock persistence in handleNotificationWhenNoSlots.test.ts - Add @vitest-environment node directive to formSubmissionUtils.test.ts - Fix document.querySelector mock in embed.test.ts Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * fix: clear EventManager spy between tests for Vitest 4.0 compatibility Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * fix: update TeamRepository mock pattern for Vitest 4.0 compatibility Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * fix: convert RoutingFormResponseRepository mock to regular function for Vitest 4.0 Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * fix: convert more constructor mocks to regular functions for Vitest 4.0 Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * fix: fix mock reset and spy clear issues for Vitest 4.0 Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * fix: fix remaining test failures for Vitest 4.0 upgrade - Fix booking-validations.test.ts: convert UserRepository mock to regular function - Fix route.test.ts: update 500 error test to mock ImageResponse instead of fetch - Fix users-public-view.test.tsx: add missing mocks for getOrgFullOrigin and useRouterQuery - Add @calcom/web path alias to vitest config Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * fix: add vitest-mocks for generated files that don't exist in CI - Add svg-hashes.json mock for route.test.ts - Add tailwind.generated.css mock for embed.test.ts - Update vitest config to use mock files Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * fix: update vitest config aliases for CI compatibility - Use array format for aliases to ensure proper ordering - Add @calcom/platform-constants alias to resolve from source - Add @calcom/embed-react alias to resolve from source - Ensure svg-hashes.json mock alias is matched before @calcom/web Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * fix: add @calcom/embed-snippet alias for CI compatibility Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * Fix wrong test * fix: migrate from CLI flags to VITEST_MODE env var for Vitest 4.0 Vitest 4.0 no longer allows custom CLI flags like --packaged-embed-tests-only. This change migrates to using VITEST_MODE environment variable instead: - VITEST_MODE=packaged-embed for packaged embed tests - VITEST_MODE=integration for integration tests - VITEST_MODE=timezone for timezone-dependent tests Updated vitest.config.mts to handle mode-based include/exclude patterns. Updated CI workflows and package scripts to use the new env var approach. Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * fix: return default include pattern instead of undefined in vitest config The getTestInclude() function was returning undefined for the default case, but Vitest 4.0 expects an array. This caused 'resolved.include is not iterable' error in CI. Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * fix: always set INTEGRATION_TEST_MODE for jsdom environment The getBookingFields.ts file checks for INTEGRATION_TEST_MODE to allow server-side imports in the jsdom environment. Without this, tests fail with 'getBookingFields must not be imported on the client side' error. Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> * fix: support legacy CLI flags for backwards compatibility with main workflow The CI runs workflows from main branch, which uses the old CLI flag approach (yarn test -- --integrationTestsOnly). This commit adds backwards compatibility by checking both VITEST_MODE env var and process.argv for the legacy flags. Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
@@ -83,7 +83,7 @@ jobs:
|
||||
- uses: ./.github/actions/yarn-install
|
||||
- uses: ./.github/actions/cache-db
|
||||
- name: Run Tests
|
||||
run: yarn test -- --integrationTestsOnly
|
||||
run: VITEST_MODE=integration yarn test
|
||||
# TODO: Generate test results so we can upload them
|
||||
# - name: Upload Test Results
|
||||
# if: ${{ always() }}
|
||||
|
||||
@@ -16,4 +16,4 @@ jobs:
|
||||
- uses: ./.github/actions/yarn-install
|
||||
- run: yarn test -- --no-isolate
|
||||
# We could add different timezones here that we need to run our tests in
|
||||
- run: TZ=America/Los_Angeles yarn test -- --timeZoneDependentTestsOnly --no-isolate
|
||||
- run: TZ=America/Los_Angeles VITEST_MODE=timezone yarn test -- --no-isolate
|
||||
|
||||
@@ -73,8 +73,8 @@ describe("Verify API key - Unit Tests", () => {
|
||||
verifyKeyByHashedKey: vi.fn(),
|
||||
} as unknown as ApiKeyService;
|
||||
|
||||
vi.mocked(ApiKeyService).mockImplementation(() => mockApiKeyService);
|
||||
vi.mocked(PrismaApiKeyRepository).mockImplementation(() => ({} as unknown as PrismaApiKeyRepository));
|
||||
vi.mocked(ApiKeyService).mockImplementation(function() { return mockApiKeyService; });
|
||||
vi.mocked(PrismaApiKeyRepository).mockImplementation(function() { return {} as unknown as PrismaApiKeyRepository; });
|
||||
|
||||
vi.mocked(isAdminGuard).mockReset();
|
||||
vi.mocked(isLockedOrBlocked).mockReset();
|
||||
|
||||
@@ -67,9 +67,9 @@ vi.mock("@calcom/features/webhooks/lib/sendOrSchedulePayload", () => ({
|
||||
|
||||
const mockFindOriginalRescheduledBooking = vi.fn();
|
||||
vi.mock("@calcom/features/bookings/repositories/BookingRepository", () => ({
|
||||
BookingRepository: vi.fn().mockImplementation(() => ({
|
||||
BookingRepository: vi.fn().mockImplementation(function() { return {
|
||||
findOriginalRescheduledBooking: mockFindOriginalRescheduledBooking,
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/features/watchlist/operations/check-if-users-are-blocked.controller", () => ({
|
||||
@@ -87,7 +87,8 @@ vi.mock("@calcom/features/di/containers/QualifiedHosts", () => ({
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/features/bookings/lib/EventManager", () => ({
|
||||
default: vi.fn().mockImplementation(() => ({
|
||||
default: vi.fn().mockImplementation(function() {
|
||||
return {
|
||||
reschedule: vi.fn().mockResolvedValue({
|
||||
results: [],
|
||||
referencesToCreate: [],
|
||||
@@ -103,7 +104,8 @@ vi.mock("@calcom/features/bookings/lib/EventManager", () => ({
|
||||
createAllCalendarEvents: vi.fn().mockResolvedValue([]),
|
||||
updateAllCalendarEvents: vi.fn().mockResolvedValue([]),
|
||||
deleteEventsAndMeetings: vi.fn().mockResolvedValue([]),
|
||||
})),
|
||||
};
|
||||
}),
|
||||
placeholderCreatedEvent: {
|
||||
results: [],
|
||||
referencesToCreate: [],
|
||||
@@ -146,10 +148,10 @@ vi.mock("@calcom/features/profile/repositories/ProfileRepository", () => ({
|
||||
},
|
||||
}));
|
||||
vi.mock("@calcom/features/flags/features.repository", () => ({
|
||||
FeaturesRepository: vi.fn().mockImplementation(() => ({
|
||||
FeaturesRepository: vi.fn().mockImplementation(function() { return {
|
||||
checkIfFeatureIsEnabledGlobally: vi.fn().mockResolvedValue(false),
|
||||
checkIfTeamHasFeature: vi.fn().mockResolvedValue(false),
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/features/webhooks/lib/getWebhooks", () => ({
|
||||
|
||||
@@ -35,9 +35,9 @@ vi.mock("@calcom/features/watchlist/operations/check-if-email-in-watchlist.contr
|
||||
|
||||
const mockCreate = vi.fn();
|
||||
vi.mock("@calcom/features/users/repositories/UserRepository", () => ({
|
||||
UserRepository: vi.fn().mockImplementation(() => ({
|
||||
UserRepository: vi.fn().mockImplementation(function() { return {
|
||||
create: mockCreate,
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/lib/auth/hashPassword", () => ({
|
||||
|
||||
@@ -11,9 +11,9 @@ import { handleCreateSelectedCalendars, isSameEmail } from "../route";
|
||||
const getPrimaryCalendarMock = vi.fn();
|
||||
vi.mock("@calcom/app-store/googlecalendar/lib/CalendarService", () => {
|
||||
return {
|
||||
default: vi.fn().mockImplementation(() => ({
|
||||
default: vi.fn().mockImplementation(function() { return {
|
||||
getPrimaryCalendar: getPrimaryCalendarMock,
|
||||
})),
|
||||
}; }),
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -50,9 +50,9 @@ const mockQueuedFormResponse = {
|
||||
|
||||
describe("queuedResponseHandler", () => {
|
||||
beforeEach(() => {
|
||||
vi.mocked(RoutingFormResponseRepository).mockImplementation(
|
||||
() => mockRoutingFormResponseRepository as any
|
||||
);
|
||||
vi.mocked(RoutingFormResponseRepository).mockImplementation(function () {
|
||||
return mockRoutingFormResponseRepository as any;
|
||||
});
|
||||
});
|
||||
|
||||
it("should process a queued form response", async () => {
|
||||
|
||||
@@ -6,14 +6,14 @@ import { getOGImageVersion } from "@calcom/lib/OgImages";
|
||||
import { GET } from "../route";
|
||||
|
||||
vi.mock("next/og", () => ({
|
||||
ImageResponse: vi.fn().mockImplementation(() => ({
|
||||
ImageResponse: vi.fn().mockImplementation(function() { return {
|
||||
body: new ReadableStream({
|
||||
start(controller) {
|
||||
controller.enqueue(new Uint8Array([1, 2, 3, 4]));
|
||||
controller.close();
|
||||
},
|
||||
}),
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/lib/OgImages", async (importOriginal) => {
|
||||
@@ -102,8 +102,11 @@ describe("GET /api/social/og/image", () => {
|
||||
});
|
||||
|
||||
describe("Server errors (500 Internal Server Error)", () => {
|
||||
test("returns 500 when font loading fails", async () => {
|
||||
vi.mocked(global.fetch).mockRejectedValue(new Error("Font loading failed"));
|
||||
test("returns 500 when ImageResponse throws", async () => {
|
||||
const { ImageResponse } = await import("next/og");
|
||||
vi.mocked(ImageResponse).mockImplementation(function () {
|
||||
throw new Error("ImageResponse failed");
|
||||
});
|
||||
|
||||
const request = createNextRequest(
|
||||
"http://example.com/api/social/og/image?type=meeting&title=Test&meetingProfileName=John"
|
||||
|
||||
@@ -76,10 +76,10 @@ const mockSendCreditBalanceLimitReachedEmails = vi.fn();
|
||||
const mockSendCreditBalanceLowWarningEmails = vi.fn();
|
||||
|
||||
vi.mock("@calcom/features/ee/billing/credit-service", () => ({
|
||||
CreditService: vi.fn().mockImplementation(() => ({
|
||||
CreditService: vi.fn().mockImplementation(function() { return {
|
||||
hasAvailableCredits: mockHasAvailableCredits,
|
||||
chargeCredits: mockChargeCredits,
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/emails/email-manager", () => ({
|
||||
@@ -92,15 +92,15 @@ const mockFindByPhoneNumber = vi.fn();
|
||||
const mockFindByProviderAgentId = vi.fn();
|
||||
|
||||
vi.mock("@calcom/features/calAIPhone/repositories/PrismaPhoneNumberRepository", () => ({
|
||||
PrismaPhoneNumberRepository: vi.fn().mockImplementation(() => ({
|
||||
PrismaPhoneNumberRepository: vi.fn().mockImplementation(function() { return {
|
||||
findByPhoneNumber: mockFindByPhoneNumber,
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/features/calAIPhone/repositories/PrismaAgentRepository", () => ({
|
||||
PrismaAgentRepository: vi.fn().mockImplementation(() => ({
|
||||
PrismaAgentRepository: vi.fn().mockImplementation(function() { return {
|
||||
findByProviderAgentId: mockFindByProviderAgentId,
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
vi.mock("next/server", () => ({
|
||||
|
||||
@@ -89,6 +89,10 @@ vi.mock("@calcom/lib/hooks/useLocale", () => ({
|
||||
useLocale: vi.fn(() => ({ t: (key: string) => key })),
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/features/ee/organizations/context/provider", () => ({
|
||||
useOrgBranding: vi.fn(() => null),
|
||||
}));
|
||||
|
||||
let findTeamMembersMatchingAttributeLogicResponse: {
|
||||
result: { users: { email: string }[] } | null;
|
||||
checkedFallback: boolean;
|
||||
|
||||
@@ -85,6 +85,10 @@ vi.mock("@calcom/lib/hooks/useLocale", () => ({
|
||||
useLocale: vi.fn(() => ({ t: (key: string) => key })),
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/features/ee/organizations/context/provider", () => ({
|
||||
useOrgBranding: vi.fn(() => null),
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/web/lib/hooks/useRouterQuery", () => ({
|
||||
default: vi.fn(() => {
|
||||
return {
|
||||
|
||||
@@ -10,6 +10,14 @@ vi.mock("@calcom/lib/constants", async () => {
|
||||
return await vi.importActual("@calcom/lib/constants");
|
||||
});
|
||||
|
||||
vi.mock("@calcom/ee/organizations/lib/orgDomains", () => ({
|
||||
getOrgFullOrigin: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/lib/hooks/useRouterQuery", () => ({
|
||||
useRouterQuery: vi.fn(),
|
||||
}));
|
||||
|
||||
function mockedUserPageComponentProps(props: Partial<React.ComponentProps<typeof UserPage>>) {
|
||||
return {
|
||||
themeBasis: "dark",
|
||||
|
||||
@@ -7,9 +7,9 @@ import { validateIntervalLimitOrder } from "@calcom/lib/intervalLimits/validateI
|
||||
|
||||
const mockCountBookingsByEventTypeAndDateRange = vi.fn();
|
||||
vi.mock("@calcom/features/bookings/repositories/BookingRepository", () => ({
|
||||
BookingRepository: vi.fn().mockImplementation(() => ({
|
||||
BookingRepository: vi.fn().mockImplementation(function() { return {
|
||||
countBookingsByEventTypeAndDateRange: mockCountBookingsByEventTypeAndDateRange,
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
type Mockdata = {
|
||||
|
||||
@@ -6,9 +6,9 @@ import { validateIntervalLimitOrder } from "@calcom/lib/intervalLimits/validateI
|
||||
|
||||
const mockGetTotalBookingDuration = vi.fn();
|
||||
vi.mock("@calcom/features/bookings/repositories/BookingRepository", () => ({
|
||||
BookingRepository: vi.fn().mockImplementation(() => ({
|
||||
BookingRepository: vi.fn().mockImplementation(function() { return {
|
||||
getTotalBookingDuration: mockGetTotalBookingDuration,
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
type MockData = {
|
||||
|
||||
@@ -18,13 +18,15 @@ import { setupAndTeardown } from "./setupAndTeardown";
|
||||
|
||||
// Mock the FeaturesRepository to enable restriction-schedule feature
|
||||
vi.mock("@calcom/features/flags/features.repository", () => ({
|
||||
FeaturesRepository: vi.fn().mockImplementation(() => ({
|
||||
FeaturesRepository: vi.fn().mockImplementation(function() {
|
||||
return {
|
||||
checkIfTeamHasFeature: vi.fn().mockResolvedValue(true),
|
||||
checkIfFeatureIsEnabledGlobally: vi.fn().mockResolvedValue(true),
|
||||
getAllFeatures: vi.fn().mockResolvedValue([]),
|
||||
getFeatureFlagMap: vi.fn().mockResolvedValue({}),
|
||||
checkIfUserHasFeature: vi.fn().mockResolvedValue(true),
|
||||
})),
|
||||
};
|
||||
}),
|
||||
}));
|
||||
|
||||
type ScheduleScenario = {
|
||||
|
||||
@@ -1,39 +1,39 @@
|
||||
import { createOrganization } from "@calcom/web/test/utils/bookingScenario/bookingScenario";
|
||||
|
||||
import type { TestFunction } from "vitest";
|
||||
|
||||
import { WEBSITE_URL } from "@calcom/lib/constants";
|
||||
import { test } from "@calcom/web/test/fixtures/fixtures";
|
||||
import type { Fixtures } from "@calcom/web/test/fixtures/fixtures";
|
||||
|
||||
type OrgContext = {
|
||||
org: {
|
||||
organization: { id: number | null };
|
||||
urlOrigin?: string;
|
||||
} | null;
|
||||
};
|
||||
|
||||
const WEBSITE_PROTOCOL = new URL(WEBSITE_URL).protocol;
|
||||
const _testWithAndWithoutOrg = (
|
||||
description: Parameters<typeof testWithAndWithoutOrg>[0],
|
||||
fn: Parameters<typeof testWithAndWithoutOrg>[1],
|
||||
timeout: Parameters<typeof testWithAndWithoutOrg>[2],
|
||||
description: string,
|
||||
fn: (context: Fixtures & OrgContext) => Promise<void> | void,
|
||||
timeout: number | undefined,
|
||||
mode: "only" | "skip" | "run" = "run"
|
||||
) => {
|
||||
): void => {
|
||||
const t = mode === "only" ? test.only : mode === "skip" ? test.skip : test;
|
||||
t(
|
||||
`${description} - With org`,
|
||||
async ({ emails, sms, task, onTestFailed, expect, skip, onTestFinished }) => {
|
||||
async ({ emails, sms }) => {
|
||||
const org = await createOrganization({
|
||||
name: "Test Org",
|
||||
slug: "testorg",
|
||||
});
|
||||
|
||||
await fn({
|
||||
task,
|
||||
onTestFailed,
|
||||
expect,
|
||||
emails,
|
||||
sms,
|
||||
skip,
|
||||
org: {
|
||||
organization: org,
|
||||
urlOrigin: `${WEBSITE_PROTOCOL}//${org.slug}.cal.local:3000`,
|
||||
},
|
||||
onTestFinished,
|
||||
});
|
||||
},
|
||||
timeout
|
||||
@@ -41,41 +41,31 @@ const _testWithAndWithoutOrg = (
|
||||
|
||||
t(
|
||||
`${description}`,
|
||||
async ({ emails, sms, task, onTestFailed, expect, skip, onTestFinished }) => {
|
||||
async ({ emails, sms }) => {
|
||||
await fn({
|
||||
emails,
|
||||
sms,
|
||||
task,
|
||||
onTestFailed,
|
||||
expect,
|
||||
skip,
|
||||
org: null,
|
||||
onTestFinished,
|
||||
});
|
||||
},
|
||||
timeout
|
||||
);
|
||||
};
|
||||
|
||||
type TestFunctionWithOrg = (context: Fixtures & OrgContext) => Promise<void> | void;
|
||||
|
||||
export const testWithAndWithoutOrg = (
|
||||
description: string,
|
||||
fn: TestFunction<
|
||||
Fixtures & {
|
||||
org: {
|
||||
organization: { id: number | null };
|
||||
urlOrigin?: string;
|
||||
} | null;
|
||||
}
|
||||
>,
|
||||
fn: TestFunctionWithOrg,
|
||||
timeout?: number
|
||||
) => {
|
||||
): void => {
|
||||
_testWithAndWithoutOrg(description, fn, timeout, "run");
|
||||
};
|
||||
|
||||
testWithAndWithoutOrg.only = ((description, fn, timeout) => {
|
||||
testWithAndWithoutOrg.only = ((description: string, fn: TestFunctionWithOrg, timeout?: number): void => {
|
||||
_testWithAndWithoutOrg(description, fn, timeout, "only");
|
||||
}) as typeof _testWithAndWithoutOrg;
|
||||
}) as typeof testWithAndWithoutOrg;
|
||||
|
||||
testWithAndWithoutOrg.skip = ((description, fn, timeout) => {
|
||||
testWithAndWithoutOrg.skip = ((description: string, fn: TestFunctionWithOrg, timeout?: number): void => {
|
||||
_testWithAndWithoutOrg(description, fn, timeout, "skip");
|
||||
}) as typeof _testWithAndWithoutOrg;
|
||||
}) as typeof testWithAndWithoutOrg;
|
||||
|
||||
+11
-5
@@ -69,6 +69,16 @@
|
||||
}
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
"includes": ["**/*.test.ts", "**/*.test.tsx"],
|
||||
"linter": {
|
||||
"rules": {
|
||||
"complexity": {
|
||||
"useArrowFunction": "off"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"includes": ["**/*.tsx"],
|
||||
"javascript": {
|
||||
@@ -76,11 +86,7 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"includes": [
|
||||
"apps/web/app/**/page.tsx",
|
||||
"apps/web/app/**/layout.tsx",
|
||||
"apps/web/app/pages/**/*.tsx"
|
||||
],
|
||||
"includes": ["apps/web/app/**/page.tsx", "apps/web/app/**/layout.tsx", "apps/web/app/pages/**/*.tsx"],
|
||||
"linter": {
|
||||
"rules": {
|
||||
"style": {
|
||||
|
||||
+4
-4
@@ -95,7 +95,7 @@
|
||||
"@snaplet/copycat": "4.1.0",
|
||||
"@testing-library/jest-dom": "5.17.0",
|
||||
"@testing-library/react": "16.0.1",
|
||||
"@vitest/ui": "2.1.9",
|
||||
"@vitest/ui": "4.0.16",
|
||||
"c8": "7.13.0",
|
||||
"checkly": "latest",
|
||||
"dotenv-checker": "1.1.5",
|
||||
@@ -113,9 +113,9 @@
|
||||
"tsc-absolute": "1.0.0",
|
||||
"turbo": "2.7.1",
|
||||
"typescript": "5.9.3",
|
||||
"vitest": "2.1.9",
|
||||
"vitest-fetch-mock": "0.3.0",
|
||||
"vitest-mock-extended": "2.0.2"
|
||||
"vitest": "4.0.16",
|
||||
"vitest-fetch-mock": "0.4.5",
|
||||
"vitest-mock-extended": "3.1.0"
|
||||
},
|
||||
"resolutions": {
|
||||
"types-ramda": "0.29.4",
|
||||
|
||||
@@ -32,7 +32,9 @@ export function generateTextResponse({
|
||||
status?: number;
|
||||
statusText?: string;
|
||||
}) {
|
||||
return new Response(text, {
|
||||
// Status 204 (No Content) doesn't allow a body, so pass null for body
|
||||
const body = status === 204 ? null : text;
|
||||
return new Response(body, {
|
||||
status: status,
|
||||
statusText: statusText,
|
||||
});
|
||||
|
||||
@@ -32,7 +32,7 @@ const calendarMockImplementation = {
|
||||
|
||||
const calendarMock = {
|
||||
calendar_v3: {
|
||||
Calendar: vi.fn().mockImplementation(() => calendarMockImplementation),
|
||||
Calendar: vi.fn().mockImplementation(function() { return calendarMockImplementation; }),
|
||||
},
|
||||
};
|
||||
const adminMock = {
|
||||
@@ -88,7 +88,7 @@ vi.mock("googleapis-common", async () => {
|
||||
const actual = await vi.importActual("googleapis-common");
|
||||
return {
|
||||
...actual,
|
||||
OAuth2Client: vi.fn().mockImplementation((...args: [string, string, string]) => {
|
||||
OAuth2Client: vi.fn().mockImplementation(function(...args: [string, string, string]) {
|
||||
lastCreatedOAuth2Client = {
|
||||
type: "oauth2",
|
||||
args,
|
||||
@@ -104,7 +104,7 @@ vi.mock("googleapis-common", async () => {
|
||||
};
|
||||
return lastCreatedOAuth2Client;
|
||||
}),
|
||||
JWT: vi.fn().mockImplementation((config: MockJWT["config"]) => {
|
||||
JWT: vi.fn().mockImplementation(function(config: MockJWT["config"]) {
|
||||
lastCreatedJWT = {
|
||||
type: "jwt",
|
||||
config,
|
||||
|
||||
@@ -177,7 +177,7 @@ export const createMockJWTInstance = ({
|
||||
createGToken: vi.fn(),
|
||||
};
|
||||
|
||||
vi.mocked(JWT).mockImplementation(() => {
|
||||
vi.mocked(JWT).mockImplementation(function() {
|
||||
setLastCreatedJWT(mockJWTInstance);
|
||||
return mockJWTInstance as unknown as JWT;
|
||||
});
|
||||
|
||||
@@ -34,7 +34,7 @@ vi.mock("../../_utils/getParsedAppKeysFromSlug", () => ({
|
||||
|
||||
const mockRequestRaw = vi.fn();
|
||||
vi.mock("../../_utils/oauth/OAuthManager", () => ({
|
||||
OAuthManager: vi.fn().mockImplementation(() => {
|
||||
OAuthManager: vi.fn().mockImplementation(function() {
|
||||
return { requestRaw: mockRequestRaw };
|
||||
}),
|
||||
}));
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
/**
|
||||
* @vitest-environment node
|
||||
*/
|
||||
import "@calcom/lib/__mocks__/logger";
|
||||
import { prisma } from "@calcom/prisma/__mocks__/prisma";
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ vi.mock("@calcom/lib/constants", () => {
|
||||
vi.mock("@jsforce/jsforce-node", () => {
|
||||
return {
|
||||
default: {
|
||||
Connection: vi.fn().mockImplementation(() => ({})),
|
||||
Connection: vi.fn().mockImplementation(function() { return {}; }),
|
||||
},
|
||||
};
|
||||
});
|
||||
@@ -116,13 +116,15 @@ describe("SalesforceCRMService", () => {
|
||||
// Override jsforce mock with our custom mock
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore - Not full implementation of jsforce.Connection
|
||||
vi.mocked(jsforce.Connection).mockImplementation(() => ({
|
||||
vi.mocked(jsforce.Connection).mockImplementation(function() {
|
||||
return {
|
||||
...salesforceMock.mockConnection,
|
||||
version: "1.0",
|
||||
loginUrl: "https://test.salesforce.com",
|
||||
instanceUrl: "https://test.salesforce.com",
|
||||
accessToken: "123",
|
||||
}));
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
describe("createOnLeadAndSearchOnAccount", () => {
|
||||
|
||||
@@ -20,11 +20,15 @@ vi.mock("@calcom/prisma", () => ({
|
||||
|
||||
vi.mock("../../lib/getCustomerAndCheckoutSession");
|
||||
vi.mock("@calcom/features/auth/lib/sendVerificationRequest");
|
||||
vi.mock("@calcom/lib/server/service/VerificationTokenService");
|
||||
vi.mock("@calcom/lib/server/service/VerificationTokenService", () => ({
|
||||
VerificationTokenService: {
|
||||
create: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
const mockGetCustomerAndCheckoutSession = vi.mocked(getCustomerAndCheckoutSession);
|
||||
const mockSendVerificationRequest = vi.mocked(sendVerificationRequest);
|
||||
const mockVerificationTokenService = vi.mocked(VerificationTokenService);
|
||||
const mockVerificationTokenServiceCreate = vi.mocked(VerificationTokenService.create);
|
||||
|
||||
// Type the mocked prisma properly
|
||||
const mockPrisma = prisma as unknown as {
|
||||
@@ -84,7 +88,7 @@ describe("paymentCallback", () => {
|
||||
username: "premium-user",
|
||||
} as any); // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
|
||||
mockVerificationTokenService.create.mockResolvedValue("test-token-123");
|
||||
mockVerificationTokenServiceCreate.mockResolvedValue("test-token-123");
|
||||
mockSendVerificationRequest.mockResolvedValue(undefined);
|
||||
});
|
||||
|
||||
@@ -94,12 +98,12 @@ describe("paymentCallback", () => {
|
||||
|
||||
await handler(mockReq as NextApiRequest, mockRes as NextApiResponse);
|
||||
|
||||
expect(mockVerificationTokenService.create).toHaveBeenCalledWith({
|
||||
expect(mockVerificationTokenServiceCreate).toHaveBeenCalledWith({
|
||||
identifier: "test@example.com",
|
||||
expires: expect.any(Date),
|
||||
});
|
||||
|
||||
const callArgs = mockVerificationTokenService.create.mock.calls[0][0];
|
||||
const callArgs = mockVerificationTokenServiceCreate.mock.calls[0][0];
|
||||
const expiresDate = callArgs.expires;
|
||||
const now = Date.now();
|
||||
const oneDayInMs = 86400 * 1000;
|
||||
@@ -124,7 +128,7 @@ describe("paymentCallback", () => {
|
||||
const { default: handler } = await import("../paymentCallback");
|
||||
const callOrder: string[] = [];
|
||||
|
||||
mockVerificationTokenService.create.mockImplementation(async () => {
|
||||
mockVerificationTokenServiceCreate.mockImplementation(async function () {
|
||||
callOrder.push("create-token");
|
||||
return "test-token";
|
||||
});
|
||||
@@ -154,7 +158,7 @@ describe("paymentCallback", () => {
|
||||
|
||||
await handler(mockReq as NextApiRequest, mockRes as NextApiResponse);
|
||||
|
||||
expect(mockVerificationTokenService.create).not.toHaveBeenCalled();
|
||||
expect(mockVerificationTokenServiceCreate).not.toHaveBeenCalled();
|
||||
expect(mockSendVerificationRequest).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -173,7 +177,7 @@ describe("paymentCallback", () => {
|
||||
|
||||
await handler(mockReq as NextApiRequest, mockRes as NextApiResponse);
|
||||
|
||||
expect(mockVerificationTokenService.create).toHaveBeenCalledWith({
|
||||
expect(mockVerificationTokenServiceCreate).toHaveBeenCalledWith({
|
||||
identifier: "different@example.com", // Should use user.email from found user
|
||||
expires: expect.any(Date),
|
||||
});
|
||||
@@ -188,7 +192,7 @@ describe("paymentCallback", () => {
|
||||
return {} as any; // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
});
|
||||
|
||||
mockVerificationTokenService.create.mockImplementation(async () => {
|
||||
mockVerificationTokenServiceCreate.mockImplementation(async function () {
|
||||
callOrder.push("create-token");
|
||||
return "token";
|
||||
});
|
||||
@@ -225,7 +229,7 @@ describe("paymentCallback", () => {
|
||||
expect((error as HttpError).statusCode).toBe(404);
|
||||
}
|
||||
|
||||
expect(mockVerificationTokenService.create).not.toHaveBeenCalled();
|
||||
expect(mockVerificationTokenServiceCreate).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should not create verification token when user is not found", async () => {
|
||||
@@ -240,7 +244,7 @@ describe("paymentCallback", () => {
|
||||
expect((error as HttpError).statusCode).toBe(404);
|
||||
}
|
||||
|
||||
expect(mockVerificationTokenService.create).not.toHaveBeenCalled();
|
||||
expect(mockVerificationTokenServiceCreate).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should use user email if stripe customer email is missing", async () => {
|
||||
@@ -257,7 +261,7 @@ describe("paymentCallback", () => {
|
||||
|
||||
await handler(mockReq as NextApiRequest, mockRes as NextApiResponse);
|
||||
|
||||
expect(mockVerificationTokenService.create).toHaveBeenCalledWith({
|
||||
expect(mockVerificationTokenServiceCreate).toHaveBeenCalledWith({
|
||||
identifier: "test@example.com", // Should use user.email
|
||||
expires: expect.any(Date),
|
||||
});
|
||||
|
||||
@@ -124,7 +124,9 @@ describe("Portal API - Service-Based Architecture", () => {
|
||||
mockTeamRepo = {
|
||||
findById: vi.fn(),
|
||||
};
|
||||
mockTeamRepository.mockImplementation(() => mockTeamRepo as unknown as TeamRepository);
|
||||
mockTeamRepository.mockImplementation(function () {
|
||||
return mockTeamRepo as unknown as TeamRepository;
|
||||
});
|
||||
});
|
||||
|
||||
it("should create OrganizationBillingPortalService for organizations", async () => {
|
||||
@@ -167,14 +169,16 @@ describe("Portal API - Service-Based Architecture", () => {
|
||||
checkPermission: vi.fn().mockResolvedValue(true),
|
||||
};
|
||||
|
||||
vi.mocked(PermissionCheckService).mockImplementation(
|
||||
() => mockPermissionServiceInstance as unknown as PermissionCheckService
|
||||
);
|
||||
vi.mocked(PermissionCheckService).mockImplementation(function () {
|
||||
return mockPermissionServiceInstance as unknown as PermissionCheckService;
|
||||
});
|
||||
|
||||
const mockTeamRepo: MockTeamRepository = {
|
||||
findById: vi.fn(),
|
||||
};
|
||||
mockTeamRepository.mockImplementation(() => mockTeamRepo as unknown as TeamRepository);
|
||||
mockTeamRepository.mockImplementation(function () {
|
||||
return mockTeamRepo as unknown as TeamRepository;
|
||||
});
|
||||
|
||||
service = new TeamBillingPortalService();
|
||||
});
|
||||
@@ -201,9 +205,9 @@ describe("Portal API - Service-Based Architecture", () => {
|
||||
checkPermission: vi.fn().mockResolvedValue(true),
|
||||
};
|
||||
|
||||
vi.mocked(PermissionCheckService).mockImplementation(
|
||||
() => mockPermissionServiceInstance as unknown as PermissionCheckService
|
||||
);
|
||||
vi.mocked(PermissionCheckService).mockImplementation(function () {
|
||||
return mockPermissionServiceInstance as unknown as PermissionCheckService;
|
||||
});
|
||||
|
||||
service = new OrganizationBillingPortalService();
|
||||
});
|
||||
|
||||
@@ -28,16 +28,16 @@ export default oAuthManagerMock;
|
||||
const setFullMockOAuthManagerRequest = () => {
|
||||
useFullMockOAuthManagerRequest = true;
|
||||
};
|
||||
const defaultMockOAuthManager = vi.fn().mockImplementation(() => {
|
||||
const defaultMockOAuthManager = vi.fn().mockImplementation(function() {
|
||||
return {
|
||||
getTokenObjectOrFetch: vi.fn().mockImplementation(() => {
|
||||
getTokenObjectOrFetch: vi.fn().mockImplementation(function() {
|
||||
return {
|
||||
token: {
|
||||
access_token: "FAKE_ACCESS_TOKEN",
|
||||
},
|
||||
};
|
||||
}),
|
||||
request: vi.fn().mockImplementation((fn) => {
|
||||
request: vi.fn().mockImplementation(function(fn) {
|
||||
if (useFullMockOAuthManagerRequest) {
|
||||
console.log("OAuthManager.request full mock being used");
|
||||
return oAuthManagerRequestFullMock(fn);
|
||||
|
||||
@@ -7,9 +7,9 @@ import { shouldSkipAttendeeEmailWithSettings, fetchOrganizationEmailSettings } f
|
||||
const mockGetEmailSettings = vi.fn();
|
||||
|
||||
vi.mock("@calcom/features/organizations/repositories/OrganizationSettingsRepository", () => ({
|
||||
OrganizationSettingsRepository: vi.fn().mockImplementation(() => ({
|
||||
OrganizationSettingsRepository: vi.fn().mockImplementation(function() { return {
|
||||
getEmailSettings: mockGetEmailSettings,
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/prisma", () => ({
|
||||
|
||||
@@ -45,13 +45,13 @@
|
||||
"@playwright/test": "1.57.0",
|
||||
"@tailwindcss/cli": "4.1.16",
|
||||
"@tailwindcss/postcss": "4.1.15",
|
||||
"@vitejs/plugin-basic-ssl": "1.1.0",
|
||||
"@vitejs/plugin-basic-ssl": "2.1.0",
|
||||
"autoprefixer": "10.4.19",
|
||||
"npm-run-all": "4.1.5",
|
||||
"postcss": "8.5.6",
|
||||
"tailwindcss": "4.1.17",
|
||||
"typescript": "5.9.3",
|
||||
"vite": "4.5.14",
|
||||
"vite": "6.4.1",
|
||||
"vite-plugin-environment": "1.1.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { EmbedElement } from "../EmbedElement";
|
||||
import { getErrorString } from "../lib/utils";
|
||||
import loaderCss from "../loader.css";
|
||||
import loaderCss from "../loader.css?inline";
|
||||
import modalBoxHtml, { getSkeletonData } from "./ModalBoxHtml";
|
||||
|
||||
export class ModalBox extends EmbedElement {
|
||||
|
||||
@@ -735,6 +735,9 @@ describe("Cal", () => {
|
||||
};
|
||||
// Reset document.querySelector mock before each test
|
||||
vi.restoreAllMocks();
|
||||
// Mock document.querySelector to return null by default (no existing modal)
|
||||
// This prevents isInFailedState from being true
|
||||
vi.spyOn(document, "querySelector").mockReturnValue(null);
|
||||
});
|
||||
|
||||
it("should return fullReload when cal link is different", () => {
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
EMBED_MODAL_PRERENDER_PREVENT_THRESHOLD_MS,
|
||||
} from "./constants";
|
||||
import type { InterfaceWithParent, interfaceWithParent } from "./embed-iframe";
|
||||
import css from "./embed.css";
|
||||
import css from "./embed.css?inline";
|
||||
import { getScrollableAncestor } from "./lib/domUtils";
|
||||
import { getScrollByDistanceHandler } from "./lib/eventHandlers/scrollByDistanceEventHandler";
|
||||
import {
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
"embed-tests": "yarn playwright test --config=./playwright/config/playwright.config.ts",
|
||||
"embed-tests-quick": "QUICK=true yarn embed-tests",
|
||||
"embed-tests-update-snapshots:ci": "yarn embed-tests-quick --update-snapshots",
|
||||
"packaged:tests": "cd test/packaged && yarn tsc --noEmit && yarn run -T test -- --packaged-embed-tests-only",
|
||||
"packaged:tests": "cd test/packaged && yarn tsc --noEmit && VITEST_MODE=packaged-embed yarn run -T test",
|
||||
"withEmbedPublishEnv": "NEXT_PUBLIC_EMBED_LIB_URL='https://app.cal.com/embed/embed.js' NEXT_PUBLIC_WEBAPP_URL='https://app.cal.com' yarn",
|
||||
"prepack": "yarn ../../../ lint --filter='@calcom/embed-react' && yarn withEmbedPublishEnv build && yarn packaged:tests",
|
||||
"embed-web-start": "yarn workspace @calcom/web start",
|
||||
@@ -47,10 +47,10 @@
|
||||
"@playwright/test": "1.57.0",
|
||||
"@types/react": "18.0.26",
|
||||
"@types/react-dom": "18.2.6",
|
||||
"@vitejs/plugin-react": "2.2.0",
|
||||
"@vitejs/plugin-react": "5.1.2",
|
||||
"npm-run-all": "4.1.5",
|
||||
"typescript": "5.9.3",
|
||||
"vite": "4.5.14"
|
||||
"vite": "6.4.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@calcom/embed-core": "workspace:*",
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
"types": "./dist/index.d.ts",
|
||||
"devDependencies": {
|
||||
"typescript": "5.9.3",
|
||||
"vite": "4.5.14"
|
||||
"vite": "6.4.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@calcom/embed-core": "workspace:*"
|
||||
|
||||
@@ -23,9 +23,9 @@ const mockFindByEmailAndIncludeProfilesAndPassword = vi.fn();
|
||||
|
||||
vi.mock("@calcom/features/users/repositories/UserRepository", () => {
|
||||
return {
|
||||
UserRepository: vi.fn().mockImplementation(() => ({
|
||||
UserRepository: vi.fn().mockImplementation(function() { return {
|
||||
findByEmailAndIncludeProfilesAndPassword: mockFindByEmailAndIncludeProfilesAndPassword,
|
||||
})),
|
||||
}; }),
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
+3
-3
@@ -130,9 +130,9 @@ describe("BookingAuditAccessService - Permission Checks", () => {
|
||||
checkPermission: vi.fn(),
|
||||
};
|
||||
|
||||
vi.mocked(BookingRepository).mockImplementation(() => mockBookingRepository as unknown as BookingRepository);
|
||||
vi.mocked(MembershipRepository).mockImplementation(() => mockMembershipRepository as unknown as MembershipRepository);
|
||||
vi.mocked(PermissionCheckService).mockImplementation(() => mockPermissionCheckService as unknown as PermissionCheckService);
|
||||
vi.mocked(BookingRepository).mockImplementation(function() { return mockBookingRepository as unknown as BookingRepository; });
|
||||
vi.mocked(MembershipRepository).mockImplementation(function() { return mockMembershipRepository as unknown as MembershipRepository; });
|
||||
vi.mocked(PermissionCheckService).mockImplementation(function() { return mockPermissionCheckService as unknown as PermissionCheckService; });
|
||||
|
||||
service = new BookingAuditAccessService({
|
||||
bookingRepository: mockBookingRepository as unknown as BookingRepository,
|
||||
|
||||
+4
-4
@@ -144,10 +144,10 @@ describe("BookingAuditViewerService - Integration Tests", () => {
|
||||
error: vi.fn(),
|
||||
};
|
||||
|
||||
vi.mocked(BookingRepository).mockImplementation(() => mockBookingRepository as unknown as BookingRepository);
|
||||
vi.mocked(UserRepository).mockImplementation(() => mockUserRepository as unknown as UserRepository);
|
||||
vi.mocked(MembershipRepository).mockImplementation(() => mockMembershipRepository as unknown as MembershipRepository);
|
||||
vi.mocked(PermissionCheckService).mockImplementation(() => mockPermissionCheckService as unknown as PermissionCheckService);
|
||||
vi.mocked(BookingRepository).mockImplementation(function() { return mockBookingRepository as unknown as BookingRepository; });
|
||||
vi.mocked(UserRepository).mockImplementation(function() { return mockUserRepository as unknown as UserRepository; });
|
||||
vi.mocked(MembershipRepository).mockImplementation(function() { return mockMembershipRepository as unknown as MembershipRepository; });
|
||||
vi.mocked(PermissionCheckService).mockImplementation(function() { return mockPermissionCheckService as unknown as PermissionCheckService; });
|
||||
|
||||
service = new BookingAuditViewerService({
|
||||
bookingAuditRepository: mockBookingAuditRepository as unknown as IBookingAuditRepository,
|
||||
|
||||
+26
-32
@@ -11,9 +11,9 @@ import { UserRepository } from "@calcom/features/users/repositories/UserReposito
|
||||
|
||||
vi.mock("@calcom/features/users/repositories/UserRepository", () => {
|
||||
return {
|
||||
UserRepository: vi.fn().mockImplementation(() => ({
|
||||
UserRepository: vi.fn().mockImplementation(function() { return {
|
||||
enrichUserWithItsProfile: vi.fn(),
|
||||
})),
|
||||
}; }),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -25,12 +25,11 @@ describe("getAllCredentialsIncludeServiceAccountKey", () => {
|
||||
|
||||
const mockUserRepository = vi.mocked(UserRepository);
|
||||
if (mockUserRepository && typeof mockUserRepository.mockImplementation === "function") {
|
||||
mockUserRepository.mockImplementation(
|
||||
() =>
|
||||
({
|
||||
mockUserRepository.mockImplementation(function () {
|
||||
return {
|
||||
enrichUserWithItsProfile: mockEnrichUserWithItsProfile,
|
||||
} as any)
|
||||
);
|
||||
} as InstanceType<typeof UserRepository>;
|
||||
});
|
||||
}
|
||||
|
||||
const getAllCredentialsIncludeServiceAccountKey = (await import("./getAllCredentials"))
|
||||
@@ -80,12 +79,11 @@ describe("getAllCredentialsIncludeServiceAccountKey", () => {
|
||||
|
||||
const mockUserRepository = vi.mocked(UserRepository);
|
||||
if (mockUserRepository && typeof mockUserRepository.mockImplementation === "function") {
|
||||
mockUserRepository.mockImplementation(
|
||||
() =>
|
||||
({
|
||||
mockUserRepository.mockImplementation(function () {
|
||||
return {
|
||||
enrichUserWithItsProfile: mockEnrichUserWithItsProfile,
|
||||
} as any)
|
||||
);
|
||||
} as InstanceType<typeof UserRepository>;
|
||||
});
|
||||
}
|
||||
|
||||
const getAllCredentialsIncludeServiceAccountKey = (await import("./getAllCredentials"))
|
||||
@@ -164,12 +162,11 @@ describe("getAllCredentialsIncludeServiceAccountKey", () => {
|
||||
|
||||
const mockUserRepository = vi.mocked(UserRepository);
|
||||
if (mockUserRepository && typeof mockUserRepository.mockImplementation === "function") {
|
||||
mockUserRepository.mockImplementation(
|
||||
() =>
|
||||
({
|
||||
mockUserRepository.mockImplementation(function () {
|
||||
return {
|
||||
enrichUserWithItsProfile: mockEnrichUserWithItsProfile,
|
||||
} as any)
|
||||
);
|
||||
} as InstanceType<typeof UserRepository>;
|
||||
});
|
||||
}
|
||||
|
||||
const getAllCredentialsIncludeServiceAccountKey = (await import("./getAllCredentials"))
|
||||
@@ -241,12 +238,11 @@ describe("getAllCredentialsIncludeServiceAccountKey", () => {
|
||||
|
||||
const mockUserRepository = vi.mocked(UserRepository);
|
||||
if (mockUserRepository && typeof mockUserRepository.mockImplementation === "function") {
|
||||
mockUserRepository.mockImplementation(
|
||||
() =>
|
||||
({
|
||||
mockUserRepository.mockImplementation(function () {
|
||||
return {
|
||||
enrichUserWithItsProfile: mockEnrichUserWithItsProfile,
|
||||
} as any)
|
||||
);
|
||||
} as InstanceType<typeof UserRepository>;
|
||||
});
|
||||
}
|
||||
|
||||
const getAllCredentialsIncludeServiceAccountKey = (await import("./getAllCredentials"))
|
||||
@@ -346,12 +342,11 @@ describe("getAllCredentialsIncludeServiceAccountKey", () => {
|
||||
|
||||
const mockUserRepository = vi.mocked(UserRepository);
|
||||
if (mockUserRepository && typeof mockUserRepository.mockImplementation === "function") {
|
||||
mockUserRepository.mockImplementation(
|
||||
() =>
|
||||
({
|
||||
mockUserRepository.mockImplementation(function () {
|
||||
return {
|
||||
enrichUserWithItsProfile: mockEnrichUserWithItsProfile,
|
||||
} as any)
|
||||
);
|
||||
} as InstanceType<typeof UserRepository>;
|
||||
});
|
||||
}
|
||||
|
||||
const crmCredential = {
|
||||
@@ -669,12 +664,11 @@ describe("getAllCredentialsIncludeServiceAccountKey", () => {
|
||||
|
||||
const mockUserRepository = vi.mocked(UserRepository);
|
||||
if (mockUserRepository && typeof mockUserRepository.mockImplementation === "function") {
|
||||
mockUserRepository.mockImplementation(
|
||||
() =>
|
||||
({
|
||||
mockUserRepository.mockImplementation(function () {
|
||||
return {
|
||||
enrichUserWithItsProfile: mockEnrichUserWithItsProfile,
|
||||
} as any)
|
||||
);
|
||||
} as InstanceType<typeof UserRepository>;
|
||||
});
|
||||
}
|
||||
|
||||
const crmCredential = {
|
||||
|
||||
@@ -39,7 +39,7 @@ vi.mock("@calcom/features/users/repositories/UserRepository", async (importOrigi
|
||||
|
||||
return {
|
||||
...actual,
|
||||
UserRepository: vi.fn().mockImplementation((prisma) => {
|
||||
UserRepository: vi.fn(function (prisma) {
|
||||
const realInstance = new OriginalUserRepository(prisma);
|
||||
realInstance.findManyByEmailsWithEmailVerificationSettings =
|
||||
mockFindManyByEmailsWithEmailVerificationSettings;
|
||||
|
||||
+4
-2
@@ -25,10 +25,12 @@ vi.mock("@calcom/features/CalendarEventBuilder", () => {
|
||||
fromEvent: vi.fn().mockImplementation((_evt) => ({
|
||||
withDestinationCalendar: withDestinationCalendarSpy,
|
||||
withTeam: withTeamSpy,
|
||||
build: vi.fn().mockImplementation(() => ({
|
||||
build: vi.fn().mockImplementation(function() {
|
||||
return {
|
||||
destinationCalendar: [],
|
||||
team: {}, // <- you won't use this result anyway
|
||||
})),
|
||||
};
|
||||
}),
|
||||
})),
|
||||
},
|
||||
};
|
||||
|
||||
@@ -33,9 +33,11 @@ describe("handleSeats", () => {
|
||||
|
||||
describe("Correct parameters being passed into handleSeats from handleNewBooking", () => {
|
||||
vi.mock("./handleSeats");
|
||||
|
||||
test("On new booking handleSeats is not called", async () => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const spy = vi.spyOn(handleSeatsModule, "default");
|
||||
spy.mockClear();
|
||||
|
||||
const booker = getBooker({
|
||||
email: "booker@example.com",
|
||||
@@ -97,6 +99,7 @@ describe("handleSeats", () => {
|
||||
|
||||
test("handleSeats is called when a new attendee is added", async () => {
|
||||
const spy = vi.spyOn(handleSeatsModule, "default");
|
||||
spy.mockClear();
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
|
||||
const booker = getBooker({
|
||||
@@ -242,6 +245,7 @@ describe("handleSeats", () => {
|
||||
|
||||
test("handleSeats is called on rescheduling a seated event", async () => {
|
||||
const spy = vi.spyOn(handleSeatsModule, "default");
|
||||
spy.mockClear();
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
|
||||
const booker = getBooker({
|
||||
|
||||
@@ -14,9 +14,9 @@ import { handleNoShowFee } from "./handleNoShowFee";
|
||||
vi.mock("@calcom/app-store/payment.services.generated", () => ({
|
||||
PaymentServiceMap: {
|
||||
stripepayment: Promise.resolve({
|
||||
PaymentService: vi.fn().mockImplementation(() => ({
|
||||
PaymentService: vi.fn().mockImplementation(function() { return {
|
||||
chargeCard: vi.fn(),
|
||||
})),
|
||||
}; }),
|
||||
}),
|
||||
},
|
||||
}));
|
||||
@@ -43,9 +43,9 @@ vi.mock("@calcom/features/membership/repositories/MembershipRepository", () => (
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/features/ee/teams/repositories/TeamRepository", () => ({
|
||||
TeamRepository: vi.fn().mockImplementation(() => ({
|
||||
TeamRepository: vi.fn().mockImplementation(function() { return {
|
||||
findParentOrganizationByTeamId: vi.fn(),
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/prisma", () => ({
|
||||
@@ -62,7 +62,7 @@ describe("handleNoShowFee", () => {
|
||||
};
|
||||
|
||||
const paymentServiceModule = await PaymentServiceMap.stripepayment;
|
||||
vi.mocked(paymentServiceModule.PaymentService).mockImplementation(() => mockPaymentService);
|
||||
vi.mocked(paymentServiceModule.PaymentService).mockImplementation(function() { return mockPaymentService; });
|
||||
});
|
||||
|
||||
const mockBooking = {
|
||||
@@ -211,7 +211,7 @@ describe("handleNoShowFee", () => {
|
||||
const mockTeamRepository = {
|
||||
findParentOrganizationByTeamId: vi.fn().mockResolvedValue({ id: 2 }),
|
||||
};
|
||||
vi.mocked(TeamRepository).mockImplementation(() => mockTeamRepository);
|
||||
vi.mocked(TeamRepository).mockImplementation(function() { return mockTeamRepository; });
|
||||
|
||||
const result = await handleNoShowFee({
|
||||
booking: teamBooking,
|
||||
|
||||
@@ -40,8 +40,8 @@ describe("BookingAccessService", () => {
|
||||
checkPermission: vi.fn(),
|
||||
};
|
||||
|
||||
vi.mocked(BookingRepository).mockImplementation(() => mockBookingRepo as any);
|
||||
vi.mocked(UserRepository).mockImplementation(() => mockUserRepo as any);
|
||||
vi.mocked(BookingRepository).mockImplementation(function() { return mockBookingRepo as any; });
|
||||
vi.mocked(UserRepository).mockImplementation(function() { return mockUserRepo as any; });
|
||||
|
||||
service = new BookingAccessService(mockPrismaClient);
|
||||
|
||||
|
||||
@@ -16,13 +16,15 @@ import { AIPhoneServiceProviderType } from "./interfaces/AIPhoneService.interfac
|
||||
vi.stubEnv("RETELL_AI_KEY", "test-api-key");
|
||||
|
||||
vi.mock("./providers/retellAI", () => ({
|
||||
RetellAIPhoneServiceProviderFactory: vi.fn().mockImplementation(() => ({
|
||||
RetellAIPhoneServiceProviderFactory: vi.fn().mockImplementation(function() {
|
||||
return {
|
||||
create: vi.fn().mockReturnValue({
|
||||
setupConfiguration: vi.fn(),
|
||||
createPhoneCall: vi.fn(),
|
||||
createPhoneNumber: vi.fn(),
|
||||
}),
|
||||
})),
|
||||
};
|
||||
}),
|
||||
}));
|
||||
|
||||
describe("AIPhoneServiceRegistry", () => {
|
||||
|
||||
+14
-10
@@ -19,7 +19,8 @@ vi.mock("@calcom/lib/logger", () => ({
|
||||
}));
|
||||
|
||||
vi.mock("./RetellSDKClient", () => ({
|
||||
RetellSDKClient: vi.fn().mockImplementation((logger) => ({
|
||||
RetellSDKClient: vi.fn().mockImplementation(function (logger) {
|
||||
return {
|
||||
logger,
|
||||
createLLM: vi.fn(),
|
||||
getLLM: vi.fn(),
|
||||
@@ -35,13 +36,15 @@ vi.mock("./RetellSDKClient", () => ({
|
||||
getPhoneNumber: vi.fn(),
|
||||
updatePhoneNumber: vi.fn(),
|
||||
createPhoneCall: vi.fn(),
|
||||
})),
|
||||
};
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("./RetellAIPhoneServiceProvider", () => ({
|
||||
RetellAIPhoneServiceProvider: vi
|
||||
.fn()
|
||||
.mockImplementation((repository, agentRepository, phoneNumberRepository, transactionManager) => ({
|
||||
.mockImplementation(function (repository, agentRepository, phoneNumberRepository, transactionManager) {
|
||||
return {
|
||||
repository,
|
||||
agentRepository,
|
||||
phoneNumberRepository,
|
||||
@@ -58,11 +61,12 @@ vi.mock("./RetellAIPhoneServiceProvider", () => ({
|
||||
getPhoneNumber: vi.fn(),
|
||||
updatePhoneNumber: vi.fn(),
|
||||
importPhoneNumber: vi.fn(),
|
||||
})),
|
||||
};
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("../adapters/PrismaAgentRepositoryAdapter", () => ({
|
||||
PrismaAgentRepositoryAdapter: vi.fn().mockImplementation(() => ({
|
||||
PrismaAgentRepositoryAdapter: vi.fn().mockImplementation(function() { return {
|
||||
canManageTeamResources: vi.fn(),
|
||||
findByIdWithUserAccess: vi.fn(),
|
||||
findByProviderAgentIdWithUserAccess: vi.fn(),
|
||||
@@ -73,11 +77,11 @@ vi.mock("../adapters/PrismaAgentRepositoryAdapter", () => ({
|
||||
findByIdWithCallAccess: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
linkOutboundAgentToWorkflow: vi.fn(),
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
vi.mock("../adapters/PrismaPhoneNumberRepositoryAdapter", () => ({
|
||||
PrismaPhoneNumberRepositoryAdapter: vi.fn().mockImplementation(() => ({
|
||||
PrismaPhoneNumberRepositoryAdapter: vi.fn().mockImplementation(function() { return {
|
||||
findByPhoneNumberAndUserId: vi.fn(),
|
||||
findByPhoneNumberAndTeamId: vi.fn(),
|
||||
findByIdAndUserId: vi.fn(),
|
||||
@@ -86,13 +90,13 @@ vi.mock("../adapters/PrismaPhoneNumberRepositoryAdapter", () => ({
|
||||
deletePhoneNumber: vi.fn(),
|
||||
updateSubscriptionStatus: vi.fn(),
|
||||
updateAgents: vi.fn(),
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
vi.mock("../adapters/PrismaTransactionAdapter", () => ({
|
||||
PrismaTransactionAdapter: vi.fn().mockImplementation(() => ({
|
||||
PrismaTransactionAdapter: vi.fn().mockImplementation(function() { return {
|
||||
executeInTransaction: vi.fn(),
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
describe("RetellAIPhoneServiceProviderFactory", () => {
|
||||
|
||||
@@ -34,10 +34,12 @@ vi.mock("@calcom/features/ee/payments/server/stripe", () => ({
|
||||
|
||||
const mockGetAllCredits = vi.fn();
|
||||
const mockHasAvailableCredits = vi.fn();
|
||||
const mockCreditService = vi.fn().mockImplementation(() => ({
|
||||
const mockCreditService = vi.fn().mockImplementation(function() {
|
||||
return {
|
||||
getAllCredits: mockGetAllCredits,
|
||||
hasAvailableCredits: mockHasAvailableCredits,
|
||||
}));
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("@calcom/features/ee/billing/credit-service", () => ({
|
||||
CreditService: mockCreditService,
|
||||
@@ -849,9 +851,11 @@ describe("RetellAIService", () => {
|
||||
const { CreditService } = await import("@calcom/features/ee/billing/credit-service");
|
||||
|
||||
const mockHasAvailableCredits = vi.fn().mockResolvedValue(true);
|
||||
(CreditService as any).mockImplementation(() => ({
|
||||
(CreditService as any).mockImplementation(function() {
|
||||
return {
|
||||
hasAvailableCredits: mockHasAvailableCredits,
|
||||
}));
|
||||
};
|
||||
});
|
||||
|
||||
// Mock rate limiting like the working example
|
||||
vi.mocked(checkRateLimitAndThrowError).mockResolvedValueOnce(undefined as any);
|
||||
@@ -931,9 +935,11 @@ describe("RetellAIService", () => {
|
||||
|
||||
// Mock credit service to return false (no credits)
|
||||
const mockHasAvailableCredits = vi.fn().mockResolvedValue(false);
|
||||
(CreditService as any).mockImplementation(() => ({
|
||||
(CreditService as any).mockImplementation(function() {
|
||||
return {
|
||||
hasAvailableCredits: mockHasAvailableCredits,
|
||||
}));
|
||||
};
|
||||
});
|
||||
|
||||
await expect(
|
||||
service.createTestCall({
|
||||
@@ -952,9 +958,11 @@ describe("RetellAIService", () => {
|
||||
|
||||
// Mock sufficient credits to get past credit check
|
||||
const mockHasAvailableCredits = vi.fn().mockResolvedValue(true);
|
||||
(CreditService as any).mockImplementation(() => ({
|
||||
(CreditService as any).mockImplementation(function() {
|
||||
return {
|
||||
hasAvailableCredits: mockHasAvailableCredits,
|
||||
}));
|
||||
};
|
||||
});
|
||||
|
||||
(checkRateLimitAndThrowError as any).mockResolvedValue(undefined);
|
||||
|
||||
@@ -974,9 +982,11 @@ describe("RetellAIService", () => {
|
||||
|
||||
// Mock sufficient credits
|
||||
const mockHasAvailableCredits = vi.fn().mockResolvedValue(true);
|
||||
(CreditService as any).mockImplementation(() => ({
|
||||
(CreditService as any).mockImplementation(function() {
|
||||
return {
|
||||
hasAvailableCredits: mockHasAvailableCredits,
|
||||
}));
|
||||
};
|
||||
});
|
||||
|
||||
(checkRateLimitAndThrowError as any).mockResolvedValue(undefined);
|
||||
mockAgentRepository.findByIdWithCallAccess.mockResolvedValue(null);
|
||||
@@ -998,9 +1008,11 @@ describe("RetellAIService", () => {
|
||||
|
||||
// Mock sufficient credits
|
||||
const mockHasAvailableCredits = vi.fn().mockResolvedValue(true);
|
||||
(CreditService as any).mockImplementation(() => ({
|
||||
(CreditService as any).mockImplementation(function() {
|
||||
return {
|
||||
hasAvailableCredits: mockHasAvailableCredits,
|
||||
}));
|
||||
};
|
||||
});
|
||||
|
||||
(checkRateLimitAndThrowError as any).mockResolvedValue(undefined);
|
||||
mockAgentRepository.findByIdWithCallAccess.mockResolvedValue({
|
||||
|
||||
@@ -16,7 +16,8 @@ import type {
|
||||
let RetellSDKClient: typeof import("./RetellSDKClient").RetellSDKClient;
|
||||
|
||||
vi.mock("retell-sdk", () => ({
|
||||
Retell: vi.fn().mockImplementation(() => ({
|
||||
Retell: vi.fn().mockImplementation(function() {
|
||||
return {
|
||||
llm: {
|
||||
create: vi.fn(),
|
||||
retrieve: vi.fn(),
|
||||
@@ -39,7 +40,8 @@ vi.mock("retell-sdk", () => ({
|
||||
call: {
|
||||
createPhoneCall: vi.fn(),
|
||||
},
|
||||
})),
|
||||
};
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/lib/logger", () => ({
|
||||
@@ -107,7 +109,7 @@ describe("RetellSDKClient", () => {
|
||||
},
|
||||
};
|
||||
|
||||
(Retell as any).mockImplementation(() => mockRetellInstance);
|
||||
(Retell as any).mockImplementation(function() { return mockRetellInstance; });
|
||||
});
|
||||
|
||||
describe("constructor", () => {
|
||||
|
||||
+16
-8
@@ -26,9 +26,11 @@ describe("CallService", () => {
|
||||
const { CreditService } = await import("@calcom/features/ee/billing/credit-service");
|
||||
const { checkRateLimitAndThrowError } = await import("@calcom/lib/checkRateLimitAndThrowError");
|
||||
|
||||
vi.mocked(CreditService).mockImplementation(() => ({
|
||||
vi.mocked(CreditService).mockImplementation(function () {
|
||||
return {
|
||||
hasAvailableCredits: vi.fn().mockResolvedValue(true),
|
||||
}));
|
||||
};
|
||||
});
|
||||
|
||||
vi.mocked(checkRateLimitAndThrowError).mockResolvedValue(undefined);
|
||||
|
||||
@@ -233,9 +235,11 @@ describe("CallService", () => {
|
||||
mocks.mockRetellRepository.createPhoneCall.mockResolvedValue(createMockCall());
|
||||
|
||||
const { CreditService } = await import("@calcom/features/ee/billing/credit-service");
|
||||
vi.mocked(CreditService).mockImplementation(() => ({
|
||||
vi.mocked(CreditService).mockImplementation(function () {
|
||||
return {
|
||||
getAllCredits: vi.fn().mockRejectedValue(new TestError("Credit service unavailable")),
|
||||
}));
|
||||
};
|
||||
});
|
||||
|
||||
await expect(service.createTestCall(validTestCallData)).rejects.toThrow(
|
||||
"Unable to validate credits. Please try again."
|
||||
@@ -247,9 +251,11 @@ describe("CallService", () => {
|
||||
mocks.mockRetellRepository.createPhoneCall.mockResolvedValue(createMockCall());
|
||||
|
||||
const { CreditService } = await import("@calcom/features/ee/billing/credit-service");
|
||||
vi.mocked(CreditService).mockImplementation(() => ({
|
||||
vi.mocked(CreditService).mockImplementation(function () {
|
||||
return {
|
||||
hasAvailableCredits: vi.fn().mockResolvedValue(false),
|
||||
}));
|
||||
};
|
||||
});
|
||||
|
||||
await expect(service.createTestCall(validTestCallData)).rejects.toThrow(
|
||||
"Insufficient credits to make test call. Please purchase more credits."
|
||||
@@ -261,9 +267,11 @@ describe("CallService", () => {
|
||||
mocks.mockRetellRepository.createPhoneCall.mockResolvedValue(createMockCall());
|
||||
|
||||
const { CreditService } = await import("@calcom/features/ee/billing/credit-service");
|
||||
vi.mocked(CreditService).mockImplementation(() => ({
|
||||
vi.mocked(CreditService).mockImplementation(function () {
|
||||
return {
|
||||
hasAvailableCredits: vi.fn().mockResolvedValue(false),
|
||||
}));
|
||||
};
|
||||
});
|
||||
|
||||
await expect(service.createTestCall(validTestCallData)).rejects.toThrow(
|
||||
"Insufficient credits to make test call. Please purchase more credits."
|
||||
|
||||
+4
-2
@@ -94,9 +94,11 @@ describe("GoogleCalendarSubscriptionAdapter", () => {
|
||||
};
|
||||
|
||||
const { CalendarAuth } = await import("../__mocks__/CalendarAuth");
|
||||
vi.mocked(CalendarAuth).mockImplementation(() => ({
|
||||
vi.mocked(CalendarAuth).mockImplementation(function() {
|
||||
return {
|
||||
getClient: vi.fn().mockResolvedValue(mockClient),
|
||||
}));
|
||||
};
|
||||
});
|
||||
|
||||
adapter = new GoogleCalendarSubscriptionAdapter();
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -27,9 +27,9 @@ vi.mock("@calcom/features/credentials/repositories/CredentialRepository", () =>
|
||||
|
||||
vi.mock("@calcom/features/users/repositories/UserRepository", () => {
|
||||
return {
|
||||
UserRepository: vi.fn().mockImplementation(() => ({
|
||||
UserRepository: vi.fn().mockImplementation(function() { return {
|
||||
getUserOrganizationAndTeams: vi.fn(),
|
||||
})),
|
||||
}; }),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -123,7 +123,7 @@ describe("CredentialAccessService", () => {
|
||||
}),
|
||||
};
|
||||
|
||||
vi.mocked(UserRepository).mockImplementation(() => mockUserRepo as any);
|
||||
vi.mocked(UserRepository).mockImplementation(function() { return mockUserRepo as any; });
|
||||
|
||||
const service = new CredentialAccessService();
|
||||
await expect(
|
||||
@@ -168,7 +168,7 @@ describe("CredentialAccessService", () => {
|
||||
}),
|
||||
};
|
||||
|
||||
vi.mocked(UserRepository).mockImplementation(() => mockUserRepo as any);
|
||||
vi.mocked(UserRepository).mockImplementation(function() { return mockUserRepo as any; });
|
||||
|
||||
const service = new CredentialAccessService();
|
||||
await expect(
|
||||
@@ -207,7 +207,7 @@ describe("CredentialAccessService", () => {
|
||||
}),
|
||||
};
|
||||
|
||||
vi.mocked(UserRepository).mockImplementation(() => mockUserRepo as any);
|
||||
vi.mocked(UserRepository).mockImplementation(function() { return mockUserRepo as any; });
|
||||
|
||||
const service = new CredentialAccessService();
|
||||
await expect(
|
||||
@@ -273,7 +273,7 @@ describe("CredentialAccessService", () => {
|
||||
}),
|
||||
};
|
||||
|
||||
vi.mocked(UserRepository).mockImplementation(() => mockUserRepo as any);
|
||||
vi.mocked(UserRepository).mockImplementation(function() { return mockUserRepo as any; });
|
||||
|
||||
const service = new CredentialAccessService();
|
||||
const error = await service
|
||||
|
||||
@@ -34,7 +34,7 @@ describe("autoLock", () => {
|
||||
beforeEach(() => {
|
||||
// Reset all mocks before each test
|
||||
vi.clearAllMocks();
|
||||
vi.mocked(RedisService).mockImplementation(() => mockRedis as any);
|
||||
vi.mocked(RedisService).mockImplementation(function() { return mockRedis as any; });
|
||||
|
||||
// Mock environment variables
|
||||
process.env.UPSTASH_REDIS_REST_TOKEN = "test-token";
|
||||
|
||||
@@ -130,7 +130,7 @@ describe("CreditService", () => {
|
||||
let creditService: CreditService;
|
||||
|
||||
beforeEach(async () => {
|
||||
vi.restoreAllMocks();
|
||||
vi.resetAllMocks();
|
||||
|
||||
mockStripe.prices.retrieve.mockResolvedValue({ id: "price_123", unit_amount: 1000 });
|
||||
mockStripe.customers.create.mockResolvedValue({ id: "cus_123" });
|
||||
@@ -469,7 +469,7 @@ describe("CreditService", () => {
|
||||
members: [{ accepted: true }],
|
||||
}),
|
||||
};
|
||||
vi.mocked(TeamRepository).mockImplementation(() => mockTeamRepo as unknown as TeamRepository);
|
||||
vi.mocked(TeamRepository).mockImplementation(function() { return mockTeamRepo as unknown as TeamRepository; });
|
||||
|
||||
const mockTeamBillingService = {
|
||||
getSubscriptionStatus: vi.fn().mockResolvedValue(SubscriptionStatus.TRIALING),
|
||||
@@ -493,7 +493,7 @@ describe("CreditService", () => {
|
||||
members: [{ accepted: true }, { accepted: true }, { accepted: true }],
|
||||
}),
|
||||
};
|
||||
vi.mocked(TeamRepository).mockImplementation(() => mockTeamRepo as unknown as TeamRepository);
|
||||
vi.mocked(TeamRepository).mockImplementation(function() { return mockTeamRepo as unknown as TeamRepository; });
|
||||
|
||||
const mockTeamBillingService = {
|
||||
getSubscriptionStatus: vi.fn().mockResolvedValue(SubscriptionStatus.ACTIVE),
|
||||
@@ -524,7 +524,7 @@ describe("CreditService", () => {
|
||||
members: [{ accepted: true }, { accepted: true }],
|
||||
}),
|
||||
};
|
||||
vi.mocked(TeamRepository).mockImplementation(() => mockTeamRepo as unknown as TeamRepository);
|
||||
vi.mocked(TeamRepository).mockImplementation(function() { return mockTeamRepo as unknown as TeamRepository; });
|
||||
|
||||
const mockTeamBillingService = {
|
||||
getSubscriptionStatus: vi.fn().mockResolvedValue(SubscriptionStatus.ACTIVE),
|
||||
@@ -549,7 +549,7 @@ describe("CreditService", () => {
|
||||
members: [{ accepted: true }, { accepted: true }, { accepted: true }],
|
||||
}),
|
||||
};
|
||||
vi.mocked(TeamRepository).mockImplementation(() => mockTeamRepo as unknown as TeamRepository);
|
||||
vi.mocked(TeamRepository).mockImplementation(function() { return mockTeamRepo as unknown as TeamRepository; });
|
||||
|
||||
const mockTeamBillingService = {
|
||||
getSubscriptionStatus: vi.fn().mockResolvedValue(SubscriptionStatus.ACTIVE),
|
||||
@@ -841,9 +841,14 @@ describe("CreditService", () => {
|
||||
{ teamId: 2 },
|
||||
]);
|
||||
|
||||
vi.spyOn(TeamRepository.prototype, "findTeamsForCreditCheck").mockResolvedValue([
|
||||
const mockTeamRepoInstance = {
|
||||
findTeamsForCreditCheck: vi.fn().mockResolvedValue([
|
||||
{ id: 2, isOrganization: false, parentId: null, parent: null },
|
||||
]);
|
||||
]),
|
||||
};
|
||||
vi.mocked(TeamRepository).mockImplementation(function () {
|
||||
return mockTeamRepoInstance as unknown as TeamRepository;
|
||||
});
|
||||
|
||||
vi.mocked(CreditsRepository.findCreditBalance).mockResolvedValue({
|
||||
id: "2",
|
||||
@@ -876,10 +881,15 @@ describe("CreditService", () => {
|
||||
{ teamId: 2 },
|
||||
]);
|
||||
|
||||
vi.spyOn(TeamRepository.prototype, "findTeamsForCreditCheck").mockResolvedValue([
|
||||
const mockTeamRepoInstance = {
|
||||
findTeamsForCreditCheck: vi.fn().mockResolvedValue([
|
||||
{ id: 1, isOrganization: true, parentId: null, parent: null },
|
||||
{ id: 2, isOrganization: false, parentId: null, parent: null },
|
||||
]);
|
||||
]),
|
||||
};
|
||||
vi.mocked(TeamRepository).mockImplementation(function () {
|
||||
return mockTeamRepoInstance as unknown as TeamRepository;
|
||||
});
|
||||
|
||||
vi.mocked(CreditsRepository.findCreditBalance).mockResolvedValue({
|
||||
id: "1",
|
||||
@@ -910,10 +920,15 @@ describe("CreditService", () => {
|
||||
{ teamId: 2 },
|
||||
]);
|
||||
|
||||
vi.spyOn(TeamRepository.prototype, "findTeamsForCreditCheck").mockResolvedValue([
|
||||
const mockTeamRepoInstance = {
|
||||
findTeamsForCreditCheck: vi.fn().mockResolvedValue([
|
||||
{ id: 1, isOrganization: true, parentId: null, parent: null },
|
||||
{ id: 2, isOrganization: false, parentId: null, parent: null },
|
||||
]);
|
||||
]),
|
||||
};
|
||||
vi.mocked(TeamRepository).mockImplementation(function () {
|
||||
return mockTeamRepoInstance as unknown as TeamRepository;
|
||||
});
|
||||
|
||||
vi.mocked(CreditsRepository.findCreditBalance).mockResolvedValue({
|
||||
id: "1",
|
||||
@@ -944,9 +959,14 @@ describe("CreditService", () => {
|
||||
{ teamId: 2 },
|
||||
]);
|
||||
|
||||
vi.spyOn(TeamRepository.prototype, "findTeamsForCreditCheck").mockResolvedValue([
|
||||
const mockTeamRepoInstance = {
|
||||
findTeamsForCreditCheck: vi.fn().mockResolvedValue([
|
||||
{ id: 2, isOrganization: false, parentId: null, parent: null },
|
||||
]);
|
||||
]),
|
||||
};
|
||||
vi.mocked(TeamRepository).mockImplementation(function () {
|
||||
return mockTeamRepoInstance as unknown as TeamRepository;
|
||||
});
|
||||
|
||||
vi.mocked(CreditsRepository.findCreditBalance).mockResolvedValue({
|
||||
id: "2",
|
||||
|
||||
@@ -48,9 +48,9 @@ vi.mock("./removeUserFromOrg", () => ({
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/features/users/repositories/UserRepository", () => ({
|
||||
UserRepository: vi.fn().mockImplementation(() => ({
|
||||
UserRepository: vi.fn().mockImplementation(function() { return {
|
||||
isAMemberOfOrganization: vi.fn().mockResolvedValue(false),
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
async function createMockOrganization({ id, name, slug }: { id: number; name: string; slug: string }) {
|
||||
@@ -191,12 +191,11 @@ describe("handleUserEvents", () => {
|
||||
};
|
||||
|
||||
const { UserRepository } = await import("@calcom/features/users/repositories/UserRepository");
|
||||
vi.mocked(UserRepository).mockImplementation(
|
||||
() =>
|
||||
({
|
||||
vi.mocked(UserRepository).mockImplementation(function () {
|
||||
return {
|
||||
isAMemberOfOrganization: vi.fn().mockResolvedValue(true),
|
||||
} as unknown as InstanceType<typeof UserRepository>)
|
||||
);
|
||||
} as unknown as InstanceType<typeof UserRepository>;
|
||||
});
|
||||
|
||||
await expect(handleUserEvents(event, organizationId)).resolves.not.toThrow();
|
||||
});
|
||||
@@ -292,12 +291,11 @@ describe("handleUserEvents", () => {
|
||||
};
|
||||
|
||||
const { UserRepository } = await import("@calcom/features/users/repositories/UserRepository");
|
||||
vi.mocked(UserRepository).mockImplementation(
|
||||
() =>
|
||||
({
|
||||
vi.mocked(UserRepository).mockImplementation(function () {
|
||||
return {
|
||||
isAMemberOfOrganization: vi.fn().mockResolvedValue(false),
|
||||
} as unknown as InstanceType<typeof UserRepository>)
|
||||
);
|
||||
} as unknown as InstanceType<typeof UserRepository>;
|
||||
});
|
||||
|
||||
const inviteExistingUserToOrg = (await import("./users/inviteExistingUserToOrg")).default;
|
||||
const sendExistingUserTeamInviteEmails = (
|
||||
@@ -377,12 +375,11 @@ describe("handleUserEvents", () => {
|
||||
};
|
||||
|
||||
const { UserRepository } = await import("@calcom/features/users/repositories/UserRepository");
|
||||
vi.mocked(UserRepository).mockImplementation(
|
||||
() =>
|
||||
({
|
||||
vi.mocked(UserRepository).mockImplementation(function () {
|
||||
return {
|
||||
isAMemberOfOrganization: vi.fn().mockResolvedValue(true),
|
||||
} as unknown as InstanceType<typeof UserRepository>)
|
||||
);
|
||||
} as unknown as InstanceType<typeof UserRepository>;
|
||||
});
|
||||
|
||||
const { assignValueToUserInOrgBulk } = await import("./assignValueToUser");
|
||||
|
||||
|
||||
@@ -179,7 +179,10 @@ type ConferenceResult = {
|
||||
const mockEventManagerReschedule = async (config?: MockEventManagerConfig) => {
|
||||
const EventManager = (await import("@calcom/features/bookings/lib/EventManager")).default;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const spy = vi.spyOn(EventManager.prototype as any, "reschedule");
|
||||
const existingSpy = vi.spyOn(EventManager.prototype as any, "reschedule");
|
||||
// Clear any existing mock calls from previous tests
|
||||
existingSpy.mockClear();
|
||||
const spy = existingSpy;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
spy.mockImplementation(async (event: any) => {
|
||||
|
||||
@@ -64,6 +64,8 @@ describe("roundRobinReassignment test", () => {
|
||||
const EventManager = (await import("@calcom/features/bookings/lib/EventManager")).default;
|
||||
|
||||
const eventManagerSpy = vi.spyOn(EventManager.prototype as any, "reschedule");
|
||||
// Clear any existing mock calls from previous tests
|
||||
eventManagerSpy.mockClear();
|
||||
eventManagerSpy.mockResolvedValue({ referencesToCreate: [] });
|
||||
|
||||
const users = testUsers;
|
||||
@@ -197,6 +199,8 @@ describe("roundRobinReassignment test", () => {
|
||||
const EventManager = (await import("@calcom/features/bookings/lib/EventManager")).default;
|
||||
|
||||
const eventManagerSpy = vi.spyOn(EventManager.prototype as any, "reschedule");
|
||||
// Clear any existing mock calls from previous tests
|
||||
eventManagerSpy.mockClear();
|
||||
|
||||
const users = testUsers;
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ const mockTeamRepo = {
|
||||
throw new Error(`Team with id ${id} not found`);
|
||||
}),
|
||||
};
|
||||
vi.mocked(TeamRepository).mockImplementation(() => mockTeamRepo);
|
||||
vi.mocked(TeamRepository).mockImplementation(function() { return mockTeamRepo; });
|
||||
|
||||
vi.mocked(deleteDomain).mockImplementation(async (slug) => {
|
||||
database.domains.delete(slug);
|
||||
|
||||
@@ -61,7 +61,7 @@ describe("TeamService", () => {
|
||||
const mockTeamRepo = {
|
||||
deleteById: vi.fn().mockResolvedValue(mockDeletedTeam),
|
||||
} as Pick<TeamRepository, "deleteById">;
|
||||
vi.mocked(TeamRepository).mockImplementation(() => mockTeamRepo);
|
||||
vi.mocked(TeamRepository).mockImplementation(function() { return mockTeamRepo; });
|
||||
|
||||
const result = await TeamService.delete({ id: 1 });
|
||||
|
||||
|
||||
@@ -19,9 +19,9 @@ vi.mock("@calcom/features/profile/lib/hideBranding", () => ({
|
||||
|
||||
const mockWorkflowReminderCreate = vi.fn();
|
||||
vi.mock("@calcom/features/ee/workflows/repositories/WorkflowReminderRepository", () => ({
|
||||
WorkflowReminderRepository: vi.fn().mockImplementation(() => ({
|
||||
WorkflowReminderRepository: vi.fn().mockImplementation(function() { return {
|
||||
create: mockWorkflowReminderCreate,
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/prisma", () => ({
|
||||
|
||||
@@ -18,10 +18,10 @@ vi.mock("../reminders/providers/twilioProvider", () => ({
|
||||
|
||||
const mockChargeCredits = vi.fn().mockResolvedValue({ teamId: 1 });
|
||||
vi.mock("@calcom/features/ee/billing/credit-service", () => ({
|
||||
CreditService: vi.fn().mockImplementation(() => ({
|
||||
CreditService: vi.fn().mockImplementation(function() { return {
|
||||
chargeCredits: mockChargeCredits,
|
||||
calculateCreditsFromPrice: vi.fn().mockReturnValue(1),
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
const mockFindFirst = vi.fn();
|
||||
|
||||
@@ -14,7 +14,7 @@ vi.mock("@calcom/prisma", () => {
|
||||
return {
|
||||
__esModule: true,
|
||||
default: mockPrisma,
|
||||
PrismaClient: vi.fn(() => mockPrisma),
|
||||
PrismaClient: vi.fn().mockImplementation(function() { return mockPrisma; }),
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -35,8 +35,8 @@ describe("getEventTypePermissions", () => {
|
||||
getResourcePermissions: vi.fn(),
|
||||
};
|
||||
|
||||
vi.mocked(FeaturesRepository).mockImplementation(() => mockFeaturesRepository as any);
|
||||
vi.mocked(PermissionCheckService).mockImplementation(() => mockPermissionCheckService as any);
|
||||
vi.mocked(FeaturesRepository).mockImplementation(function() { return mockFeaturesRepository as any; });
|
||||
vi.mocked(PermissionCheckService).mockImplementation(function() { return mockPermissionCheckService as any; });
|
||||
|
||||
prisma.membership.findFirst = vi.fn();
|
||||
prisma.team.findUnique = vi.fn();
|
||||
@@ -546,8 +546,8 @@ describe("getEventTypePermissions", () => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
// Re-initialize mocks after clearing
|
||||
vi.mocked(FeaturesRepository).mockImplementation(() => mockFeaturesRepository as any);
|
||||
vi.mocked(PermissionCheckService).mockImplementation(() => mockPermissionCheckService as any);
|
||||
vi.mocked(FeaturesRepository).mockImplementation(function() { return mockFeaturesRepository as any; });
|
||||
vi.mocked(PermissionCheckService).mockImplementation(function() { return mockPermissionCheckService as any; });
|
||||
prisma.membership.findFirst = vi.fn();
|
||||
prisma.team.findUnique = vi.fn();
|
||||
|
||||
|
||||
@@ -42,9 +42,9 @@ describe("getResourcePermissions", () => {
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
vi.mocked(FeaturesRepository).mockImplementation(() => mockFeaturesRepository as any);
|
||||
vi.mocked(FeaturesRepository).mockImplementation(function() { return mockFeaturesRepository as any; });
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
vi.mocked(PermissionCheckService).mockImplementation(() => mockPermissionCheckService as any);
|
||||
vi.mocked(PermissionCheckService).mockImplementation(function() { return mockPermissionCheckService as any; });
|
||||
});
|
||||
|
||||
describe("when PBAC is disabled", () => {
|
||||
|
||||
@@ -26,9 +26,9 @@ vi.mock("@calcom/lib/checkRateLimitAndThrowError");
|
||||
vi.mock("@calcom/features/routing-forms/repositories/PrismaRoutingFormRepository");
|
||||
vi.mock("@calcom/features/users/repositories/UserRepository", () => {
|
||||
return {
|
||||
UserRepository: vi.fn().mockImplementation(() => ({
|
||||
UserRepository: vi.fn().mockImplementation(function() { return {
|
||||
enrichUserWithItsProfile: vi.fn(),
|
||||
})),
|
||||
}; }),
|
||||
};
|
||||
});
|
||||
vi.mock("@calcom/features/ee/organizations/lib/orgDomains");
|
||||
@@ -89,13 +89,12 @@ describe("getRoutedUrl", () => {
|
||||
const mockEnrichUserWithItsProfile = vi.fn().mockImplementation(async ({ user }) => user);
|
||||
const mockUserRepository = vi.mocked(UserRepository);
|
||||
if (mockUserRepository && typeof mockUserRepository.mockImplementation === "function") {
|
||||
mockUserRepository.mockImplementation(
|
||||
() =>
|
||||
({
|
||||
mockUserRepository.mockImplementation(function () {
|
||||
return {
|
||||
enrichUserWithItsProfile: mockEnrichUserWithItsProfile,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} as any)
|
||||
);
|
||||
} as any;
|
||||
});
|
||||
}
|
||||
vi.mocked(isAuthorizedToViewFormOnOrgDomain).mockReturnValue(true);
|
||||
vi.mocked(getSerializableForm).mockResolvedValue(mockSerializableForm as never);
|
||||
|
||||
@@ -119,10 +119,10 @@ const mockResponse: Record<
|
||||
describe("handleResponse", () => {
|
||||
beforeEach(() => {
|
||||
vi.resetAllMocks();
|
||||
vi.mocked(RoutingFormResponseRepository).mockImplementation(
|
||||
vi.mocked(RoutingFormResponseRepository).mockImplementation(function () {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
() => mockRoutingFormResponseRepository as any
|
||||
);
|
||||
return mockRoutingFormResponseRepository as any;
|
||||
});
|
||||
});
|
||||
|
||||
it("should throw an Error for missing required fields", async () => {
|
||||
|
||||
@@ -19,9 +19,11 @@ vi.mock("@calcom/features/redis/RedisService", () => {
|
||||
});
|
||||
|
||||
vi.mock("@calcom/features/flags/features.repository", () => ({
|
||||
FeaturesRepository: vi.fn().mockImplementation(() => ({
|
||||
FeaturesRepository: vi.fn(function () {
|
||||
return {
|
||||
checkIfFeatureIsEnabledGlobally: vi.fn().mockResolvedValue(false),
|
||||
})),
|
||||
};
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.spyOn(CalcomEmails, "sendOrganizationAdminNoSlotsNotification");
|
||||
|
||||
@@ -6,9 +6,9 @@ vi.mock("@calcom/emails/workflow-email-service", () => ({
|
||||
|
||||
const mockGetBookingForCalEventBuilderFromUid = vi.fn();
|
||||
vi.mock("@calcom/features/bookings/repositories/BookingRepository", () => ({
|
||||
BookingRepository: vi.fn().mockImplementation(() => ({
|
||||
BookingRepository: vi.fn().mockImplementation(function() { return {
|
||||
getBookingForCalEventBuilderFromUid: mockGetBookingForCalEventBuilderFromUid,
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/features/bookings/repositories/BookingSeatRepository", () => ({
|
||||
@@ -17,9 +17,9 @@ vi.mock("@calcom/features/bookings/repositories/BookingSeatRepository", () => ({
|
||||
|
||||
const mockHandleSendEmailWorkflowTask = vi.fn();
|
||||
vi.mock("@calcom/features/ee/workflows/lib/service/EmailWorkflowService", () => ({
|
||||
EmailWorkflowService: vi.fn().mockImplementation(() => ({
|
||||
EmailWorkflowService: vi.fn().mockImplementation(function() { return {
|
||||
handleSendEmailWorkflowTask: mockHandleSendEmailWorkflowTask,
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/features/ee/workflows/repositories/WorkflowReminderRepository", () => ({
|
||||
|
||||
@@ -27,7 +27,9 @@ const mockUserRepository = {
|
||||
|
||||
vi.mock("@calcom/features/users/repositories/UserRepository", () => {
|
||||
return {
|
||||
UserRepository: vi.fn().mockImplementation(() => mockUserRepository),
|
||||
UserRepository: vi.fn(function () {
|
||||
return mockUserRepository;
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import { describe, expect, it } from "vitest";
|
||||
import { useCompatSearchParams } from "./useCompatSearchParams";
|
||||
|
||||
vi.mock("next/navigation", () => ({
|
||||
ReadonlyURLSearchParams: vi.fn((a) => a),
|
||||
ReadonlyURLSearchParams: vi.fn().mockImplementation(function(a) { return a; }),
|
||||
}));
|
||||
|
||||
describe("useCompatSearchParams hook", () => {
|
||||
|
||||
@@ -64,7 +64,11 @@ describe("getServerErrorFromUnknown", () => {
|
||||
expect(result).toBeInstanceOf(HttpError);
|
||||
expect(result.statusCode).toBe(400);
|
||||
expect(result.message).toBe(stripeError.message);
|
||||
expect(result.cause).toEqual(stripeError);
|
||||
// Check that cause contains the essential properties (Vitest 4.0 uses stricter equality)
|
||||
expect(result.cause).toMatchObject({
|
||||
name: stripeError.name,
|
||||
message: stripeError.message,
|
||||
});
|
||||
expect(result.name).toBe("HttpError");
|
||||
});
|
||||
|
||||
|
||||
@@ -25,8 +25,8 @@
|
||||
"@types/node": "20.17.23",
|
||||
"@types/react": "18.0.26",
|
||||
"@types/react-dom": "18.2.6",
|
||||
"@vitejs/plugin-react": "2.2.0",
|
||||
"@vitejs/plugin-react-swc": "3.7.0",
|
||||
"@vitejs/plugin-react": "5.1.2",
|
||||
"@vitejs/plugin-react-swc": "4.2.2",
|
||||
"autoprefixer": "10.4.19",
|
||||
"cssnano": "7.1.2",
|
||||
"jest": "29.7.0",
|
||||
@@ -37,8 +37,8 @@
|
||||
"postcss-prefixwrap": "1.46.0",
|
||||
"ts-jest": "29.1.4",
|
||||
"typescript": "5.9.3",
|
||||
"vite": "5.4.21",
|
||||
"vite-plugin-dts": "3.7.3",
|
||||
"vite": "6.4.1",
|
||||
"vite-plugin-dts": "4.5.4",
|
||||
"vite-plugin-inspect": "0.8.4"
|
||||
},
|
||||
"files": [
|
||||
|
||||
@@ -28,10 +28,10 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "20.17.23",
|
||||
"@vitejs/plugin-react": "4.2.1",
|
||||
"@vitejs/plugin-react": "5.1.2",
|
||||
"typescript": "5.9.3",
|
||||
"vite": "5.4.21",
|
||||
"vite-plugin-dts": "3.7.3",
|
||||
"vite": "6.4.1",
|
||||
"vite-plugin-dts": "4.5.4",
|
||||
"vite-plugin-environment": "1.1.3"
|
||||
},
|
||||
"exports": {
|
||||
|
||||
+2
-2
@@ -14,9 +14,9 @@ vi.mock("@calcom/lib/hasEditPermissionForUser", () => ({
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/features/schedules/repositories/ScheduleRepository", () => ({
|
||||
ScheduleRepository: vi.fn().mockImplementation(() => ({
|
||||
ScheduleRepository: vi.fn().mockImplementation(function() { return {
|
||||
getDefaultScheduleId: vi.fn().mockResolvedValue(DEFAULT_SCHEDULE_ID),
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
import { hasReadPermissionsForUserId } from "@calcom/lib/hasEditPermissionForUser";
|
||||
|
||||
@@ -58,9 +58,9 @@ describe("reportBookingHandler", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
vi.mocked(BookingRepository).mockImplementation(() => mockBookingRepo);
|
||||
vi.mocked(PrismaBookingReportRepository).mockImplementation(() => mockReportRepo);
|
||||
vi.mocked(BookingAccessService).mockImplementation(() => mockBookingAccessService);
|
||||
vi.mocked(BookingRepository).mockImplementation(function() { return mockBookingRepo; });
|
||||
vi.mocked(PrismaBookingReportRepository).mockImplementation(function() { return mockReportRepo; });
|
||||
vi.mocked(BookingAccessService).mockImplementation(function() { return mockBookingAccessService; });
|
||||
mockReportRepo.createReport.mockResolvedValue({ id: "new-report" });
|
||||
});
|
||||
|
||||
|
||||
@@ -27,9 +27,9 @@ vi.mock("@calcom/features/profile/repositories/ProfileRepository", () => ({
|
||||
const mockFilterTeamsByEventTypeReadPermission = vi.fn();
|
||||
|
||||
vi.mock("../teamAccessUseCase", () => ({
|
||||
TeamAccessUseCase: vi.fn().mockImplementation(() => ({
|
||||
TeamAccessUseCase: vi.fn().mockImplementation(function() { return {
|
||||
filterTeamsByEventTypeReadPermission: mockFilterTeamsByEventTypeReadPermission,
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/features/ee/organizations/lib/getBookerUrlServer", () => ({
|
||||
|
||||
@@ -44,7 +44,7 @@ describe("createEventPbacProcedure", () => {
|
||||
checkPermission: vi.fn(),
|
||||
};
|
||||
|
||||
vi.mocked(PermissionCheckService).mockImplementation(() => mockPermissionCheckService as any);
|
||||
vi.mocked(PermissionCheckService).mockImplementation(function() { return mockPermissionCheckService as any; });
|
||||
});
|
||||
|
||||
describe("personal events", () => {
|
||||
|
||||
@@ -15,7 +15,14 @@ vi.mock("@calcom/features/eventtypes/repositories/eventTypeRepository");
|
||||
describe("duplicateHandler", () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const ctx = { user: { id: 1, profile: { id: 1 } } } as any;
|
||||
const input = { id: 123, slug: "test-event", title: "Test", description: "Test", length: 30, teamId: null };
|
||||
const input = {
|
||||
id: 123,
|
||||
slug: "test-event",
|
||||
title: "Test",
|
||||
description: "Test",
|
||||
length: 30,
|
||||
teamId: null,
|
||||
};
|
||||
const eventType = { id: 123, userId: 1, teamId: null, users: [{ id: 1 }] };
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -23,13 +30,12 @@ describe("duplicateHandler", () => {
|
||||
prismaMock.eventType.findUnique.mockResolvedValue(eventType);
|
||||
});
|
||||
|
||||
it("should throw BAD_REQUEST in case of unique constraint violation", async () => {
|
||||
it("should throw INTERNAL_SERVER_ERROR in case of unique constraint violation", async () => {
|
||||
const { EventTypeRepository } = await import(
|
||||
"@calcom/features/eventtypes/repositories/eventTypeRepository"
|
||||
);
|
||||
vi.mocked(EventTypeRepository).mockImplementation(
|
||||
() =>
|
||||
({
|
||||
vi.mocked(EventTypeRepository).mockImplementation(function () {
|
||||
return {
|
||||
create: vi.fn().mockRejectedValue(
|
||||
new PrismaClientKnownRequestError("Unique constraint failed", {
|
||||
code: "P2002",
|
||||
@@ -37,13 +43,14 @@ describe("duplicateHandler", () => {
|
||||
})
|
||||
),
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} as any)
|
||||
);
|
||||
} as any;
|
||||
});
|
||||
|
||||
await expect(duplicateHandler({ ctx, input })).rejects.toThrow(
|
||||
new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "Error duplicating event type PrismaClientKnownRequestError: Unique constraint failed",
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
message:
|
||||
"Error duplicating event type PrismaClientKnownRequestError: Unique constraint failed",
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
@@ -6,9 +6,9 @@ import { TeamAccessUseCase } from "./teamAccessUseCase";
|
||||
|
||||
// Mock the PermissionCheckService
|
||||
vi.mock("@calcom/features/pbac/services/permission-check.service", () => ({
|
||||
PermissionCheckService: vi.fn().mockImplementation(() => ({
|
||||
PermissionCheckService: vi.fn().mockImplementation(function() { return {
|
||||
checkPermission: vi.fn(),
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
describe("TeamAccessUseCase", () => {
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ describe("deleteWatchlistEntryHandler", () => {
|
||||
);
|
||||
|
||||
vi.mocked(getOrganizationWatchlistOperationsService).mockReturnValue(mockService as never);
|
||||
vi.mocked(WatchlistRepository).mockImplementation(() => mockWatchlistRepo as never);
|
||||
vi.mocked(WatchlistRepository).mockImplementation(function() { return mockWatchlistRepo as never; });
|
||||
});
|
||||
|
||||
describe("access control", () => {
|
||||
|
||||
+6
-6
@@ -49,12 +49,12 @@ describe("dismissBookingReportHandler", () => {
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
vi.mocked(PermissionCheckService).mockImplementation(
|
||||
() => mockPermissionCheckService as InstanceType<typeof PermissionCheckService>
|
||||
);
|
||||
vi.mocked(PrismaBookingReportRepository).mockImplementation(
|
||||
() => mockReportRepo as InstanceType<typeof PrismaBookingReportRepository>
|
||||
);
|
||||
vi.mocked(PermissionCheckService).mockImplementation(function () {
|
||||
return mockPermissionCheckService as InstanceType<typeof PermissionCheckService>;
|
||||
});
|
||||
vi.mocked(PrismaBookingReportRepository).mockImplementation(function () {
|
||||
return mockReportRepo as InstanceType<typeof PrismaBookingReportRepository>;
|
||||
});
|
||||
});
|
||||
|
||||
describe("access control", () => {
|
||||
|
||||
@@ -114,7 +114,7 @@ describe("intentToCreateOrgHandler", () => {
|
||||
vi.resetAllMocks();
|
||||
await prismock.reset();
|
||||
|
||||
vi.mocked(OrganizationPaymentService).mockImplementation(() => {
|
||||
vi.mocked(OrganizationPaymentService).mockImplementation(function () {
|
||||
return {
|
||||
createOrganizationOnboarding: vi
|
||||
.fn()
|
||||
|
||||
+6
-6
@@ -81,12 +81,12 @@ describe("listBookingReportsHandler (Organization)", () => {
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
vi.mocked(PermissionCheckService).mockImplementation(
|
||||
() => mockPermissionCheckService as InstanceType<typeof PermissionCheckService>
|
||||
);
|
||||
vi.mocked(PrismaBookingReportRepository).mockImplementation(
|
||||
() => mockReportRepo as InstanceType<typeof PrismaBookingReportRepository>
|
||||
);
|
||||
vi.mocked(PermissionCheckService).mockImplementation(function () {
|
||||
return mockPermissionCheckService as InstanceType<typeof PermissionCheckService>;
|
||||
});
|
||||
vi.mocked(PrismaBookingReportRepository).mockImplementation(function () {
|
||||
return mockReportRepo as InstanceType<typeof PrismaBookingReportRepository>;
|
||||
});
|
||||
});
|
||||
|
||||
describe("access control", () => {
|
||||
|
||||
@@ -15,9 +15,9 @@ vi.mock("@calcom/prisma", () => ({
|
||||
// Mock FeaturesRepository
|
||||
const mockCheckIfTeamHasFeature = vi.fn();
|
||||
vi.mock("@calcom/features/flags/features.repository", () => ({
|
||||
FeaturesRepository: vi.fn().mockImplementation(() => ({
|
||||
FeaturesRepository: vi.fn().mockImplementation(function() { return {
|
||||
checkIfTeamHasFeature: mockCheckIfTeamHasFeature,
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
// Mock PBAC permissions
|
||||
@@ -31,16 +31,18 @@ vi.mock("@calcom/features/pbac/lib/resource-permissions", () => ({
|
||||
// Mock PermissionCheckService
|
||||
const mockCheckPermission = vi.fn().mockResolvedValue(true);
|
||||
vi.mock("@calcom/features/pbac/services/permission-check.service", () => ({
|
||||
PermissionCheckService: vi.fn().mockImplementation(() => ({
|
||||
PermissionCheckService: vi.fn().mockImplementation(function() { return {
|
||||
checkPermission: mockCheckPermission,
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
// Mock UserRepository
|
||||
vi.mock("@calcom/features/users/repositories/UserRepository", () => ({
|
||||
UserRepository: vi.fn().mockImplementation(() => ({
|
||||
UserRepository: vi.fn().mockImplementation(function() {
|
||||
return {
|
||||
enrichUserWithItsProfile: vi.fn().mockImplementation(({ user }) => user),
|
||||
})),
|
||||
};
|
||||
}),
|
||||
}));
|
||||
|
||||
const ORGANIZATION_ID = 123;
|
||||
|
||||
@@ -13,9 +13,9 @@ const dynamicImportHandler = async () => await import("./reserveSlot.handler");
|
||||
// The repository instance method is used to check for an existing reservation by someone else.
|
||||
// To keep this unit test isolated from the database layer, we stub this to always resolve falsey.
|
||||
vi.mock("@calcom/features/selectedSlots/repositories/PrismaSelectedSlotRepository", () => ({
|
||||
PrismaSelectedSlotRepository: vi.fn().mockImplementation(() => ({
|
||||
PrismaSelectedSlotRepository: vi.fn().mockImplementation(function() { return {
|
||||
findReservedByOthers: vi.fn().mockResolvedValue(null),
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
// A tiny helper to build a canned handler context with stubbed Prisma methods.
|
||||
|
||||
@@ -47,23 +47,27 @@ vi.mock("@calcom/features/flags/features.repository");
|
||||
vi.mock("@calcom/features/membership/repositories/MembershipRepository");
|
||||
vi.mock("@calcom/features/pbac/services/permission.service", () => {
|
||||
return {
|
||||
PermissionService: vi.fn().mockImplementation(() => ({
|
||||
PermissionService: vi.fn().mockImplementation(function() {
|
||||
return {
|
||||
validatePermission: vi.fn().mockReturnValue({ isValid: true }),
|
||||
validatePermissions: vi.fn().mockReturnValue({ isValid: true }),
|
||||
})),
|
||||
};
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("@calcom/features/pbac/services/permission-check.service", () => {
|
||||
return {
|
||||
PermissionCheckService: vi.fn().mockImplementation(() => ({
|
||||
PermissionCheckService: vi.fn().mockImplementation(function() {
|
||||
return {
|
||||
checkPermission: vi.fn().mockResolvedValue(true),
|
||||
checkPermissions: vi.fn().mockResolvedValue(true),
|
||||
getUserPermissions: vi.fn().mockResolvedValue([]),
|
||||
getResourcePermissions: vi.fn().mockResolvedValue([]),
|
||||
getTeamIdsWithPermission: vi.fn().mockResolvedValue([]),
|
||||
getTeamIdsWithPermissions: vi.fn().mockResolvedValue([]),
|
||||
})),
|
||||
};
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -136,12 +136,11 @@ describe("Invite Member Utils", () => {
|
||||
describe("ensureAtleastAdminPermissions", () => {
|
||||
it("It should throw an error if the user is not an admin of the ORG", async () => {
|
||||
const mockCheckPermission = vi.fn().mockResolvedValue(false);
|
||||
vi.mocked(PermissionCheckService).mockImplementation(
|
||||
() =>
|
||||
({
|
||||
vi.mocked(PermissionCheckService).mockImplementation(function () {
|
||||
return {
|
||||
checkPermission: mockCheckPermission,
|
||||
} as any)
|
||||
);
|
||||
} as any;
|
||||
});
|
||||
|
||||
await expect(ensureAtleastAdminPermissions({ userId: 1, teamId: 1, isOrg: true })).rejects.toThrow(
|
||||
"UNAUTHORIZED"
|
||||
@@ -157,12 +156,11 @@ describe("Invite Member Utils", () => {
|
||||
|
||||
it("It should NOT throw an error if the user is an admin of the ORG", async () => {
|
||||
const mockCheckPermission = vi.fn().mockResolvedValue(true);
|
||||
vi.mocked(PermissionCheckService).mockImplementation(
|
||||
() =>
|
||||
({
|
||||
vi.mocked(PermissionCheckService).mockImplementation(function () {
|
||||
return {
|
||||
checkPermission: mockCheckPermission,
|
||||
} as any)
|
||||
);
|
||||
} as any;
|
||||
});
|
||||
|
||||
await expect(
|
||||
ensureAtleastAdminPermissions({ userId: 1, teamId: 1, isOrg: true })
|
||||
|
||||
+32
-16
@@ -44,9 +44,11 @@ describe("removeHostsFromEventTypesHandler", () => {
|
||||
|
||||
it("throws UNAUTHORIZED if user does not have eventType.update permission", async () => {
|
||||
const mockCheckPermission = vi.fn().mockResolvedValue(false);
|
||||
(PermissionCheckService as any).mockImplementation(() => ({
|
||||
(PermissionCheckService as any).mockImplementation(function () {
|
||||
return {
|
||||
checkPermission: mockCheckPermission,
|
||||
}));
|
||||
};
|
||||
});
|
||||
|
||||
await expect(
|
||||
removeHostsFromEventTypesHandler({
|
||||
@@ -70,9 +72,11 @@ describe("removeHostsFromEventTypesHandler", () => {
|
||||
|
||||
it("deletes hosts when user has permission and all users are team members", async () => {
|
||||
const mockCheckPermission = vi.fn().mockResolvedValue(true);
|
||||
(PermissionCheckService as any).mockImplementation(() => ({
|
||||
(PermissionCheckService as any).mockImplementation(function () {
|
||||
return {
|
||||
checkPermission: mockCheckPermission,
|
||||
}));
|
||||
};
|
||||
});
|
||||
|
||||
// Mock that all userIds are valid team members
|
||||
(MembershipRepository.findAcceptedMembershipsByUserIdsInTeam as any).mockResolvedValue([
|
||||
@@ -119,9 +123,11 @@ describe("removeHostsFromEventTypesHandler", () => {
|
||||
|
||||
it("only removes hosts for userIds that are team members (filters out non-members)", async () => {
|
||||
const mockCheckPermission = vi.fn().mockResolvedValue(true);
|
||||
(PermissionCheckService as any).mockImplementation(() => ({
|
||||
(PermissionCheckService as any).mockImplementation(function () {
|
||||
return {
|
||||
checkPermission: mockCheckPermission,
|
||||
}));
|
||||
};
|
||||
});
|
||||
|
||||
// Mock that only userId 101 is a team member, 102 is not
|
||||
(MembershipRepository.findAcceptedMembershipsByUserIdsInTeam as any).mockResolvedValue([
|
||||
@@ -161,9 +167,11 @@ describe("removeHostsFromEventTypesHandler", () => {
|
||||
|
||||
it("handles empty userIds array", async () => {
|
||||
const mockCheckPermission = vi.fn().mockResolvedValue(true);
|
||||
(PermissionCheckService as any).mockImplementation(() => ({
|
||||
(PermissionCheckService as any).mockImplementation(function () {
|
||||
return {
|
||||
checkPermission: mockCheckPermission,
|
||||
}));
|
||||
};
|
||||
});
|
||||
|
||||
// Empty array means no memberships to validate
|
||||
(MembershipRepository.findAcceptedMembershipsByUserIdsInTeam as any).mockResolvedValue([]);
|
||||
@@ -200,9 +208,11 @@ describe("removeHostsFromEventTypesHandler", () => {
|
||||
|
||||
it("handles empty eventTypeIds array", async () => {
|
||||
const mockCheckPermission = vi.fn().mockResolvedValue(true);
|
||||
(PermissionCheckService as any).mockImplementation(() => ({
|
||||
(PermissionCheckService as any).mockImplementation(function () {
|
||||
return {
|
||||
checkPermission: mockCheckPermission,
|
||||
}));
|
||||
};
|
||||
});
|
||||
|
||||
// Mock that all userIds are valid team members
|
||||
(MembershipRepository.findAcceptedMembershipsByUserIdsInTeam as any).mockResolvedValue([
|
||||
@@ -242,9 +252,11 @@ describe("removeHostsFromEventTypesHandler", () => {
|
||||
|
||||
it("returns count of 0 when no hosts match the criteria", async () => {
|
||||
const mockCheckPermission = vi.fn().mockResolvedValue(true);
|
||||
(PermissionCheckService as any).mockImplementation(() => ({
|
||||
(PermissionCheckService as any).mockImplementation(function () {
|
||||
return {
|
||||
checkPermission: mockCheckPermission,
|
||||
}));
|
||||
};
|
||||
});
|
||||
|
||||
// Mock that all userIds are valid team members
|
||||
(MembershipRepository.findAcceptedMembershipsByUserIdsInTeam as any).mockResolvedValue([
|
||||
@@ -265,9 +277,11 @@ describe("removeHostsFromEventTypesHandler", () => {
|
||||
|
||||
it("returns count of 0 when userId is a team member but not a host on the specified event types", async () => {
|
||||
const mockCheckPermission = vi.fn().mockResolvedValue(true);
|
||||
(PermissionCheckService as any).mockImplementation(() => ({
|
||||
(PermissionCheckService as any).mockImplementation(function () {
|
||||
return {
|
||||
checkPermission: mockCheckPermission,
|
||||
}));
|
||||
};
|
||||
});
|
||||
|
||||
// User 999 is a valid team member
|
||||
(MembershipRepository.findAcceptedMembershipsByUserIdsInTeam as any).mockResolvedValue([
|
||||
@@ -307,9 +321,11 @@ describe("removeHostsFromEventTypesHandler", () => {
|
||||
|
||||
it("returns count of 0 when event types do not belong to the specified team", async () => {
|
||||
const mockCheckPermission = vi.fn().mockResolvedValue(true);
|
||||
(PermissionCheckService as any).mockImplementation(() => ({
|
||||
(PermissionCheckService as any).mockImplementation(function () {
|
||||
return {
|
||||
checkPermission: mockCheckPermission,
|
||||
}));
|
||||
};
|
||||
});
|
||||
|
||||
// Mock that all userIds are valid team members
|
||||
(MembershipRepository.findAcceptedMembershipsByUserIdsInTeam as any).mockResolvedValue([
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ describe("PBACRemoveMemberService", () => {
|
||||
getTeamIdsWithPermission: vi.fn(),
|
||||
};
|
||||
|
||||
vi.mocked(PermissionCheckService).mockImplementation(() => mockPermissionCheckService as any);
|
||||
vi.mocked(PermissionCheckService).mockImplementation(function() { return mockPermissionCheckService as any; });
|
||||
|
||||
service = new PBACRemoveMemberService();
|
||||
});
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ describe("RemoveMemberServiceFactory", () => {
|
||||
checkIfTeamHasFeature: vi.fn(),
|
||||
};
|
||||
|
||||
vi.mocked(FeaturesRepository).mockImplementation(() => mockFeaturesRepository as any);
|
||||
vi.mocked(FeaturesRepository).mockImplementation(function() { return mockFeaturesRepository as any; });
|
||||
});
|
||||
|
||||
describe("Service Creation", () => {
|
||||
|
||||
@@ -26,15 +26,15 @@ vi.mock("@calcom/prisma", () => ({
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/features/pbac/services/permission-check.service", () => ({
|
||||
PermissionCheckService: vi.fn().mockImplementation(() => ({
|
||||
PermissionCheckService: vi.fn().mockImplementation(function() { return {
|
||||
checkPermission: vi.fn(),
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/features/ee/teams/repositories/TeamRepository", () => ({
|
||||
TeamRepository: vi.fn().mockImplementation(() => ({
|
||||
TeamRepository: vi.fn().mockImplementation(function() { return {
|
||||
isSlugAvailableForUpdate: vi.fn().mockResolvedValue(true),
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/lib/server/avatar", () => ({
|
||||
@@ -64,12 +64,12 @@ describe("updateHandler - Permission Check Tests", () => {
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
vi.mocked(PermissionCheckService).mockImplementation(
|
||||
() => mockPermissionCheckService as unknown as InstanceType<typeof PermissionCheckService>
|
||||
);
|
||||
vi.mocked(TeamRepository).mockImplementation(
|
||||
() => mockTeamRepository as unknown as InstanceType<typeof TeamRepository>
|
||||
);
|
||||
vi.mocked(PermissionCheckService).mockImplementation(function () {
|
||||
return mockPermissionCheckService as unknown as InstanceType<typeof PermissionCheckService>;
|
||||
});
|
||||
vi.mocked(TeamRepository).mockImplementation(function () {
|
||||
return mockTeamRepository as unknown as InstanceType<typeof TeamRepository>;
|
||||
});
|
||||
});
|
||||
|
||||
describe("Permission Check Service", () => {
|
||||
|
||||
@@ -28,9 +28,9 @@ vi.mock("@calcom/prisma", () => ({
|
||||
const mockCheckPermission = vi.fn();
|
||||
|
||||
vi.mock("@calcom/features/pbac/services/permission-check.service", () => ({
|
||||
PermissionCheckService: vi.fn().mockImplementation(() => ({
|
||||
PermissionCheckService: vi.fn().mockImplementation(function() { return {
|
||||
checkPermission: mockCheckPermission,
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
vi.mock("../../../procedures/authedProcedure", () => ({
|
||||
|
||||
@@ -18,13 +18,12 @@ describe("isAuthorized", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
mockCheckPermission = vi.fn();
|
||||
mockPermissionCheckService.mockImplementation(
|
||||
() =>
|
||||
({
|
||||
mockPermissionCheckService.mockImplementation(function () {
|
||||
return {
|
||||
checkPermission: mockCheckPermission,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} as any)
|
||||
);
|
||||
} as any;
|
||||
});
|
||||
});
|
||||
|
||||
describe("null workflow", () => {
|
||||
|
||||
@@ -7,11 +7,13 @@ import { Button, buttonClasses } from "./Button";
|
||||
|
||||
const observeMock = vi.fn();
|
||||
|
||||
window.ResizeObserver = vi.fn().mockImplementation(() => ({
|
||||
window.ResizeObserver = vi.fn().mockImplementation(function() {
|
||||
return {
|
||||
disconnect: vi.fn(),
|
||||
observe: observeMock,
|
||||
unobserve: vi.fn(),
|
||||
}));
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("../tooltip", async () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
{}
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
import path from "path";
|
||||
import react from "@vitejs/plugin-react";
|
||||
import { defineConfig } from "vitest/config";
|
||||
|
||||
const vitestMode = process.env.VITEST_MODE;
|
||||
// Support both new VITEST_MODE env var and legacy CLI flags for backwards compatibility
|
||||
// The CLI flags are passed through but Vitest 4.0 doesn't reject them when using yarn test
|
||||
const isPackagedEmbedMode = vitestMode === "packaged-embed" || process.argv.includes("--packaged-embed-tests-only");
|
||||
const isIntegrationMode = vitestMode === "integration" || process.argv.includes("--integrationTestsOnly");
|
||||
const isTimezoneMode = vitestMode === "timezone" || process.argv.includes("--timeZoneDependentTestsOnly");
|
||||
|
||||
// Always set INTEGRATION_TEST_MODE to allow server-side imports in jsdom environment
|
||||
// This is needed because getBookingFields.ts checks for this env var to allow imports
|
||||
process.env.INTEGRATION_TEST_MODE = "true";
|
||||
|
||||
if (isTimezoneMode && !process.env.TZ) {
|
||||
throw new Error("TZ environment variable is not set for timezone tests");
|
||||
}
|
||||
|
||||
function getTestInclude() {
|
||||
if (isPackagedEmbedMode) {
|
||||
return ["packages/embeds/**/packaged/**/*.{test,spec}.{ts,js}"];
|
||||
}
|
||||
if (isIntegrationMode) {
|
||||
return ["packages/**/*.integration-test.ts", "apps/**/*.integration-test.ts"];
|
||||
}
|
||||
if (isTimezoneMode) {
|
||||
return ["packages/**/*.timezone.test.ts", "apps/**/*.timezone.test.ts"];
|
||||
}
|
||||
// Default: run all test files (Vitest default pattern)
|
||||
return ["**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"];
|
||||
}
|
||||
|
||||
function getTestExclude() {
|
||||
const baseExclude = [
|
||||
"**/node_modules/**",
|
||||
"**/dist/**",
|
||||
"apps/api/v2/**/*.spec.ts",
|
||||
"__checks__/**/*.spec.ts",
|
||||
];
|
||||
if (isIntegrationMode || isTimezoneMode) {
|
||||
return [...baseExclude, "packages/embeds/**/*"];
|
||||
}
|
||||
return baseExclude;
|
||||
}
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
resolve: {
|
||||
alias: [
|
||||
// Mock generated files that may not exist in CI (must come before general aliases)
|
||||
{
|
||||
find: "@calcom/web/public/app-store/svg-hashes.json",
|
||||
replacement: path.resolve(__dirname, "vitest-mocks/svg-hashes.json"),
|
||||
},
|
||||
{
|
||||
find: /^\.\/tailwind\.generated\.css\?inline$/,
|
||||
replacement: path.resolve(
|
||||
__dirname,
|
||||
"vitest-mocks/tailwind.generated.css"
|
||||
),
|
||||
},
|
||||
// Alias Node.js built-ins for jsdom environment
|
||||
{ find: "crypto", replacement: "node:crypto" },
|
||||
// API v1 path alias
|
||||
{ find: "~", replacement: path.resolve(__dirname, "apps/api/v1") },
|
||||
// apps/web path aliases
|
||||
{ find: "@lib", replacement: path.resolve(__dirname, "apps/web/lib") },
|
||||
{ find: "app", replacement: path.resolve(__dirname, "apps/web/app") },
|
||||
{ find: "@calcom/web", replacement: path.resolve(__dirname, "apps/web") },
|
||||
// Platform packages that need to be resolved from source in CI
|
||||
{
|
||||
find: "@calcom/platform-constants",
|
||||
replacement: path.resolve(
|
||||
__dirname,
|
||||
"packages/platform/constants/index.ts"
|
||||
),
|
||||
},
|
||||
{
|
||||
find: "@calcom/embed-react",
|
||||
replacement: path.resolve(
|
||||
__dirname,
|
||||
"packages/embeds/embed-react/src/index.ts"
|
||||
),
|
||||
},
|
||||
{
|
||||
find: "@calcom/embed-snippet",
|
||||
replacement: path.resolve(
|
||||
__dirname,
|
||||
"packages/embeds/embed-snippet/src/index.ts"
|
||||
),
|
||||
},
|
||||
],
|
||||
},
|
||||
test: {
|
||||
globals: true,
|
||||
silent: true,
|
||||
environment: "jsdom",
|
||||
setupFiles: ["./setupVitest.ts"],
|
||||
include: getTestInclude(),
|
||||
exclude: getTestExclude(),
|
||||
server: {
|
||||
deps: {
|
||||
inline: [/@calcom\/.*/],
|
||||
},
|
||||
},
|
||||
coverage: {
|
||||
provider: "v8",
|
||||
},
|
||||
passWithNoTests: true,
|
||||
testTimeout: 500000,
|
||||
},
|
||||
});
|
||||
|
||||
setEnvVariablesThatAreUsedBeforeSetup();
|
||||
|
||||
function setEnvVariablesThatAreUsedBeforeSetup() {
|
||||
// We can't set it during tests because it is used as soon as _metadata.ts is imported which happens before tests start running
|
||||
process.env.DAILY_API_KEY = "MOCK_DAILY_API_KEY";
|
||||
// With same env variable, we can test both non org and org booking scenarios
|
||||
process.env.NEXT_PUBLIC_WEBAPP_URL = "http://app.cal.local:3000";
|
||||
process.env.CALCOM_SERVICE_ACCOUNT_ENCRYPTION_KEY =
|
||||
"UNIT_TEST_ENCRYPTION_KEY";
|
||||
process.env.STRIPE_PRIVATE_KEY =
|
||||
process.env.STRIPE_PRIVATE_KEY || "sk_test_dummy_unit_test_key";
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
import { defineConfig } from "vitest/config";
|
||||
process.env.INTEGRATION_TEST_MODE = "true";
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
setupFiles: ["./setupVitest.ts"],
|
||||
|
||||
coverage: {
|
||||
provider: "v8",
|
||||
},
|
||||
passWithNoTests: true,
|
||||
testTimeout: 500000,
|
||||
},
|
||||
});
|
||||
|
||||
setEnvVariablesThatAreUsedBeforeSetup();
|
||||
|
||||
function setEnvVariablesThatAreUsedBeforeSetup() {
|
||||
// We can't set it during tests because it is used as soon as _metadata.ts is imported which happens before tests start running
|
||||
process.env.DAILY_API_KEY = "MOCK_DAILY_API_KEY";
|
||||
// With same env variable, we can test both non org and org booking scenarios
|
||||
process.env.NEXT_PUBLIC_WEBAPP_URL = "http://app.cal.local:3000";
|
||||
process.env.CALCOM_SERVICE_ACCOUNT_ENCRYPTION_KEY = "UNIT_TEST_ENCRYPTION_KEY";
|
||||
process.env.STRIPE_PRIVATE_KEY = process.env.STRIPE_PRIVATE_KEY || "sk_test_dummy_unit_test_key";
|
||||
}
|
||||
+7
-3
@@ -1,8 +1,12 @@
|
||||
import { defineWorkspace } from "vitest/config";
|
||||
|
||||
const packagedEmbedTestsOnly = process.argv.includes("--packaged-embed-tests-only");
|
||||
const timeZoneDependentTestsOnly = process.argv.includes("--timeZoneDependentTestsOnly");
|
||||
const integrationTestsOnly = process.argv.includes("--integrationTestsOnly");
|
||||
// Vitest 4.0 no longer allows custom CLI flags, so we use environment variables instead
|
||||
// eslint-disable-next-line turbo/no-undeclared-env-vars
|
||||
const packagedEmbedTestsOnly = process.env.VITEST_MODE === "packaged-embed";
|
||||
// eslint-disable-next-line turbo/no-undeclared-env-vars
|
||||
const timeZoneDependentTestsOnly = process.env.VITEST_MODE === "timezone";
|
||||
// eslint-disable-next-line turbo/no-undeclared-env-vars
|
||||
const integrationTestsOnly = process.env.VITEST_MODE === "integration";
|
||||
// eslint-disable-next-line turbo/no-undeclared-env-vars
|
||||
const envTZ = process.env.TZ;
|
||||
if (timeZoneDependentTestsOnly && !envTZ) {
|
||||
|
||||
Reference in New Issue
Block a user