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/yarn-install
|
||||||
- uses: ./.github/actions/cache-db
|
- uses: ./.github/actions/cache-db
|
||||||
- name: Run Tests
|
- name: Run Tests
|
||||||
run: yarn test -- --integrationTestsOnly
|
run: VITEST_MODE=integration yarn test
|
||||||
# TODO: Generate test results so we can upload them
|
# TODO: Generate test results so we can upload them
|
||||||
# - name: Upload Test Results
|
# - name: Upload Test Results
|
||||||
# if: ${{ always() }}
|
# if: ${{ always() }}
|
||||||
|
|||||||
@@ -16,4 +16,4 @@ jobs:
|
|||||||
- uses: ./.github/actions/yarn-install
|
- uses: ./.github/actions/yarn-install
|
||||||
- run: yarn test -- --no-isolate
|
- run: yarn test -- --no-isolate
|
||||||
# We could add different timezones here that we need to run our tests in
|
# 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(),
|
verifyKeyByHashedKey: vi.fn(),
|
||||||
} as unknown as ApiKeyService;
|
} as unknown as ApiKeyService;
|
||||||
|
|
||||||
vi.mocked(ApiKeyService).mockImplementation(() => mockApiKeyService);
|
vi.mocked(ApiKeyService).mockImplementation(function() { return mockApiKeyService; });
|
||||||
vi.mocked(PrismaApiKeyRepository).mockImplementation(() => ({} as unknown as PrismaApiKeyRepository));
|
vi.mocked(PrismaApiKeyRepository).mockImplementation(function() { return {} as unknown as PrismaApiKeyRepository; });
|
||||||
|
|
||||||
vi.mocked(isAdminGuard).mockReset();
|
vi.mocked(isAdminGuard).mockReset();
|
||||||
vi.mocked(isLockedOrBlocked).mockReset();
|
vi.mocked(isLockedOrBlocked).mockReset();
|
||||||
|
|||||||
@@ -67,9 +67,9 @@ vi.mock("@calcom/features/webhooks/lib/sendOrSchedulePayload", () => ({
|
|||||||
|
|
||||||
const mockFindOriginalRescheduledBooking = vi.fn();
|
const mockFindOriginalRescheduledBooking = vi.fn();
|
||||||
vi.mock("@calcom/features/bookings/repositories/BookingRepository", () => ({
|
vi.mock("@calcom/features/bookings/repositories/BookingRepository", () => ({
|
||||||
BookingRepository: vi.fn().mockImplementation(() => ({
|
BookingRepository: vi.fn().mockImplementation(function() { return {
|
||||||
findOriginalRescheduledBooking: mockFindOriginalRescheduledBooking,
|
findOriginalRescheduledBooking: mockFindOriginalRescheduledBooking,
|
||||||
})),
|
}; }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("@calcom/features/watchlist/operations/check-if-users-are-blocked.controller", () => ({
|
vi.mock("@calcom/features/watchlist/operations/check-if-users-are-blocked.controller", () => ({
|
||||||
@@ -87,23 +87,25 @@ vi.mock("@calcom/features/di/containers/QualifiedHosts", () => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("@calcom/features/bookings/lib/EventManager", () => ({
|
vi.mock("@calcom/features/bookings/lib/EventManager", () => ({
|
||||||
default: vi.fn().mockImplementation(() => ({
|
default: vi.fn().mockImplementation(function() {
|
||||||
reschedule: vi.fn().mockResolvedValue({
|
return {
|
||||||
results: [],
|
reschedule: vi.fn().mockResolvedValue({
|
||||||
referencesToCreate: [],
|
results: [],
|
||||||
}),
|
referencesToCreate: [],
|
||||||
create: vi.fn().mockResolvedValue({
|
}),
|
||||||
results: [],
|
create: vi.fn().mockResolvedValue({
|
||||||
referencesToCreate: [],
|
results: [],
|
||||||
}),
|
referencesToCreate: [],
|
||||||
update: vi.fn().mockResolvedValue({
|
}),
|
||||||
results: [],
|
update: vi.fn().mockResolvedValue({
|
||||||
referencesToCreate: [],
|
results: [],
|
||||||
}),
|
referencesToCreate: [],
|
||||||
createAllCalendarEvents: vi.fn().mockResolvedValue([]),
|
}),
|
||||||
updateAllCalendarEvents: vi.fn().mockResolvedValue([]),
|
createAllCalendarEvents: vi.fn().mockResolvedValue([]),
|
||||||
deleteEventsAndMeetings: vi.fn().mockResolvedValue([]),
|
updateAllCalendarEvents: vi.fn().mockResolvedValue([]),
|
||||||
})),
|
deleteEventsAndMeetings: vi.fn().mockResolvedValue([]),
|
||||||
|
};
|
||||||
|
}),
|
||||||
placeholderCreatedEvent: {
|
placeholderCreatedEvent: {
|
||||||
results: [],
|
results: [],
|
||||||
referencesToCreate: [],
|
referencesToCreate: [],
|
||||||
@@ -146,10 +148,10 @@ vi.mock("@calcom/features/profile/repositories/ProfileRepository", () => ({
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
vi.mock("@calcom/features/flags/features.repository", () => ({
|
vi.mock("@calcom/features/flags/features.repository", () => ({
|
||||||
FeaturesRepository: vi.fn().mockImplementation(() => ({
|
FeaturesRepository: vi.fn().mockImplementation(function() { return {
|
||||||
checkIfFeatureIsEnabledGlobally: vi.fn().mockResolvedValue(false),
|
checkIfFeatureIsEnabledGlobally: vi.fn().mockResolvedValue(false),
|
||||||
checkIfTeamHasFeature: vi.fn().mockResolvedValue(false),
|
checkIfTeamHasFeature: vi.fn().mockResolvedValue(false),
|
||||||
})),
|
}; }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("@calcom/features/webhooks/lib/getWebhooks", () => ({
|
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();
|
const mockCreate = vi.fn();
|
||||||
vi.mock("@calcom/features/users/repositories/UserRepository", () => ({
|
vi.mock("@calcom/features/users/repositories/UserRepository", () => ({
|
||||||
UserRepository: vi.fn().mockImplementation(() => ({
|
UserRepository: vi.fn().mockImplementation(function() { return {
|
||||||
create: mockCreate,
|
create: mockCreate,
|
||||||
})),
|
}; }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("@calcom/lib/auth/hashPassword", () => ({
|
vi.mock("@calcom/lib/auth/hashPassword", () => ({
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ import { handleCreateSelectedCalendars, isSameEmail } from "../route";
|
|||||||
const getPrimaryCalendarMock = vi.fn();
|
const getPrimaryCalendarMock = vi.fn();
|
||||||
vi.mock("@calcom/app-store/googlecalendar/lib/CalendarService", () => {
|
vi.mock("@calcom/app-store/googlecalendar/lib/CalendarService", () => {
|
||||||
return {
|
return {
|
||||||
default: vi.fn().mockImplementation(() => ({
|
default: vi.fn().mockImplementation(function() { return {
|
||||||
getPrimaryCalendar: getPrimaryCalendarMock,
|
getPrimaryCalendar: getPrimaryCalendarMock,
|
||||||
})),
|
}; }),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -50,9 +50,9 @@ const mockQueuedFormResponse = {
|
|||||||
|
|
||||||
describe("queuedResponseHandler", () => {
|
describe("queuedResponseHandler", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.mocked(RoutingFormResponseRepository).mockImplementation(
|
vi.mocked(RoutingFormResponseRepository).mockImplementation(function () {
|
||||||
() => mockRoutingFormResponseRepository as any
|
return mockRoutingFormResponseRepository as any;
|
||||||
);
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should process a queued form response", async () => {
|
it("should process a queued form response", async () => {
|
||||||
|
|||||||
@@ -6,14 +6,14 @@ import { getOGImageVersion } from "@calcom/lib/OgImages";
|
|||||||
import { GET } from "../route";
|
import { GET } from "../route";
|
||||||
|
|
||||||
vi.mock("next/og", () => ({
|
vi.mock("next/og", () => ({
|
||||||
ImageResponse: vi.fn().mockImplementation(() => ({
|
ImageResponse: vi.fn().mockImplementation(function() { return {
|
||||||
body: new ReadableStream({
|
body: new ReadableStream({
|
||||||
start(controller) {
|
start(controller) {
|
||||||
controller.enqueue(new Uint8Array([1, 2, 3, 4]));
|
controller.enqueue(new Uint8Array([1, 2, 3, 4]));
|
||||||
controller.close();
|
controller.close();
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
})),
|
}; }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("@calcom/lib/OgImages", async (importOriginal) => {
|
vi.mock("@calcom/lib/OgImages", async (importOriginal) => {
|
||||||
@@ -102,8 +102,11 @@ describe("GET /api/social/og/image", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("Server errors (500 Internal Server Error)", () => {
|
describe("Server errors (500 Internal Server Error)", () => {
|
||||||
test("returns 500 when font loading fails", async () => {
|
test("returns 500 when ImageResponse throws", async () => {
|
||||||
vi.mocked(global.fetch).mockRejectedValue(new Error("Font loading failed"));
|
const { ImageResponse } = await import("next/og");
|
||||||
|
vi.mocked(ImageResponse).mockImplementation(function () {
|
||||||
|
throw new Error("ImageResponse failed");
|
||||||
|
});
|
||||||
|
|
||||||
const request = createNextRequest(
|
const request = createNextRequest(
|
||||||
"http://example.com/api/social/og/image?type=meeting&title=Test&meetingProfileName=John"
|
"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();
|
const mockSendCreditBalanceLowWarningEmails = vi.fn();
|
||||||
|
|
||||||
vi.mock("@calcom/features/ee/billing/credit-service", () => ({
|
vi.mock("@calcom/features/ee/billing/credit-service", () => ({
|
||||||
CreditService: vi.fn().mockImplementation(() => ({
|
CreditService: vi.fn().mockImplementation(function() { return {
|
||||||
hasAvailableCredits: mockHasAvailableCredits,
|
hasAvailableCredits: mockHasAvailableCredits,
|
||||||
chargeCredits: mockChargeCredits,
|
chargeCredits: mockChargeCredits,
|
||||||
})),
|
}; }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("@calcom/emails/email-manager", () => ({
|
vi.mock("@calcom/emails/email-manager", () => ({
|
||||||
@@ -92,15 +92,15 @@ const mockFindByPhoneNumber = vi.fn();
|
|||||||
const mockFindByProviderAgentId = vi.fn();
|
const mockFindByProviderAgentId = vi.fn();
|
||||||
|
|
||||||
vi.mock("@calcom/features/calAIPhone/repositories/PrismaPhoneNumberRepository", () => ({
|
vi.mock("@calcom/features/calAIPhone/repositories/PrismaPhoneNumberRepository", () => ({
|
||||||
PrismaPhoneNumberRepository: vi.fn().mockImplementation(() => ({
|
PrismaPhoneNumberRepository: vi.fn().mockImplementation(function() { return {
|
||||||
findByPhoneNumber: mockFindByPhoneNumber,
|
findByPhoneNumber: mockFindByPhoneNumber,
|
||||||
})),
|
}; }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("@calcom/features/calAIPhone/repositories/PrismaAgentRepository", () => ({
|
vi.mock("@calcom/features/calAIPhone/repositories/PrismaAgentRepository", () => ({
|
||||||
PrismaAgentRepository: vi.fn().mockImplementation(() => ({
|
PrismaAgentRepository: vi.fn().mockImplementation(function() { return {
|
||||||
findByProviderAgentId: mockFindByProviderAgentId,
|
findByProviderAgentId: mockFindByProviderAgentId,
|
||||||
})),
|
}; }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("next/server", () => ({
|
vi.mock("next/server", () => ({
|
||||||
|
|||||||
@@ -89,6 +89,10 @@ vi.mock("@calcom/lib/hooks/useLocale", () => ({
|
|||||||
useLocale: vi.fn(() => ({ t: (key: string) => key })),
|
useLocale: vi.fn(() => ({ t: (key: string) => key })),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
vi.mock("@calcom/features/ee/organizations/context/provider", () => ({
|
||||||
|
useOrgBranding: vi.fn(() => null),
|
||||||
|
}));
|
||||||
|
|
||||||
let findTeamMembersMatchingAttributeLogicResponse: {
|
let findTeamMembersMatchingAttributeLogicResponse: {
|
||||||
result: { users: { email: string }[] } | null;
|
result: { users: { email: string }[] } | null;
|
||||||
checkedFallback: boolean;
|
checkedFallback: boolean;
|
||||||
|
|||||||
@@ -85,6 +85,10 @@ vi.mock("@calcom/lib/hooks/useLocale", () => ({
|
|||||||
useLocale: vi.fn(() => ({ t: (key: string) => key })),
|
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", () => ({
|
vi.mock("@calcom/web/lib/hooks/useRouterQuery", () => ({
|
||||||
default: vi.fn(() => {
|
default: vi.fn(() => {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -10,6 +10,14 @@ vi.mock("@calcom/lib/constants", async () => {
|
|||||||
return await vi.importActual("@calcom/lib/constants");
|
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>>) {
|
function mockedUserPageComponentProps(props: Partial<React.ComponentProps<typeof UserPage>>) {
|
||||||
return {
|
return {
|
||||||
themeBasis: "dark",
|
themeBasis: "dark",
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ import { validateIntervalLimitOrder } from "@calcom/lib/intervalLimits/validateI
|
|||||||
|
|
||||||
const mockCountBookingsByEventTypeAndDateRange = vi.fn();
|
const mockCountBookingsByEventTypeAndDateRange = vi.fn();
|
||||||
vi.mock("@calcom/features/bookings/repositories/BookingRepository", () => ({
|
vi.mock("@calcom/features/bookings/repositories/BookingRepository", () => ({
|
||||||
BookingRepository: vi.fn().mockImplementation(() => ({
|
BookingRepository: vi.fn().mockImplementation(function() { return {
|
||||||
countBookingsByEventTypeAndDateRange: mockCountBookingsByEventTypeAndDateRange,
|
countBookingsByEventTypeAndDateRange: mockCountBookingsByEventTypeAndDateRange,
|
||||||
})),
|
}; }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
type Mockdata = {
|
type Mockdata = {
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ import { validateIntervalLimitOrder } from "@calcom/lib/intervalLimits/validateI
|
|||||||
|
|
||||||
const mockGetTotalBookingDuration = vi.fn();
|
const mockGetTotalBookingDuration = vi.fn();
|
||||||
vi.mock("@calcom/features/bookings/repositories/BookingRepository", () => ({
|
vi.mock("@calcom/features/bookings/repositories/BookingRepository", () => ({
|
||||||
BookingRepository: vi.fn().mockImplementation(() => ({
|
BookingRepository: vi.fn().mockImplementation(function() { return {
|
||||||
getTotalBookingDuration: mockGetTotalBookingDuration,
|
getTotalBookingDuration: mockGetTotalBookingDuration,
|
||||||
})),
|
}; }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
type MockData = {
|
type MockData = {
|
||||||
|
|||||||
@@ -18,13 +18,15 @@ import { setupAndTeardown } from "./setupAndTeardown";
|
|||||||
|
|
||||||
// Mock the FeaturesRepository to enable restriction-schedule feature
|
// Mock the FeaturesRepository to enable restriction-schedule feature
|
||||||
vi.mock("@calcom/features/flags/features.repository", () => ({
|
vi.mock("@calcom/features/flags/features.repository", () => ({
|
||||||
FeaturesRepository: vi.fn().mockImplementation(() => ({
|
FeaturesRepository: vi.fn().mockImplementation(function() {
|
||||||
checkIfTeamHasFeature: vi.fn().mockResolvedValue(true),
|
return {
|
||||||
checkIfFeatureIsEnabledGlobally: vi.fn().mockResolvedValue(true),
|
checkIfTeamHasFeature: vi.fn().mockResolvedValue(true),
|
||||||
getAllFeatures: vi.fn().mockResolvedValue([]),
|
checkIfFeatureIsEnabledGlobally: vi.fn().mockResolvedValue(true),
|
||||||
getFeatureFlagMap: vi.fn().mockResolvedValue({}),
|
getAllFeatures: vi.fn().mockResolvedValue([]),
|
||||||
checkIfUserHasFeature: vi.fn().mockResolvedValue(true),
|
getFeatureFlagMap: vi.fn().mockResolvedValue({}),
|
||||||
})),
|
checkIfUserHasFeature: vi.fn().mockResolvedValue(true),
|
||||||
|
};
|
||||||
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
type ScheduleScenario = {
|
type ScheduleScenario = {
|
||||||
|
|||||||
@@ -1,39 +1,39 @@
|
|||||||
import { createOrganization } from "@calcom/web/test/utils/bookingScenario/bookingScenario";
|
import { createOrganization } from "@calcom/web/test/utils/bookingScenario/bookingScenario";
|
||||||
|
|
||||||
import type { TestFunction } from "vitest";
|
|
||||||
|
|
||||||
import { WEBSITE_URL } from "@calcom/lib/constants";
|
import { WEBSITE_URL } from "@calcom/lib/constants";
|
||||||
import { test } from "@calcom/web/test/fixtures/fixtures";
|
import { test } from "@calcom/web/test/fixtures/fixtures";
|
||||||
import type { Fixtures } 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 WEBSITE_PROTOCOL = new URL(WEBSITE_URL).protocol;
|
||||||
const _testWithAndWithoutOrg = (
|
const _testWithAndWithoutOrg = (
|
||||||
description: Parameters<typeof testWithAndWithoutOrg>[0],
|
description: string,
|
||||||
fn: Parameters<typeof testWithAndWithoutOrg>[1],
|
fn: (context: Fixtures & OrgContext) => Promise<void> | void,
|
||||||
timeout: Parameters<typeof testWithAndWithoutOrg>[2],
|
timeout: number | undefined,
|
||||||
mode: "only" | "skip" | "run" = "run"
|
mode: "only" | "skip" | "run" = "run"
|
||||||
) => {
|
): void => {
|
||||||
const t = mode === "only" ? test.only : mode === "skip" ? test.skip : test;
|
const t = mode === "only" ? test.only : mode === "skip" ? test.skip : test;
|
||||||
t(
|
t(
|
||||||
`${description} - With org`,
|
`${description} - With org`,
|
||||||
async ({ emails, sms, task, onTestFailed, expect, skip, onTestFinished }) => {
|
async ({ emails, sms }) => {
|
||||||
const org = await createOrganization({
|
const org = await createOrganization({
|
||||||
name: "Test Org",
|
name: "Test Org",
|
||||||
slug: "testorg",
|
slug: "testorg",
|
||||||
});
|
});
|
||||||
|
|
||||||
await fn({
|
await fn({
|
||||||
task,
|
|
||||||
onTestFailed,
|
|
||||||
expect,
|
|
||||||
emails,
|
emails,
|
||||||
sms,
|
sms,
|
||||||
skip,
|
|
||||||
org: {
|
org: {
|
||||||
organization: org,
|
organization: org,
|
||||||
urlOrigin: `${WEBSITE_PROTOCOL}//${org.slug}.cal.local:3000`,
|
urlOrigin: `${WEBSITE_PROTOCOL}//${org.slug}.cal.local:3000`,
|
||||||
},
|
},
|
||||||
onTestFinished,
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
timeout
|
timeout
|
||||||
@@ -41,41 +41,31 @@ const _testWithAndWithoutOrg = (
|
|||||||
|
|
||||||
t(
|
t(
|
||||||
`${description}`,
|
`${description}`,
|
||||||
async ({ emails, sms, task, onTestFailed, expect, skip, onTestFinished }) => {
|
async ({ emails, sms }) => {
|
||||||
await fn({
|
await fn({
|
||||||
emails,
|
emails,
|
||||||
sms,
|
sms,
|
||||||
task,
|
|
||||||
onTestFailed,
|
|
||||||
expect,
|
|
||||||
skip,
|
|
||||||
org: null,
|
org: null,
|
||||||
onTestFinished,
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
timeout
|
timeout
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type TestFunctionWithOrg = (context: Fixtures & OrgContext) => Promise<void> | void;
|
||||||
|
|
||||||
export const testWithAndWithoutOrg = (
|
export const testWithAndWithoutOrg = (
|
||||||
description: string,
|
description: string,
|
||||||
fn: TestFunction<
|
fn: TestFunctionWithOrg,
|
||||||
Fixtures & {
|
|
||||||
org: {
|
|
||||||
organization: { id: number | null };
|
|
||||||
urlOrigin?: string;
|
|
||||||
} | null;
|
|
||||||
}
|
|
||||||
>,
|
|
||||||
timeout?: number
|
timeout?: number
|
||||||
) => {
|
): void => {
|
||||||
_testWithAndWithoutOrg(description, fn, timeout, "run");
|
_testWithAndWithoutOrg(description, fn, timeout, "run");
|
||||||
};
|
};
|
||||||
|
|
||||||
testWithAndWithoutOrg.only = ((description, fn, timeout) => {
|
testWithAndWithoutOrg.only = ((description: string, fn: TestFunctionWithOrg, timeout?: number): void => {
|
||||||
_testWithAndWithoutOrg(description, fn, timeout, "only");
|
_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");
|
_testWithAndWithoutOrg(description, fn, timeout, "skip");
|
||||||
}) as typeof _testWithAndWithoutOrg;
|
}) as typeof testWithAndWithoutOrg;
|
||||||
|
|||||||
+11
-5
@@ -69,6 +69,16 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"overrides": [
|
"overrides": [
|
||||||
|
{
|
||||||
|
"includes": ["**/*.test.ts", "**/*.test.tsx"],
|
||||||
|
"linter": {
|
||||||
|
"rules": {
|
||||||
|
"complexity": {
|
||||||
|
"useArrowFunction": "off"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"includes": ["**/*.tsx"],
|
"includes": ["**/*.tsx"],
|
||||||
"javascript": {
|
"javascript": {
|
||||||
@@ -76,11 +86,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"includes": [
|
"includes": ["apps/web/app/**/page.tsx", "apps/web/app/**/layout.tsx", "apps/web/app/pages/**/*.tsx"],
|
||||||
"apps/web/app/**/page.tsx",
|
|
||||||
"apps/web/app/**/layout.tsx",
|
|
||||||
"apps/web/app/pages/**/*.tsx"
|
|
||||||
],
|
|
||||||
"linter": {
|
"linter": {
|
||||||
"rules": {
|
"rules": {
|
||||||
"style": {
|
"style": {
|
||||||
|
|||||||
+4
-4
@@ -95,7 +95,7 @@
|
|||||||
"@snaplet/copycat": "4.1.0",
|
"@snaplet/copycat": "4.1.0",
|
||||||
"@testing-library/jest-dom": "5.17.0",
|
"@testing-library/jest-dom": "5.17.0",
|
||||||
"@testing-library/react": "16.0.1",
|
"@testing-library/react": "16.0.1",
|
||||||
"@vitest/ui": "2.1.9",
|
"@vitest/ui": "4.0.16",
|
||||||
"c8": "7.13.0",
|
"c8": "7.13.0",
|
||||||
"checkly": "latest",
|
"checkly": "latest",
|
||||||
"dotenv-checker": "1.1.5",
|
"dotenv-checker": "1.1.5",
|
||||||
@@ -113,9 +113,9 @@
|
|||||||
"tsc-absolute": "1.0.0",
|
"tsc-absolute": "1.0.0",
|
||||||
"turbo": "2.7.1",
|
"turbo": "2.7.1",
|
||||||
"typescript": "5.9.3",
|
"typescript": "5.9.3",
|
||||||
"vitest": "2.1.9",
|
"vitest": "4.0.16",
|
||||||
"vitest-fetch-mock": "0.3.0",
|
"vitest-fetch-mock": "0.4.5",
|
||||||
"vitest-mock-extended": "2.0.2"
|
"vitest-mock-extended": "3.1.0"
|
||||||
},
|
},
|
||||||
"resolutions": {
|
"resolutions": {
|
||||||
"types-ramda": "0.29.4",
|
"types-ramda": "0.29.4",
|
||||||
|
|||||||
@@ -32,7 +32,9 @@ export function generateTextResponse({
|
|||||||
status?: number;
|
status?: number;
|
||||||
statusText?: string;
|
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,
|
status: status,
|
||||||
statusText: statusText,
|
statusText: statusText,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ const calendarMockImplementation = {
|
|||||||
|
|
||||||
const calendarMock = {
|
const calendarMock = {
|
||||||
calendar_v3: {
|
calendar_v3: {
|
||||||
Calendar: vi.fn().mockImplementation(() => calendarMockImplementation),
|
Calendar: vi.fn().mockImplementation(function() { return calendarMockImplementation; }),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const adminMock = {
|
const adminMock = {
|
||||||
@@ -88,7 +88,7 @@ vi.mock("googleapis-common", async () => {
|
|||||||
const actual = await vi.importActual("googleapis-common");
|
const actual = await vi.importActual("googleapis-common");
|
||||||
return {
|
return {
|
||||||
...actual,
|
...actual,
|
||||||
OAuth2Client: vi.fn().mockImplementation((...args: [string, string, string]) => {
|
OAuth2Client: vi.fn().mockImplementation(function(...args: [string, string, string]) {
|
||||||
lastCreatedOAuth2Client = {
|
lastCreatedOAuth2Client = {
|
||||||
type: "oauth2",
|
type: "oauth2",
|
||||||
args,
|
args,
|
||||||
@@ -104,7 +104,7 @@ vi.mock("googleapis-common", async () => {
|
|||||||
};
|
};
|
||||||
return lastCreatedOAuth2Client;
|
return lastCreatedOAuth2Client;
|
||||||
}),
|
}),
|
||||||
JWT: vi.fn().mockImplementation((config: MockJWT["config"]) => {
|
JWT: vi.fn().mockImplementation(function(config: MockJWT["config"]) {
|
||||||
lastCreatedJWT = {
|
lastCreatedJWT = {
|
||||||
type: "jwt",
|
type: "jwt",
|
||||||
config,
|
config,
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ export const createMockJWTInstance = ({
|
|||||||
createGToken: vi.fn(),
|
createGToken: vi.fn(),
|
||||||
};
|
};
|
||||||
|
|
||||||
vi.mocked(JWT).mockImplementation(() => {
|
vi.mocked(JWT).mockImplementation(function() {
|
||||||
setLastCreatedJWT(mockJWTInstance);
|
setLastCreatedJWT(mockJWTInstance);
|
||||||
return mockJWTInstance as unknown as JWT;
|
return mockJWTInstance as unknown as JWT;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ vi.mock("../../_utils/getParsedAppKeysFromSlug", () => ({
|
|||||||
|
|
||||||
const mockRequestRaw = vi.fn();
|
const mockRequestRaw = vi.fn();
|
||||||
vi.mock("../../_utils/oauth/OAuthManager", () => ({
|
vi.mock("../../_utils/oauth/OAuthManager", () => ({
|
||||||
OAuthManager: vi.fn().mockImplementation(() => {
|
OAuthManager: vi.fn().mockImplementation(function() {
|
||||||
return { requestRaw: mockRequestRaw };
|
return { requestRaw: mockRequestRaw };
|
||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
/**
|
||||||
|
* @vitest-environment node
|
||||||
|
*/
|
||||||
import "@calcom/lib/__mocks__/logger";
|
import "@calcom/lib/__mocks__/logger";
|
||||||
import { prisma } from "@calcom/prisma/__mocks__/prisma";
|
import { prisma } from "@calcom/prisma/__mocks__/prisma";
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ vi.mock("@calcom/lib/constants", () => {
|
|||||||
vi.mock("@jsforce/jsforce-node", () => {
|
vi.mock("@jsforce/jsforce-node", () => {
|
||||||
return {
|
return {
|
||||||
default: {
|
default: {
|
||||||
Connection: vi.fn().mockImplementation(() => ({})),
|
Connection: vi.fn().mockImplementation(function() { return {}; }),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -116,13 +116,15 @@ describe("SalesforceCRMService", () => {
|
|||||||
// Override jsforce mock with our custom mock
|
// Override jsforce mock with our custom mock
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
// @ts-ignore - Not full implementation of jsforce.Connection
|
// @ts-ignore - Not full implementation of jsforce.Connection
|
||||||
vi.mocked(jsforce.Connection).mockImplementation(() => ({
|
vi.mocked(jsforce.Connection).mockImplementation(function() {
|
||||||
...salesforceMock.mockConnection,
|
return {
|
||||||
version: "1.0",
|
...salesforceMock.mockConnection,
|
||||||
loginUrl: "https://test.salesforce.com",
|
version: "1.0",
|
||||||
instanceUrl: "https://test.salesforce.com",
|
loginUrl: "https://test.salesforce.com",
|
||||||
accessToken: "123",
|
instanceUrl: "https://test.salesforce.com",
|
||||||
}));
|
accessToken: "123",
|
||||||
|
};
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("createOnLeadAndSearchOnAccount", () => {
|
describe("createOnLeadAndSearchOnAccount", () => {
|
||||||
|
|||||||
@@ -20,11 +20,15 @@ vi.mock("@calcom/prisma", () => ({
|
|||||||
|
|
||||||
vi.mock("../../lib/getCustomerAndCheckoutSession");
|
vi.mock("../../lib/getCustomerAndCheckoutSession");
|
||||||
vi.mock("@calcom/features/auth/lib/sendVerificationRequest");
|
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 mockGetCustomerAndCheckoutSession = vi.mocked(getCustomerAndCheckoutSession);
|
||||||
const mockSendVerificationRequest = vi.mocked(sendVerificationRequest);
|
const mockSendVerificationRequest = vi.mocked(sendVerificationRequest);
|
||||||
const mockVerificationTokenService = vi.mocked(VerificationTokenService);
|
const mockVerificationTokenServiceCreate = vi.mocked(VerificationTokenService.create);
|
||||||
|
|
||||||
// Type the mocked prisma properly
|
// Type the mocked prisma properly
|
||||||
const mockPrisma = prisma as unknown as {
|
const mockPrisma = prisma as unknown as {
|
||||||
@@ -84,7 +88,7 @@ describe("paymentCallback", () => {
|
|||||||
username: "premium-user",
|
username: "premium-user",
|
||||||
} as any); // eslint-disable-line @typescript-eslint/no-explicit-any
|
} as any); // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||||
|
|
||||||
mockVerificationTokenService.create.mockResolvedValue("test-token-123");
|
mockVerificationTokenServiceCreate.mockResolvedValue("test-token-123");
|
||||||
mockSendVerificationRequest.mockResolvedValue(undefined);
|
mockSendVerificationRequest.mockResolvedValue(undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -94,12 +98,12 @@ describe("paymentCallback", () => {
|
|||||||
|
|
||||||
await handler(mockReq as NextApiRequest, mockRes as NextApiResponse);
|
await handler(mockReq as NextApiRequest, mockRes as NextApiResponse);
|
||||||
|
|
||||||
expect(mockVerificationTokenService.create).toHaveBeenCalledWith({
|
expect(mockVerificationTokenServiceCreate).toHaveBeenCalledWith({
|
||||||
identifier: "test@example.com",
|
identifier: "test@example.com",
|
||||||
expires: expect.any(Date),
|
expires: expect.any(Date),
|
||||||
});
|
});
|
||||||
|
|
||||||
const callArgs = mockVerificationTokenService.create.mock.calls[0][0];
|
const callArgs = mockVerificationTokenServiceCreate.mock.calls[0][0];
|
||||||
const expiresDate = callArgs.expires;
|
const expiresDate = callArgs.expires;
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const oneDayInMs = 86400 * 1000;
|
const oneDayInMs = 86400 * 1000;
|
||||||
@@ -124,7 +128,7 @@ describe("paymentCallback", () => {
|
|||||||
const { default: handler } = await import("../paymentCallback");
|
const { default: handler } = await import("../paymentCallback");
|
||||||
const callOrder: string[] = [];
|
const callOrder: string[] = [];
|
||||||
|
|
||||||
mockVerificationTokenService.create.mockImplementation(async () => {
|
mockVerificationTokenServiceCreate.mockImplementation(async function () {
|
||||||
callOrder.push("create-token");
|
callOrder.push("create-token");
|
||||||
return "test-token";
|
return "test-token";
|
||||||
});
|
});
|
||||||
@@ -154,7 +158,7 @@ describe("paymentCallback", () => {
|
|||||||
|
|
||||||
await handler(mockReq as NextApiRequest, mockRes as NextApiResponse);
|
await handler(mockReq as NextApiRequest, mockRes as NextApiResponse);
|
||||||
|
|
||||||
expect(mockVerificationTokenService.create).not.toHaveBeenCalled();
|
expect(mockVerificationTokenServiceCreate).not.toHaveBeenCalled();
|
||||||
expect(mockSendVerificationRequest).not.toHaveBeenCalled();
|
expect(mockSendVerificationRequest).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -173,7 +177,7 @@ describe("paymentCallback", () => {
|
|||||||
|
|
||||||
await handler(mockReq as NextApiRequest, mockRes as NextApiResponse);
|
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
|
identifier: "different@example.com", // Should use user.email from found user
|
||||||
expires: expect.any(Date),
|
expires: expect.any(Date),
|
||||||
});
|
});
|
||||||
@@ -188,7 +192,7 @@ describe("paymentCallback", () => {
|
|||||||
return {} as any; // eslint-disable-line @typescript-eslint/no-explicit-any
|
return {} as any; // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||||
});
|
});
|
||||||
|
|
||||||
mockVerificationTokenService.create.mockImplementation(async () => {
|
mockVerificationTokenServiceCreate.mockImplementation(async function () {
|
||||||
callOrder.push("create-token");
|
callOrder.push("create-token");
|
||||||
return "token";
|
return "token";
|
||||||
});
|
});
|
||||||
@@ -225,7 +229,7 @@ describe("paymentCallback", () => {
|
|||||||
expect((error as HttpError).statusCode).toBe(404);
|
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 () => {
|
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((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 () => {
|
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);
|
await handler(mockReq as NextApiRequest, mockRes as NextApiResponse);
|
||||||
|
|
||||||
expect(mockVerificationTokenService.create).toHaveBeenCalledWith({
|
expect(mockVerificationTokenServiceCreate).toHaveBeenCalledWith({
|
||||||
identifier: "test@example.com", // Should use user.email
|
identifier: "test@example.com", // Should use user.email
|
||||||
expires: expect.any(Date),
|
expires: expect.any(Date),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -124,7 +124,9 @@ describe("Portal API - Service-Based Architecture", () => {
|
|||||||
mockTeamRepo = {
|
mockTeamRepo = {
|
||||||
findById: vi.fn(),
|
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 () => {
|
it("should create OrganizationBillingPortalService for organizations", async () => {
|
||||||
@@ -167,14 +169,16 @@ describe("Portal API - Service-Based Architecture", () => {
|
|||||||
checkPermission: vi.fn().mockResolvedValue(true),
|
checkPermission: vi.fn().mockResolvedValue(true),
|
||||||
};
|
};
|
||||||
|
|
||||||
vi.mocked(PermissionCheckService).mockImplementation(
|
vi.mocked(PermissionCheckService).mockImplementation(function () {
|
||||||
() => mockPermissionServiceInstance as unknown as PermissionCheckService
|
return mockPermissionServiceInstance as unknown as PermissionCheckService;
|
||||||
);
|
});
|
||||||
|
|
||||||
const mockTeamRepo: MockTeamRepository = {
|
const mockTeamRepo: MockTeamRepository = {
|
||||||
findById: vi.fn(),
|
findById: vi.fn(),
|
||||||
};
|
};
|
||||||
mockTeamRepository.mockImplementation(() => mockTeamRepo as unknown as TeamRepository);
|
mockTeamRepository.mockImplementation(function () {
|
||||||
|
return mockTeamRepo as unknown as TeamRepository;
|
||||||
|
});
|
||||||
|
|
||||||
service = new TeamBillingPortalService();
|
service = new TeamBillingPortalService();
|
||||||
});
|
});
|
||||||
@@ -201,9 +205,9 @@ describe("Portal API - Service-Based Architecture", () => {
|
|||||||
checkPermission: vi.fn().mockResolvedValue(true),
|
checkPermission: vi.fn().mockResolvedValue(true),
|
||||||
};
|
};
|
||||||
|
|
||||||
vi.mocked(PermissionCheckService).mockImplementation(
|
vi.mocked(PermissionCheckService).mockImplementation(function () {
|
||||||
() => mockPermissionServiceInstance as unknown as PermissionCheckService
|
return mockPermissionServiceInstance as unknown as PermissionCheckService;
|
||||||
);
|
});
|
||||||
|
|
||||||
service = new OrganizationBillingPortalService();
|
service = new OrganizationBillingPortalService();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -28,16 +28,16 @@ export default oAuthManagerMock;
|
|||||||
const setFullMockOAuthManagerRequest = () => {
|
const setFullMockOAuthManagerRequest = () => {
|
||||||
useFullMockOAuthManagerRequest = true;
|
useFullMockOAuthManagerRequest = true;
|
||||||
};
|
};
|
||||||
const defaultMockOAuthManager = vi.fn().mockImplementation(() => {
|
const defaultMockOAuthManager = vi.fn().mockImplementation(function() {
|
||||||
return {
|
return {
|
||||||
getTokenObjectOrFetch: vi.fn().mockImplementation(() => {
|
getTokenObjectOrFetch: vi.fn().mockImplementation(function() {
|
||||||
return {
|
return {
|
||||||
token: {
|
token: {
|
||||||
access_token: "FAKE_ACCESS_TOKEN",
|
access_token: "FAKE_ACCESS_TOKEN",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
request: vi.fn().mockImplementation((fn) => {
|
request: vi.fn().mockImplementation(function(fn) {
|
||||||
if (useFullMockOAuthManagerRequest) {
|
if (useFullMockOAuthManagerRequest) {
|
||||||
console.log("OAuthManager.request full mock being used");
|
console.log("OAuthManager.request full mock being used");
|
||||||
return oAuthManagerRequestFullMock(fn);
|
return oAuthManagerRequestFullMock(fn);
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ import { shouldSkipAttendeeEmailWithSettings, fetchOrganizationEmailSettings } f
|
|||||||
const mockGetEmailSettings = vi.fn();
|
const mockGetEmailSettings = vi.fn();
|
||||||
|
|
||||||
vi.mock("@calcom/features/organizations/repositories/OrganizationSettingsRepository", () => ({
|
vi.mock("@calcom/features/organizations/repositories/OrganizationSettingsRepository", () => ({
|
||||||
OrganizationSettingsRepository: vi.fn().mockImplementation(() => ({
|
OrganizationSettingsRepository: vi.fn().mockImplementation(function() { return {
|
||||||
getEmailSettings: mockGetEmailSettings,
|
getEmailSettings: mockGetEmailSettings,
|
||||||
})),
|
}; }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("@calcom/prisma", () => ({
|
vi.mock("@calcom/prisma", () => ({
|
||||||
|
|||||||
@@ -45,13 +45,13 @@
|
|||||||
"@playwright/test": "1.57.0",
|
"@playwright/test": "1.57.0",
|
||||||
"@tailwindcss/cli": "4.1.16",
|
"@tailwindcss/cli": "4.1.16",
|
||||||
"@tailwindcss/postcss": "4.1.15",
|
"@tailwindcss/postcss": "4.1.15",
|
||||||
"@vitejs/plugin-basic-ssl": "1.1.0",
|
"@vitejs/plugin-basic-ssl": "2.1.0",
|
||||||
"autoprefixer": "10.4.19",
|
"autoprefixer": "10.4.19",
|
||||||
"npm-run-all": "4.1.5",
|
"npm-run-all": "4.1.5",
|
||||||
"postcss": "8.5.6",
|
"postcss": "8.5.6",
|
||||||
"tailwindcss": "4.1.17",
|
"tailwindcss": "4.1.17",
|
||||||
"typescript": "5.9.3",
|
"typescript": "5.9.3",
|
||||||
"vite": "4.5.14",
|
"vite": "6.4.1",
|
||||||
"vite-plugin-environment": "1.1.3"
|
"vite-plugin-environment": "1.1.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { EmbedElement } from "../EmbedElement";
|
import { EmbedElement } from "../EmbedElement";
|
||||||
import { getErrorString } from "../lib/utils";
|
import { getErrorString } from "../lib/utils";
|
||||||
import loaderCss from "../loader.css";
|
import loaderCss from "../loader.css?inline";
|
||||||
import modalBoxHtml, { getSkeletonData } from "./ModalBoxHtml";
|
import modalBoxHtml, { getSkeletonData } from "./ModalBoxHtml";
|
||||||
|
|
||||||
export class ModalBox extends EmbedElement {
|
export class ModalBox extends EmbedElement {
|
||||||
|
|||||||
@@ -735,6 +735,9 @@ describe("Cal", () => {
|
|||||||
};
|
};
|
||||||
// Reset document.querySelector mock before each test
|
// Reset document.querySelector mock before each test
|
||||||
vi.restoreAllMocks();
|
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", () => {
|
it("should return fullReload when cal link is different", () => {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
EMBED_MODAL_PRERENDER_PREVENT_THRESHOLD_MS,
|
EMBED_MODAL_PRERENDER_PREVENT_THRESHOLD_MS,
|
||||||
} from "./constants";
|
} from "./constants";
|
||||||
import type { InterfaceWithParent, interfaceWithParent } from "./embed-iframe";
|
import type { InterfaceWithParent, interfaceWithParent } from "./embed-iframe";
|
||||||
import css from "./embed.css";
|
import css from "./embed.css?inline";
|
||||||
import { getScrollableAncestor } from "./lib/domUtils";
|
import { getScrollableAncestor } from "./lib/domUtils";
|
||||||
import { getScrollByDistanceHandler } from "./lib/eventHandlers/scrollByDistanceEventHandler";
|
import { getScrollByDistanceHandler } from "./lib/eventHandlers/scrollByDistanceEventHandler";
|
||||||
import {
|
import {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
"embed-tests": "yarn playwright test --config=./playwright/config/playwright.config.ts",
|
"embed-tests": "yarn playwright test --config=./playwright/config/playwright.config.ts",
|
||||||
"embed-tests-quick": "QUICK=true yarn embed-tests",
|
"embed-tests-quick": "QUICK=true yarn embed-tests",
|
||||||
"embed-tests-update-snapshots:ci": "yarn embed-tests-quick --update-snapshots",
|
"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",
|
"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",
|
"prepack": "yarn ../../../ lint --filter='@calcom/embed-react' && yarn withEmbedPublishEnv build && yarn packaged:tests",
|
||||||
"embed-web-start": "yarn workspace @calcom/web start",
|
"embed-web-start": "yarn workspace @calcom/web start",
|
||||||
@@ -47,10 +47,10 @@
|
|||||||
"@playwright/test": "1.57.0",
|
"@playwright/test": "1.57.0",
|
||||||
"@types/react": "18.0.26",
|
"@types/react": "18.0.26",
|
||||||
"@types/react-dom": "18.2.6",
|
"@types/react-dom": "18.2.6",
|
||||||
"@vitejs/plugin-react": "2.2.0",
|
"@vitejs/plugin-react": "5.1.2",
|
||||||
"npm-run-all": "4.1.5",
|
"npm-run-all": "4.1.5",
|
||||||
"typescript": "5.9.3",
|
"typescript": "5.9.3",
|
||||||
"vite": "4.5.14"
|
"vite": "6.4.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@calcom/embed-core": "workspace:*",
|
"@calcom/embed-core": "workspace:*",
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"typescript": "5.9.3",
|
"typescript": "5.9.3",
|
||||||
"vite": "4.5.14"
|
"vite": "6.4.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@calcom/embed-core": "workspace:*"
|
"@calcom/embed-core": "workspace:*"
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ const mockFindByEmailAndIncludeProfilesAndPassword = vi.fn();
|
|||||||
|
|
||||||
vi.mock("@calcom/features/users/repositories/UserRepository", () => {
|
vi.mock("@calcom/features/users/repositories/UserRepository", () => {
|
||||||
return {
|
return {
|
||||||
UserRepository: vi.fn().mockImplementation(() => ({
|
UserRepository: vi.fn().mockImplementation(function() { return {
|
||||||
findByEmailAndIncludeProfilesAndPassword: mockFindByEmailAndIncludeProfilesAndPassword,
|
findByEmailAndIncludeProfilesAndPassword: mockFindByEmailAndIncludeProfilesAndPassword,
|
||||||
})),
|
}; }),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -130,9 +130,9 @@ describe("BookingAuditAccessService - Permission Checks", () => {
|
|||||||
checkPermission: vi.fn(),
|
checkPermission: vi.fn(),
|
||||||
};
|
};
|
||||||
|
|
||||||
vi.mocked(BookingRepository).mockImplementation(() => mockBookingRepository as unknown as BookingRepository);
|
vi.mocked(BookingRepository).mockImplementation(function() { return mockBookingRepository as unknown as BookingRepository; });
|
||||||
vi.mocked(MembershipRepository).mockImplementation(() => mockMembershipRepository as unknown as MembershipRepository);
|
vi.mocked(MembershipRepository).mockImplementation(function() { return mockMembershipRepository as unknown as MembershipRepository; });
|
||||||
vi.mocked(PermissionCheckService).mockImplementation(() => mockPermissionCheckService as unknown as PermissionCheckService);
|
vi.mocked(PermissionCheckService).mockImplementation(function() { return mockPermissionCheckService as unknown as PermissionCheckService; });
|
||||||
|
|
||||||
service = new BookingAuditAccessService({
|
service = new BookingAuditAccessService({
|
||||||
bookingRepository: mockBookingRepository as unknown as BookingRepository,
|
bookingRepository: mockBookingRepository as unknown as BookingRepository,
|
||||||
|
|||||||
+4
-4
@@ -144,10 +144,10 @@ describe("BookingAuditViewerService - Integration Tests", () => {
|
|||||||
error: vi.fn(),
|
error: vi.fn(),
|
||||||
};
|
};
|
||||||
|
|
||||||
vi.mocked(BookingRepository).mockImplementation(() => mockBookingRepository as unknown as BookingRepository);
|
vi.mocked(BookingRepository).mockImplementation(function() { return mockBookingRepository as unknown as BookingRepository; });
|
||||||
vi.mocked(UserRepository).mockImplementation(() => mockUserRepository as unknown as UserRepository);
|
vi.mocked(UserRepository).mockImplementation(function() { return mockUserRepository as unknown as UserRepository; });
|
||||||
vi.mocked(MembershipRepository).mockImplementation(() => mockMembershipRepository as unknown as MembershipRepository);
|
vi.mocked(MembershipRepository).mockImplementation(function() { return mockMembershipRepository as unknown as MembershipRepository; });
|
||||||
vi.mocked(PermissionCheckService).mockImplementation(() => mockPermissionCheckService as unknown as PermissionCheckService);
|
vi.mocked(PermissionCheckService).mockImplementation(function() { return mockPermissionCheckService as unknown as PermissionCheckService; });
|
||||||
|
|
||||||
service = new BookingAuditViewerService({
|
service = new BookingAuditViewerService({
|
||||||
bookingAuditRepository: mockBookingAuditRepository as unknown as IBookingAuditRepository,
|
bookingAuditRepository: mockBookingAuditRepository as unknown as IBookingAuditRepository,
|
||||||
|
|||||||
+32
-38
@@ -11,9 +11,9 @@ import { UserRepository } from "@calcom/features/users/repositories/UserReposito
|
|||||||
|
|
||||||
vi.mock("@calcom/features/users/repositories/UserRepository", () => {
|
vi.mock("@calcom/features/users/repositories/UserRepository", () => {
|
||||||
return {
|
return {
|
||||||
UserRepository: vi.fn().mockImplementation(() => ({
|
UserRepository: vi.fn().mockImplementation(function() { return {
|
||||||
enrichUserWithItsProfile: vi.fn(),
|
enrichUserWithItsProfile: vi.fn(),
|
||||||
})),
|
}; }),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -25,12 +25,11 @@ describe("getAllCredentialsIncludeServiceAccountKey", () => {
|
|||||||
|
|
||||||
const mockUserRepository = vi.mocked(UserRepository);
|
const mockUserRepository = vi.mocked(UserRepository);
|
||||||
if (mockUserRepository && typeof mockUserRepository.mockImplementation === "function") {
|
if (mockUserRepository && typeof mockUserRepository.mockImplementation === "function") {
|
||||||
mockUserRepository.mockImplementation(
|
mockUserRepository.mockImplementation(function () {
|
||||||
() =>
|
return {
|
||||||
({
|
enrichUserWithItsProfile: mockEnrichUserWithItsProfile,
|
||||||
enrichUserWithItsProfile: mockEnrichUserWithItsProfile,
|
} as InstanceType<typeof UserRepository>;
|
||||||
} as any)
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const getAllCredentialsIncludeServiceAccountKey = (await import("./getAllCredentials"))
|
const getAllCredentialsIncludeServiceAccountKey = (await import("./getAllCredentials"))
|
||||||
@@ -80,12 +79,11 @@ describe("getAllCredentialsIncludeServiceAccountKey", () => {
|
|||||||
|
|
||||||
const mockUserRepository = vi.mocked(UserRepository);
|
const mockUserRepository = vi.mocked(UserRepository);
|
||||||
if (mockUserRepository && typeof mockUserRepository.mockImplementation === "function") {
|
if (mockUserRepository && typeof mockUserRepository.mockImplementation === "function") {
|
||||||
mockUserRepository.mockImplementation(
|
mockUserRepository.mockImplementation(function () {
|
||||||
() =>
|
return {
|
||||||
({
|
enrichUserWithItsProfile: mockEnrichUserWithItsProfile,
|
||||||
enrichUserWithItsProfile: mockEnrichUserWithItsProfile,
|
} as InstanceType<typeof UserRepository>;
|
||||||
} as any)
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const getAllCredentialsIncludeServiceAccountKey = (await import("./getAllCredentials"))
|
const getAllCredentialsIncludeServiceAccountKey = (await import("./getAllCredentials"))
|
||||||
@@ -164,12 +162,11 @@ describe("getAllCredentialsIncludeServiceAccountKey", () => {
|
|||||||
|
|
||||||
const mockUserRepository = vi.mocked(UserRepository);
|
const mockUserRepository = vi.mocked(UserRepository);
|
||||||
if (mockUserRepository && typeof mockUserRepository.mockImplementation === "function") {
|
if (mockUserRepository && typeof mockUserRepository.mockImplementation === "function") {
|
||||||
mockUserRepository.mockImplementation(
|
mockUserRepository.mockImplementation(function () {
|
||||||
() =>
|
return {
|
||||||
({
|
enrichUserWithItsProfile: mockEnrichUserWithItsProfile,
|
||||||
enrichUserWithItsProfile: mockEnrichUserWithItsProfile,
|
} as InstanceType<typeof UserRepository>;
|
||||||
} as any)
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const getAllCredentialsIncludeServiceAccountKey = (await import("./getAllCredentials"))
|
const getAllCredentialsIncludeServiceAccountKey = (await import("./getAllCredentials"))
|
||||||
@@ -241,12 +238,11 @@ describe("getAllCredentialsIncludeServiceAccountKey", () => {
|
|||||||
|
|
||||||
const mockUserRepository = vi.mocked(UserRepository);
|
const mockUserRepository = vi.mocked(UserRepository);
|
||||||
if (mockUserRepository && typeof mockUserRepository.mockImplementation === "function") {
|
if (mockUserRepository && typeof mockUserRepository.mockImplementation === "function") {
|
||||||
mockUserRepository.mockImplementation(
|
mockUserRepository.mockImplementation(function () {
|
||||||
() =>
|
return {
|
||||||
({
|
enrichUserWithItsProfile: mockEnrichUserWithItsProfile,
|
||||||
enrichUserWithItsProfile: mockEnrichUserWithItsProfile,
|
} as InstanceType<typeof UserRepository>;
|
||||||
} as any)
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const getAllCredentialsIncludeServiceAccountKey = (await import("./getAllCredentials"))
|
const getAllCredentialsIncludeServiceAccountKey = (await import("./getAllCredentials"))
|
||||||
@@ -346,12 +342,11 @@ describe("getAllCredentialsIncludeServiceAccountKey", () => {
|
|||||||
|
|
||||||
const mockUserRepository = vi.mocked(UserRepository);
|
const mockUserRepository = vi.mocked(UserRepository);
|
||||||
if (mockUserRepository && typeof mockUserRepository.mockImplementation === "function") {
|
if (mockUserRepository && typeof mockUserRepository.mockImplementation === "function") {
|
||||||
mockUserRepository.mockImplementation(
|
mockUserRepository.mockImplementation(function () {
|
||||||
() =>
|
return {
|
||||||
({
|
enrichUserWithItsProfile: mockEnrichUserWithItsProfile,
|
||||||
enrichUserWithItsProfile: mockEnrichUserWithItsProfile,
|
} as InstanceType<typeof UserRepository>;
|
||||||
} as any)
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const crmCredential = {
|
const crmCredential = {
|
||||||
@@ -669,12 +664,11 @@ describe("getAllCredentialsIncludeServiceAccountKey", () => {
|
|||||||
|
|
||||||
const mockUserRepository = vi.mocked(UserRepository);
|
const mockUserRepository = vi.mocked(UserRepository);
|
||||||
if (mockUserRepository && typeof mockUserRepository.mockImplementation === "function") {
|
if (mockUserRepository && typeof mockUserRepository.mockImplementation === "function") {
|
||||||
mockUserRepository.mockImplementation(
|
mockUserRepository.mockImplementation(function () {
|
||||||
() =>
|
return {
|
||||||
({
|
enrichUserWithItsProfile: mockEnrichUserWithItsProfile,
|
||||||
enrichUserWithItsProfile: mockEnrichUserWithItsProfile,
|
} as InstanceType<typeof UserRepository>;
|
||||||
} as any)
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const crmCredential = {
|
const crmCredential = {
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ vi.mock("@calcom/features/users/repositories/UserRepository", async (importOrigi
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
...actual,
|
...actual,
|
||||||
UserRepository: vi.fn().mockImplementation((prisma) => {
|
UserRepository: vi.fn(function (prisma) {
|
||||||
const realInstance = new OriginalUserRepository(prisma);
|
const realInstance = new OriginalUserRepository(prisma);
|
||||||
realInstance.findManyByEmailsWithEmailVerificationSettings =
|
realInstance.findManyByEmailsWithEmailVerificationSettings =
|
||||||
mockFindManyByEmailsWithEmailVerificationSettings;
|
mockFindManyByEmailsWithEmailVerificationSettings;
|
||||||
|
|||||||
+6
-4
@@ -25,10 +25,12 @@ vi.mock("@calcom/features/CalendarEventBuilder", () => {
|
|||||||
fromEvent: vi.fn().mockImplementation((_evt) => ({
|
fromEvent: vi.fn().mockImplementation((_evt) => ({
|
||||||
withDestinationCalendar: withDestinationCalendarSpy,
|
withDestinationCalendar: withDestinationCalendarSpy,
|
||||||
withTeam: withTeamSpy,
|
withTeam: withTeamSpy,
|
||||||
build: vi.fn().mockImplementation(() => ({
|
build: vi.fn().mockImplementation(function() {
|
||||||
destinationCalendar: [],
|
return {
|
||||||
team: {}, // <- you won't use this result anyway
|
destinationCalendar: [],
|
||||||
})),
|
team: {}, // <- you won't use this result anyway
|
||||||
|
};
|
||||||
|
}),
|
||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -33,9 +33,11 @@ describe("handleSeats", () => {
|
|||||||
|
|
||||||
describe("Correct parameters being passed into handleSeats from handleNewBooking", () => {
|
describe("Correct parameters being passed into handleSeats from handleNewBooking", () => {
|
||||||
vi.mock("./handleSeats");
|
vi.mock("./handleSeats");
|
||||||
|
|
||||||
test("On new booking handleSeats is not called", async () => {
|
test("On new booking handleSeats is not called", async () => {
|
||||||
const handleNewBooking = getNewBookingHandler();
|
const handleNewBooking = getNewBookingHandler();
|
||||||
const spy = vi.spyOn(handleSeatsModule, "default");
|
const spy = vi.spyOn(handleSeatsModule, "default");
|
||||||
|
spy.mockClear();
|
||||||
|
|
||||||
const booker = getBooker({
|
const booker = getBooker({
|
||||||
email: "booker@example.com",
|
email: "booker@example.com",
|
||||||
@@ -97,6 +99,7 @@ describe("handleSeats", () => {
|
|||||||
|
|
||||||
test("handleSeats is called when a new attendee is added", async () => {
|
test("handleSeats is called when a new attendee is added", async () => {
|
||||||
const spy = vi.spyOn(handleSeatsModule, "default");
|
const spy = vi.spyOn(handleSeatsModule, "default");
|
||||||
|
spy.mockClear();
|
||||||
const handleNewBooking = getNewBookingHandler();
|
const handleNewBooking = getNewBookingHandler();
|
||||||
|
|
||||||
const booker = getBooker({
|
const booker = getBooker({
|
||||||
@@ -242,6 +245,7 @@ describe("handleSeats", () => {
|
|||||||
|
|
||||||
test("handleSeats is called on rescheduling a seated event", async () => {
|
test("handleSeats is called on rescheduling a seated event", async () => {
|
||||||
const spy = vi.spyOn(handleSeatsModule, "default");
|
const spy = vi.spyOn(handleSeatsModule, "default");
|
||||||
|
spy.mockClear();
|
||||||
const handleNewBooking = getNewBookingHandler();
|
const handleNewBooking = getNewBookingHandler();
|
||||||
|
|
||||||
const booker = getBooker({
|
const booker = getBooker({
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ import { handleNoShowFee } from "./handleNoShowFee";
|
|||||||
vi.mock("@calcom/app-store/payment.services.generated", () => ({
|
vi.mock("@calcom/app-store/payment.services.generated", () => ({
|
||||||
PaymentServiceMap: {
|
PaymentServiceMap: {
|
||||||
stripepayment: Promise.resolve({
|
stripepayment: Promise.resolve({
|
||||||
PaymentService: vi.fn().mockImplementation(() => ({
|
PaymentService: vi.fn().mockImplementation(function() { return {
|
||||||
chargeCard: vi.fn(),
|
chargeCard: vi.fn(),
|
||||||
})),
|
}; }),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
@@ -43,9 +43,9 @@ vi.mock("@calcom/features/membership/repositories/MembershipRepository", () => (
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("@calcom/features/ee/teams/repositories/TeamRepository", () => ({
|
vi.mock("@calcom/features/ee/teams/repositories/TeamRepository", () => ({
|
||||||
TeamRepository: vi.fn().mockImplementation(() => ({
|
TeamRepository: vi.fn().mockImplementation(function() { return {
|
||||||
findParentOrganizationByTeamId: vi.fn(),
|
findParentOrganizationByTeamId: vi.fn(),
|
||||||
})),
|
}; }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("@calcom/prisma", () => ({
|
vi.mock("@calcom/prisma", () => ({
|
||||||
@@ -62,7 +62,7 @@ describe("handleNoShowFee", () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const paymentServiceModule = await PaymentServiceMap.stripepayment;
|
const paymentServiceModule = await PaymentServiceMap.stripepayment;
|
||||||
vi.mocked(paymentServiceModule.PaymentService).mockImplementation(() => mockPaymentService);
|
vi.mocked(paymentServiceModule.PaymentService).mockImplementation(function() { return mockPaymentService; });
|
||||||
});
|
});
|
||||||
|
|
||||||
const mockBooking = {
|
const mockBooking = {
|
||||||
@@ -211,7 +211,7 @@ describe("handleNoShowFee", () => {
|
|||||||
const mockTeamRepository = {
|
const mockTeamRepository = {
|
||||||
findParentOrganizationByTeamId: vi.fn().mockResolvedValue({ id: 2 }),
|
findParentOrganizationByTeamId: vi.fn().mockResolvedValue({ id: 2 }),
|
||||||
};
|
};
|
||||||
vi.mocked(TeamRepository).mockImplementation(() => mockTeamRepository);
|
vi.mocked(TeamRepository).mockImplementation(function() { return mockTeamRepository; });
|
||||||
|
|
||||||
const result = await handleNoShowFee({
|
const result = await handleNoShowFee({
|
||||||
booking: teamBooking,
|
booking: teamBooking,
|
||||||
|
|||||||
@@ -40,8 +40,8 @@ describe("BookingAccessService", () => {
|
|||||||
checkPermission: vi.fn(),
|
checkPermission: vi.fn(),
|
||||||
};
|
};
|
||||||
|
|
||||||
vi.mocked(BookingRepository).mockImplementation(() => mockBookingRepo as any);
|
vi.mocked(BookingRepository).mockImplementation(function() { return mockBookingRepo as any; });
|
||||||
vi.mocked(UserRepository).mockImplementation(() => mockUserRepo as any);
|
vi.mocked(UserRepository).mockImplementation(function() { return mockUserRepo as any; });
|
||||||
|
|
||||||
service = new BookingAccessService(mockPrismaClient);
|
service = new BookingAccessService(mockPrismaClient);
|
||||||
|
|
||||||
|
|||||||
@@ -16,13 +16,15 @@ import { AIPhoneServiceProviderType } from "./interfaces/AIPhoneService.interfac
|
|||||||
vi.stubEnv("RETELL_AI_KEY", "test-api-key");
|
vi.stubEnv("RETELL_AI_KEY", "test-api-key");
|
||||||
|
|
||||||
vi.mock("./providers/retellAI", () => ({
|
vi.mock("./providers/retellAI", () => ({
|
||||||
RetellAIPhoneServiceProviderFactory: vi.fn().mockImplementation(() => ({
|
RetellAIPhoneServiceProviderFactory: vi.fn().mockImplementation(function() {
|
||||||
create: vi.fn().mockReturnValue({
|
return {
|
||||||
setupConfiguration: vi.fn(),
|
create: vi.fn().mockReturnValue({
|
||||||
createPhoneCall: vi.fn(),
|
setupConfiguration: vi.fn(),
|
||||||
createPhoneNumber: vi.fn(),
|
createPhoneCall: vi.fn(),
|
||||||
}),
|
createPhoneNumber: vi.fn(),
|
||||||
})),
|
}),
|
||||||
|
};
|
||||||
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe("AIPhoneServiceRegistry", () => {
|
describe("AIPhoneServiceRegistry", () => {
|
||||||
|
|||||||
+45
-41
@@ -19,50 +19,54 @@ vi.mock("@calcom/lib/logger", () => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("./RetellSDKClient", () => ({
|
vi.mock("./RetellSDKClient", () => ({
|
||||||
RetellSDKClient: vi.fn().mockImplementation((logger) => ({
|
RetellSDKClient: vi.fn().mockImplementation(function (logger) {
|
||||||
logger,
|
return {
|
||||||
createLLM: vi.fn(),
|
logger,
|
||||||
getLLM: vi.fn(),
|
createLLM: vi.fn(),
|
||||||
updateLLM: vi.fn(),
|
getLLM: vi.fn(),
|
||||||
deleteLLM: vi.fn(),
|
updateLLM: vi.fn(),
|
||||||
createOutboundAgent: vi.fn(),
|
deleteLLM: vi.fn(),
|
||||||
getAgent: vi.fn(),
|
createOutboundAgent: vi.fn(),
|
||||||
updateAgent: vi.fn(),
|
getAgent: vi.fn(),
|
||||||
deleteAgent: vi.fn(),
|
updateAgent: vi.fn(),
|
||||||
createPhoneNumber: vi.fn(),
|
deleteAgent: vi.fn(),
|
||||||
importPhoneNumber: vi.fn(),
|
createPhoneNumber: vi.fn(),
|
||||||
deletePhoneNumber: vi.fn(),
|
importPhoneNumber: vi.fn(),
|
||||||
getPhoneNumber: vi.fn(),
|
deletePhoneNumber: vi.fn(),
|
||||||
updatePhoneNumber: vi.fn(),
|
getPhoneNumber: vi.fn(),
|
||||||
createPhoneCall: vi.fn(),
|
updatePhoneNumber: vi.fn(),
|
||||||
})),
|
createPhoneCall: vi.fn(),
|
||||||
|
};
|
||||||
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("./RetellAIPhoneServiceProvider", () => ({
|
vi.mock("./RetellAIPhoneServiceProvider", () => ({
|
||||||
RetellAIPhoneServiceProvider: vi
|
RetellAIPhoneServiceProvider: vi
|
||||||
.fn()
|
.fn()
|
||||||
.mockImplementation((repository, agentRepository, phoneNumberRepository, transactionManager) => ({
|
.mockImplementation(function (repository, agentRepository, phoneNumberRepository, transactionManager) {
|
||||||
repository,
|
return {
|
||||||
agentRepository,
|
repository,
|
||||||
phoneNumberRepository,
|
agentRepository,
|
||||||
transactionManager,
|
phoneNumberRepository,
|
||||||
setupConfiguration: vi.fn(),
|
transactionManager,
|
||||||
deleteConfiguration: vi.fn(),
|
setupConfiguration: vi.fn(),
|
||||||
updateLLMConfiguration: vi.fn(),
|
deleteConfiguration: vi.fn(),
|
||||||
getLLMDetails: vi.fn(),
|
updateLLMConfiguration: vi.fn(),
|
||||||
getAgent: vi.fn(),
|
getLLMDetails: vi.fn(),
|
||||||
updateAgent: vi.fn(),
|
getAgent: vi.fn(),
|
||||||
createPhoneCall: vi.fn(),
|
updateAgent: vi.fn(),
|
||||||
createPhoneNumber: vi.fn(),
|
createPhoneCall: vi.fn(),
|
||||||
deletePhoneNumber: vi.fn(),
|
createPhoneNumber: vi.fn(),
|
||||||
getPhoneNumber: vi.fn(),
|
deletePhoneNumber: vi.fn(),
|
||||||
updatePhoneNumber: vi.fn(),
|
getPhoneNumber: vi.fn(),
|
||||||
importPhoneNumber: vi.fn(),
|
updatePhoneNumber: vi.fn(),
|
||||||
})),
|
importPhoneNumber: vi.fn(),
|
||||||
|
};
|
||||||
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("../adapters/PrismaAgentRepositoryAdapter", () => ({
|
vi.mock("../adapters/PrismaAgentRepositoryAdapter", () => ({
|
||||||
PrismaAgentRepositoryAdapter: vi.fn().mockImplementation(() => ({
|
PrismaAgentRepositoryAdapter: vi.fn().mockImplementation(function() { return {
|
||||||
canManageTeamResources: vi.fn(),
|
canManageTeamResources: vi.fn(),
|
||||||
findByIdWithUserAccess: vi.fn(),
|
findByIdWithUserAccess: vi.fn(),
|
||||||
findByProviderAgentIdWithUserAccess: vi.fn(),
|
findByProviderAgentIdWithUserAccess: vi.fn(),
|
||||||
@@ -73,11 +77,11 @@ vi.mock("../adapters/PrismaAgentRepositoryAdapter", () => ({
|
|||||||
findByIdWithCallAccess: vi.fn(),
|
findByIdWithCallAccess: vi.fn(),
|
||||||
delete: vi.fn(),
|
delete: vi.fn(),
|
||||||
linkOutboundAgentToWorkflow: vi.fn(),
|
linkOutboundAgentToWorkflow: vi.fn(),
|
||||||
})),
|
}; }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("../adapters/PrismaPhoneNumberRepositoryAdapter", () => ({
|
vi.mock("../adapters/PrismaPhoneNumberRepositoryAdapter", () => ({
|
||||||
PrismaPhoneNumberRepositoryAdapter: vi.fn().mockImplementation(() => ({
|
PrismaPhoneNumberRepositoryAdapter: vi.fn().mockImplementation(function() { return {
|
||||||
findByPhoneNumberAndUserId: vi.fn(),
|
findByPhoneNumberAndUserId: vi.fn(),
|
||||||
findByPhoneNumberAndTeamId: vi.fn(),
|
findByPhoneNumberAndTeamId: vi.fn(),
|
||||||
findByIdAndUserId: vi.fn(),
|
findByIdAndUserId: vi.fn(),
|
||||||
@@ -86,13 +90,13 @@ vi.mock("../adapters/PrismaPhoneNumberRepositoryAdapter", () => ({
|
|||||||
deletePhoneNumber: vi.fn(),
|
deletePhoneNumber: vi.fn(),
|
||||||
updateSubscriptionStatus: vi.fn(),
|
updateSubscriptionStatus: vi.fn(),
|
||||||
updateAgents: vi.fn(),
|
updateAgents: vi.fn(),
|
||||||
})),
|
}; }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("../adapters/PrismaTransactionAdapter", () => ({
|
vi.mock("../adapters/PrismaTransactionAdapter", () => ({
|
||||||
PrismaTransactionAdapter: vi.fn().mockImplementation(() => ({
|
PrismaTransactionAdapter: vi.fn().mockImplementation(function() { return {
|
||||||
executeInTransaction: vi.fn(),
|
executeInTransaction: vi.fn(),
|
||||||
})),
|
}; }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe("RetellAIPhoneServiceProviderFactory", () => {
|
describe("RetellAIPhoneServiceProviderFactory", () => {
|
||||||
|
|||||||
@@ -34,10 +34,12 @@ vi.mock("@calcom/features/ee/payments/server/stripe", () => ({
|
|||||||
|
|
||||||
const mockGetAllCredits = vi.fn();
|
const mockGetAllCredits = vi.fn();
|
||||||
const mockHasAvailableCredits = vi.fn();
|
const mockHasAvailableCredits = vi.fn();
|
||||||
const mockCreditService = vi.fn().mockImplementation(() => ({
|
const mockCreditService = vi.fn().mockImplementation(function() {
|
||||||
getAllCredits: mockGetAllCredits,
|
return {
|
||||||
hasAvailableCredits: mockHasAvailableCredits,
|
getAllCredits: mockGetAllCredits,
|
||||||
}));
|
hasAvailableCredits: mockHasAvailableCredits,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
vi.mock("@calcom/features/ee/billing/credit-service", () => ({
|
vi.mock("@calcom/features/ee/billing/credit-service", () => ({
|
||||||
CreditService: mockCreditService,
|
CreditService: mockCreditService,
|
||||||
@@ -849,9 +851,11 @@ describe("RetellAIService", () => {
|
|||||||
const { CreditService } = await import("@calcom/features/ee/billing/credit-service");
|
const { CreditService } = await import("@calcom/features/ee/billing/credit-service");
|
||||||
|
|
||||||
const mockHasAvailableCredits = vi.fn().mockResolvedValue(true);
|
const mockHasAvailableCredits = vi.fn().mockResolvedValue(true);
|
||||||
(CreditService as any).mockImplementation(() => ({
|
(CreditService as any).mockImplementation(function() {
|
||||||
hasAvailableCredits: mockHasAvailableCredits,
|
return {
|
||||||
}));
|
hasAvailableCredits: mockHasAvailableCredits,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
// Mock rate limiting like the working example
|
// Mock rate limiting like the working example
|
||||||
vi.mocked(checkRateLimitAndThrowError).mockResolvedValueOnce(undefined as any);
|
vi.mocked(checkRateLimitAndThrowError).mockResolvedValueOnce(undefined as any);
|
||||||
@@ -931,9 +935,11 @@ describe("RetellAIService", () => {
|
|||||||
|
|
||||||
// Mock credit service to return false (no credits)
|
// Mock credit service to return false (no credits)
|
||||||
const mockHasAvailableCredits = vi.fn().mockResolvedValue(false);
|
const mockHasAvailableCredits = vi.fn().mockResolvedValue(false);
|
||||||
(CreditService as any).mockImplementation(() => ({
|
(CreditService as any).mockImplementation(function() {
|
||||||
hasAvailableCredits: mockHasAvailableCredits,
|
return {
|
||||||
}));
|
hasAvailableCredits: mockHasAvailableCredits,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
service.createTestCall({
|
service.createTestCall({
|
||||||
@@ -952,9 +958,11 @@ describe("RetellAIService", () => {
|
|||||||
|
|
||||||
// Mock sufficient credits to get past credit check
|
// Mock sufficient credits to get past credit check
|
||||||
const mockHasAvailableCredits = vi.fn().mockResolvedValue(true);
|
const mockHasAvailableCredits = vi.fn().mockResolvedValue(true);
|
||||||
(CreditService as any).mockImplementation(() => ({
|
(CreditService as any).mockImplementation(function() {
|
||||||
hasAvailableCredits: mockHasAvailableCredits,
|
return {
|
||||||
}));
|
hasAvailableCredits: mockHasAvailableCredits,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
(checkRateLimitAndThrowError as any).mockResolvedValue(undefined);
|
(checkRateLimitAndThrowError as any).mockResolvedValue(undefined);
|
||||||
|
|
||||||
@@ -974,9 +982,11 @@ describe("RetellAIService", () => {
|
|||||||
|
|
||||||
// Mock sufficient credits
|
// Mock sufficient credits
|
||||||
const mockHasAvailableCredits = vi.fn().mockResolvedValue(true);
|
const mockHasAvailableCredits = vi.fn().mockResolvedValue(true);
|
||||||
(CreditService as any).mockImplementation(() => ({
|
(CreditService as any).mockImplementation(function() {
|
||||||
hasAvailableCredits: mockHasAvailableCredits,
|
return {
|
||||||
}));
|
hasAvailableCredits: mockHasAvailableCredits,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
(checkRateLimitAndThrowError as any).mockResolvedValue(undefined);
|
(checkRateLimitAndThrowError as any).mockResolvedValue(undefined);
|
||||||
mockAgentRepository.findByIdWithCallAccess.mockResolvedValue(null);
|
mockAgentRepository.findByIdWithCallAccess.mockResolvedValue(null);
|
||||||
@@ -998,9 +1008,11 @@ describe("RetellAIService", () => {
|
|||||||
|
|
||||||
// Mock sufficient credits
|
// Mock sufficient credits
|
||||||
const mockHasAvailableCredits = vi.fn().mockResolvedValue(true);
|
const mockHasAvailableCredits = vi.fn().mockResolvedValue(true);
|
||||||
(CreditService as any).mockImplementation(() => ({
|
(CreditService as any).mockImplementation(function() {
|
||||||
hasAvailableCredits: mockHasAvailableCredits,
|
return {
|
||||||
}));
|
hasAvailableCredits: mockHasAvailableCredits,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
(checkRateLimitAndThrowError as any).mockResolvedValue(undefined);
|
(checkRateLimitAndThrowError as any).mockResolvedValue(undefined);
|
||||||
mockAgentRepository.findByIdWithCallAccess.mockResolvedValue({
|
mockAgentRepository.findByIdWithCallAccess.mockResolvedValue({
|
||||||
|
|||||||
@@ -16,30 +16,32 @@ import type {
|
|||||||
let RetellSDKClient: typeof import("./RetellSDKClient").RetellSDKClient;
|
let RetellSDKClient: typeof import("./RetellSDKClient").RetellSDKClient;
|
||||||
|
|
||||||
vi.mock("retell-sdk", () => ({
|
vi.mock("retell-sdk", () => ({
|
||||||
Retell: vi.fn().mockImplementation(() => ({
|
Retell: vi.fn().mockImplementation(function() {
|
||||||
llm: {
|
return {
|
||||||
create: vi.fn(),
|
llm: {
|
||||||
retrieve: vi.fn(),
|
create: vi.fn(),
|
||||||
update: vi.fn(),
|
retrieve: vi.fn(),
|
||||||
delete: vi.fn(),
|
update: vi.fn(),
|
||||||
},
|
delete: vi.fn(),
|
||||||
agent: {
|
},
|
||||||
create: vi.fn(),
|
agent: {
|
||||||
retrieve: vi.fn(),
|
create: vi.fn(),
|
||||||
update: vi.fn(),
|
retrieve: vi.fn(),
|
||||||
delete: vi.fn(),
|
update: vi.fn(),
|
||||||
},
|
delete: vi.fn(),
|
||||||
phoneNumber: {
|
},
|
||||||
create: vi.fn(),
|
phoneNumber: {
|
||||||
import: vi.fn(),
|
create: vi.fn(),
|
||||||
delete: vi.fn(),
|
import: vi.fn(),
|
||||||
retrieve: vi.fn(),
|
delete: vi.fn(),
|
||||||
update: vi.fn(),
|
retrieve: vi.fn(),
|
||||||
},
|
update: vi.fn(),
|
||||||
call: {
|
},
|
||||||
createPhoneCall: vi.fn(),
|
call: {
|
||||||
},
|
createPhoneCall: vi.fn(),
|
||||||
})),
|
},
|
||||||
|
};
|
||||||
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("@calcom/lib/logger", () => ({
|
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", () => {
|
describe("constructor", () => {
|
||||||
|
|||||||
+20
-12
@@ -26,9 +26,11 @@ describe("CallService", () => {
|
|||||||
const { CreditService } = await import("@calcom/features/ee/billing/credit-service");
|
const { CreditService } = await import("@calcom/features/ee/billing/credit-service");
|
||||||
const { checkRateLimitAndThrowError } = await import("@calcom/lib/checkRateLimitAndThrowError");
|
const { checkRateLimitAndThrowError } = await import("@calcom/lib/checkRateLimitAndThrowError");
|
||||||
|
|
||||||
vi.mocked(CreditService).mockImplementation(() => ({
|
vi.mocked(CreditService).mockImplementation(function () {
|
||||||
hasAvailableCredits: vi.fn().mockResolvedValue(true),
|
return {
|
||||||
}));
|
hasAvailableCredits: vi.fn().mockResolvedValue(true),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
vi.mocked(checkRateLimitAndThrowError).mockResolvedValue(undefined);
|
vi.mocked(checkRateLimitAndThrowError).mockResolvedValue(undefined);
|
||||||
|
|
||||||
@@ -233,9 +235,11 @@ describe("CallService", () => {
|
|||||||
mocks.mockRetellRepository.createPhoneCall.mockResolvedValue(createMockCall());
|
mocks.mockRetellRepository.createPhoneCall.mockResolvedValue(createMockCall());
|
||||||
|
|
||||||
const { CreditService } = await import("@calcom/features/ee/billing/credit-service");
|
const { CreditService } = await import("@calcom/features/ee/billing/credit-service");
|
||||||
vi.mocked(CreditService).mockImplementation(() => ({
|
vi.mocked(CreditService).mockImplementation(function () {
|
||||||
getAllCredits: vi.fn().mockRejectedValue(new TestError("Credit service unavailable")),
|
return {
|
||||||
}));
|
getAllCredits: vi.fn().mockRejectedValue(new TestError("Credit service unavailable")),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
await expect(service.createTestCall(validTestCallData)).rejects.toThrow(
|
await expect(service.createTestCall(validTestCallData)).rejects.toThrow(
|
||||||
"Unable to validate credits. Please try again."
|
"Unable to validate credits. Please try again."
|
||||||
@@ -247,9 +251,11 @@ describe("CallService", () => {
|
|||||||
mocks.mockRetellRepository.createPhoneCall.mockResolvedValue(createMockCall());
|
mocks.mockRetellRepository.createPhoneCall.mockResolvedValue(createMockCall());
|
||||||
|
|
||||||
const { CreditService } = await import("@calcom/features/ee/billing/credit-service");
|
const { CreditService } = await import("@calcom/features/ee/billing/credit-service");
|
||||||
vi.mocked(CreditService).mockImplementation(() => ({
|
vi.mocked(CreditService).mockImplementation(function () {
|
||||||
hasAvailableCredits: vi.fn().mockResolvedValue(false),
|
return {
|
||||||
}));
|
hasAvailableCredits: vi.fn().mockResolvedValue(false),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
await expect(service.createTestCall(validTestCallData)).rejects.toThrow(
|
await expect(service.createTestCall(validTestCallData)).rejects.toThrow(
|
||||||
"Insufficient credits to make test call. Please purchase more credits."
|
"Insufficient credits to make test call. Please purchase more credits."
|
||||||
@@ -261,9 +267,11 @@ describe("CallService", () => {
|
|||||||
mocks.mockRetellRepository.createPhoneCall.mockResolvedValue(createMockCall());
|
mocks.mockRetellRepository.createPhoneCall.mockResolvedValue(createMockCall());
|
||||||
|
|
||||||
const { CreditService } = await import("@calcom/features/ee/billing/credit-service");
|
const { CreditService } = await import("@calcom/features/ee/billing/credit-service");
|
||||||
vi.mocked(CreditService).mockImplementation(() => ({
|
vi.mocked(CreditService).mockImplementation(function () {
|
||||||
hasAvailableCredits: vi.fn().mockResolvedValue(false),
|
return {
|
||||||
}));
|
hasAvailableCredits: vi.fn().mockResolvedValue(false),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
await expect(service.createTestCall(validTestCallData)).rejects.toThrow(
|
await expect(service.createTestCall(validTestCallData)).rejects.toThrow(
|
||||||
"Insufficient credits to make test call. Please purchase more credits."
|
"Insufficient credits to make test call. Please purchase more credits."
|
||||||
|
|||||||
+5
-3
@@ -94,9 +94,11 @@ describe("GoogleCalendarSubscriptionAdapter", () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const { CalendarAuth } = await import("../__mocks__/CalendarAuth");
|
const { CalendarAuth } = await import("../__mocks__/CalendarAuth");
|
||||||
vi.mocked(CalendarAuth).mockImplementation(() => ({
|
vi.mocked(CalendarAuth).mockImplementation(function() {
|
||||||
getClient: vi.fn().mockResolvedValue(mockClient),
|
return {
|
||||||
}));
|
getClient: vi.fn().mockResolvedValue(mockClient),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
adapter = new GoogleCalendarSubscriptionAdapter();
|
adapter = new GoogleCalendarSubscriptionAdapter();
|
||||||
vi.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
|
|||||||
@@ -27,9 +27,9 @@ vi.mock("@calcom/features/credentials/repositories/CredentialRepository", () =>
|
|||||||
|
|
||||||
vi.mock("@calcom/features/users/repositories/UserRepository", () => {
|
vi.mock("@calcom/features/users/repositories/UserRepository", () => {
|
||||||
return {
|
return {
|
||||||
UserRepository: vi.fn().mockImplementation(() => ({
|
UserRepository: vi.fn().mockImplementation(function() { return {
|
||||||
getUserOrganizationAndTeams: vi.fn(),
|
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();
|
const service = new CredentialAccessService();
|
||||||
await expect(
|
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();
|
const service = new CredentialAccessService();
|
||||||
await expect(
|
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();
|
const service = new CredentialAccessService();
|
||||||
await expect(
|
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 service = new CredentialAccessService();
|
||||||
const error = await service
|
const error = await service
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ describe("autoLock", () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// Reset all mocks before each test
|
// Reset all mocks before each test
|
||||||
vi.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
vi.mocked(RedisService).mockImplementation(() => mockRedis as any);
|
vi.mocked(RedisService).mockImplementation(function() { return mockRedis as any; });
|
||||||
|
|
||||||
// Mock environment variables
|
// Mock environment variables
|
||||||
process.env.UPSTASH_REDIS_REST_TOKEN = "test-token";
|
process.env.UPSTASH_REDIS_REST_TOKEN = "test-token";
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ describe("CreditService", () => {
|
|||||||
let creditService: CreditService;
|
let creditService: CreditService;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
vi.restoreAllMocks();
|
vi.resetAllMocks();
|
||||||
|
|
||||||
mockStripe.prices.retrieve.mockResolvedValue({ id: "price_123", unit_amount: 1000 });
|
mockStripe.prices.retrieve.mockResolvedValue({ id: "price_123", unit_amount: 1000 });
|
||||||
mockStripe.customers.create.mockResolvedValue({ id: "cus_123" });
|
mockStripe.customers.create.mockResolvedValue({ id: "cus_123" });
|
||||||
@@ -469,7 +469,7 @@ describe("CreditService", () => {
|
|||||||
members: [{ accepted: true }],
|
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 = {
|
const mockTeamBillingService = {
|
||||||
getSubscriptionStatus: vi.fn().mockResolvedValue(SubscriptionStatus.TRIALING),
|
getSubscriptionStatus: vi.fn().mockResolvedValue(SubscriptionStatus.TRIALING),
|
||||||
@@ -493,7 +493,7 @@ describe("CreditService", () => {
|
|||||||
members: [{ accepted: true }, { accepted: true }, { accepted: true }],
|
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 = {
|
const mockTeamBillingService = {
|
||||||
getSubscriptionStatus: vi.fn().mockResolvedValue(SubscriptionStatus.ACTIVE),
|
getSubscriptionStatus: vi.fn().mockResolvedValue(SubscriptionStatus.ACTIVE),
|
||||||
@@ -524,7 +524,7 @@ describe("CreditService", () => {
|
|||||||
members: [{ accepted: true }, { accepted: true }],
|
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 = {
|
const mockTeamBillingService = {
|
||||||
getSubscriptionStatus: vi.fn().mockResolvedValue(SubscriptionStatus.ACTIVE),
|
getSubscriptionStatus: vi.fn().mockResolvedValue(SubscriptionStatus.ACTIVE),
|
||||||
@@ -549,7 +549,7 @@ describe("CreditService", () => {
|
|||||||
members: [{ accepted: true }, { accepted: true }, { accepted: true }],
|
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 = {
|
const mockTeamBillingService = {
|
||||||
getSubscriptionStatus: vi.fn().mockResolvedValue(SubscriptionStatus.ACTIVE),
|
getSubscriptionStatus: vi.fn().mockResolvedValue(SubscriptionStatus.ACTIVE),
|
||||||
@@ -841,9 +841,14 @@ describe("CreditService", () => {
|
|||||||
{ teamId: 2 },
|
{ teamId: 2 },
|
||||||
]);
|
]);
|
||||||
|
|
||||||
vi.spyOn(TeamRepository.prototype, "findTeamsForCreditCheck").mockResolvedValue([
|
const mockTeamRepoInstance = {
|
||||||
{ id: 2, isOrganization: false, parentId: null, parent: null },
|
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({
|
vi.mocked(CreditsRepository.findCreditBalance).mockResolvedValue({
|
||||||
id: "2",
|
id: "2",
|
||||||
@@ -876,10 +881,15 @@ describe("CreditService", () => {
|
|||||||
{ teamId: 2 },
|
{ teamId: 2 },
|
||||||
]);
|
]);
|
||||||
|
|
||||||
vi.spyOn(TeamRepository.prototype, "findTeamsForCreditCheck").mockResolvedValue([
|
const mockTeamRepoInstance = {
|
||||||
{ id: 1, isOrganization: true, parentId: null, parent: null },
|
findTeamsForCreditCheck: vi.fn().mockResolvedValue([
|
||||||
{ id: 2, isOrganization: false, parentId: null, parent: null },
|
{ 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({
|
vi.mocked(CreditsRepository.findCreditBalance).mockResolvedValue({
|
||||||
id: "1",
|
id: "1",
|
||||||
@@ -910,10 +920,15 @@ describe("CreditService", () => {
|
|||||||
{ teamId: 2 },
|
{ teamId: 2 },
|
||||||
]);
|
]);
|
||||||
|
|
||||||
vi.spyOn(TeamRepository.prototype, "findTeamsForCreditCheck").mockResolvedValue([
|
const mockTeamRepoInstance = {
|
||||||
{ id: 1, isOrganization: true, parentId: null, parent: null },
|
findTeamsForCreditCheck: vi.fn().mockResolvedValue([
|
||||||
{ id: 2, isOrganization: false, parentId: null, parent: null },
|
{ 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({
|
vi.mocked(CreditsRepository.findCreditBalance).mockResolvedValue({
|
||||||
id: "1",
|
id: "1",
|
||||||
@@ -944,9 +959,14 @@ describe("CreditService", () => {
|
|||||||
{ teamId: 2 },
|
{ teamId: 2 },
|
||||||
]);
|
]);
|
||||||
|
|
||||||
vi.spyOn(TeamRepository.prototype, "findTeamsForCreditCheck").mockResolvedValue([
|
const mockTeamRepoInstance = {
|
||||||
{ id: 2, isOrganization: false, parentId: null, parent: null },
|
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({
|
vi.mocked(CreditsRepository.findCreditBalance).mockResolvedValue({
|
||||||
id: "2",
|
id: "2",
|
||||||
|
|||||||
@@ -48,9 +48,9 @@ vi.mock("./removeUserFromOrg", () => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("@calcom/features/users/repositories/UserRepository", () => ({
|
vi.mock("@calcom/features/users/repositories/UserRepository", () => ({
|
||||||
UserRepository: vi.fn().mockImplementation(() => ({
|
UserRepository: vi.fn().mockImplementation(function() { return {
|
||||||
isAMemberOfOrganization: vi.fn().mockResolvedValue(false),
|
isAMemberOfOrganization: vi.fn().mockResolvedValue(false),
|
||||||
})),
|
}; }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
async function createMockOrganization({ id, name, slug }: { id: number; name: string; slug: string }) {
|
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");
|
const { UserRepository } = await import("@calcom/features/users/repositories/UserRepository");
|
||||||
vi.mocked(UserRepository).mockImplementation(
|
vi.mocked(UserRepository).mockImplementation(function () {
|
||||||
() =>
|
return {
|
||||||
({
|
isAMemberOfOrganization: vi.fn().mockResolvedValue(true),
|
||||||
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();
|
await expect(handleUserEvents(event, organizationId)).resolves.not.toThrow();
|
||||||
});
|
});
|
||||||
@@ -292,12 +291,11 @@ describe("handleUserEvents", () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const { UserRepository } = await import("@calcom/features/users/repositories/UserRepository");
|
const { UserRepository } = await import("@calcom/features/users/repositories/UserRepository");
|
||||||
vi.mocked(UserRepository).mockImplementation(
|
vi.mocked(UserRepository).mockImplementation(function () {
|
||||||
() =>
|
return {
|
||||||
({
|
isAMemberOfOrganization: vi.fn().mockResolvedValue(false),
|
||||||
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 inviteExistingUserToOrg = (await import("./users/inviteExistingUserToOrg")).default;
|
||||||
const sendExistingUserTeamInviteEmails = (
|
const sendExistingUserTeamInviteEmails = (
|
||||||
@@ -377,12 +375,11 @@ describe("handleUserEvents", () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const { UserRepository } = await import("@calcom/features/users/repositories/UserRepository");
|
const { UserRepository } = await import("@calcom/features/users/repositories/UserRepository");
|
||||||
vi.mocked(UserRepository).mockImplementation(
|
vi.mocked(UserRepository).mockImplementation(function () {
|
||||||
() =>
|
return {
|
||||||
({
|
isAMemberOfOrganization: vi.fn().mockResolvedValue(true),
|
||||||
isAMemberOfOrganization: vi.fn().mockResolvedValue(true),
|
} as unknown as InstanceType<typeof UserRepository>;
|
||||||
} as unknown as InstanceType<typeof UserRepository>)
|
});
|
||||||
);
|
|
||||||
|
|
||||||
const { assignValueToUserInOrgBulk } = await import("./assignValueToUser");
|
const { assignValueToUserInOrgBulk } = await import("./assignValueToUser");
|
||||||
|
|
||||||
|
|||||||
@@ -179,7 +179,10 @@ type ConferenceResult = {
|
|||||||
const mockEventManagerReschedule = async (config?: MockEventManagerConfig) => {
|
const mockEventManagerReschedule = async (config?: MockEventManagerConfig) => {
|
||||||
const EventManager = (await import("@calcom/features/bookings/lib/EventManager")).default;
|
const EventManager = (await import("@calcom/features/bookings/lib/EventManager")).default;
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// 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
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
spy.mockImplementation(async (event: any) => {
|
spy.mockImplementation(async (event: any) => {
|
||||||
|
|||||||
@@ -64,6 +64,8 @@ describe("roundRobinReassignment test", () => {
|
|||||||
const EventManager = (await import("@calcom/features/bookings/lib/EventManager")).default;
|
const EventManager = (await import("@calcom/features/bookings/lib/EventManager")).default;
|
||||||
|
|
||||||
const eventManagerSpy = vi.spyOn(EventManager.prototype as any, "reschedule");
|
const eventManagerSpy = vi.spyOn(EventManager.prototype as any, "reschedule");
|
||||||
|
// Clear any existing mock calls from previous tests
|
||||||
|
eventManagerSpy.mockClear();
|
||||||
eventManagerSpy.mockResolvedValue({ referencesToCreate: [] });
|
eventManagerSpy.mockResolvedValue({ referencesToCreate: [] });
|
||||||
|
|
||||||
const users = testUsers;
|
const users = testUsers;
|
||||||
@@ -197,6 +199,8 @@ describe("roundRobinReassignment test", () => {
|
|||||||
const EventManager = (await import("@calcom/features/bookings/lib/EventManager")).default;
|
const EventManager = (await import("@calcom/features/bookings/lib/EventManager")).default;
|
||||||
|
|
||||||
const eventManagerSpy = vi.spyOn(EventManager.prototype as any, "reschedule");
|
const eventManagerSpy = vi.spyOn(EventManager.prototype as any, "reschedule");
|
||||||
|
// Clear any existing mock calls from previous tests
|
||||||
|
eventManagerSpy.mockClear();
|
||||||
|
|
||||||
const users = testUsers;
|
const users = testUsers;
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ const mockTeamRepo = {
|
|||||||
throw new Error(`Team with id ${id} not found`);
|
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) => {
|
vi.mocked(deleteDomain).mockImplementation(async (slug) => {
|
||||||
database.domains.delete(slug);
|
database.domains.delete(slug);
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ describe("TeamService", () => {
|
|||||||
const mockTeamRepo = {
|
const mockTeamRepo = {
|
||||||
deleteById: vi.fn().mockResolvedValue(mockDeletedTeam),
|
deleteById: vi.fn().mockResolvedValue(mockDeletedTeam),
|
||||||
} as Pick<TeamRepository, "deleteById">;
|
} as Pick<TeamRepository, "deleteById">;
|
||||||
vi.mocked(TeamRepository).mockImplementation(() => mockTeamRepo);
|
vi.mocked(TeamRepository).mockImplementation(function() { return mockTeamRepo; });
|
||||||
|
|
||||||
const result = await TeamService.delete({ id: 1 });
|
const result = await TeamService.delete({ id: 1 });
|
||||||
|
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ vi.mock("@calcom/features/profile/lib/hideBranding", () => ({
|
|||||||
|
|
||||||
const mockWorkflowReminderCreate = vi.fn();
|
const mockWorkflowReminderCreate = vi.fn();
|
||||||
vi.mock("@calcom/features/ee/workflows/repositories/WorkflowReminderRepository", () => ({
|
vi.mock("@calcom/features/ee/workflows/repositories/WorkflowReminderRepository", () => ({
|
||||||
WorkflowReminderRepository: vi.fn().mockImplementation(() => ({
|
WorkflowReminderRepository: vi.fn().mockImplementation(function() { return {
|
||||||
create: mockWorkflowReminderCreate,
|
create: mockWorkflowReminderCreate,
|
||||||
})),
|
}; }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("@calcom/prisma", () => ({
|
vi.mock("@calcom/prisma", () => ({
|
||||||
|
|||||||
@@ -18,10 +18,10 @@ vi.mock("../reminders/providers/twilioProvider", () => ({
|
|||||||
|
|
||||||
const mockChargeCredits = vi.fn().mockResolvedValue({ teamId: 1 });
|
const mockChargeCredits = vi.fn().mockResolvedValue({ teamId: 1 });
|
||||||
vi.mock("@calcom/features/ee/billing/credit-service", () => ({
|
vi.mock("@calcom/features/ee/billing/credit-service", () => ({
|
||||||
CreditService: vi.fn().mockImplementation(() => ({
|
CreditService: vi.fn().mockImplementation(function() { return {
|
||||||
chargeCredits: mockChargeCredits,
|
chargeCredits: mockChargeCredits,
|
||||||
calculateCreditsFromPrice: vi.fn().mockReturnValue(1),
|
calculateCreditsFromPrice: vi.fn().mockReturnValue(1),
|
||||||
})),
|
}; }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const mockFindFirst = vi.fn();
|
const mockFindFirst = vi.fn();
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ vi.mock("@calcom/prisma", () => {
|
|||||||
return {
|
return {
|
||||||
__esModule: true,
|
__esModule: true,
|
||||||
default: mockPrisma,
|
default: mockPrisma,
|
||||||
PrismaClient: vi.fn(() => mockPrisma),
|
PrismaClient: vi.fn().mockImplementation(function() { return mockPrisma; }),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ describe("getEventTypePermissions", () => {
|
|||||||
getResourcePermissions: vi.fn(),
|
getResourcePermissions: vi.fn(),
|
||||||
};
|
};
|
||||||
|
|
||||||
vi.mocked(FeaturesRepository).mockImplementation(() => mockFeaturesRepository as any);
|
vi.mocked(FeaturesRepository).mockImplementation(function() { return mockFeaturesRepository as any; });
|
||||||
vi.mocked(PermissionCheckService).mockImplementation(() => mockPermissionCheckService as any);
|
vi.mocked(PermissionCheckService).mockImplementation(function() { return mockPermissionCheckService as any; });
|
||||||
|
|
||||||
prisma.membership.findFirst = vi.fn();
|
prisma.membership.findFirst = vi.fn();
|
||||||
prisma.team.findUnique = vi.fn();
|
prisma.team.findUnique = vi.fn();
|
||||||
@@ -546,8 +546,8 @@ describe("getEventTypePermissions", () => {
|
|||||||
vi.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
|
|
||||||
// Re-initialize mocks after clearing
|
// Re-initialize mocks after clearing
|
||||||
vi.mocked(FeaturesRepository).mockImplementation(() => mockFeaturesRepository as any);
|
vi.mocked(FeaturesRepository).mockImplementation(function() { return mockFeaturesRepository as any; });
|
||||||
vi.mocked(PermissionCheckService).mockImplementation(() => mockPermissionCheckService as any);
|
vi.mocked(PermissionCheckService).mockImplementation(function() { return mockPermissionCheckService as any; });
|
||||||
prisma.membership.findFirst = vi.fn();
|
prisma.membership.findFirst = vi.fn();
|
||||||
prisma.team.findUnique = vi.fn();
|
prisma.team.findUnique = vi.fn();
|
||||||
|
|
||||||
|
|||||||
@@ -42,9 +42,9 @@ describe("getResourcePermissions", () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// 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
|
// 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", () => {
|
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/routing-forms/repositories/PrismaRoutingFormRepository");
|
||||||
vi.mock("@calcom/features/users/repositories/UserRepository", () => {
|
vi.mock("@calcom/features/users/repositories/UserRepository", () => {
|
||||||
return {
|
return {
|
||||||
UserRepository: vi.fn().mockImplementation(() => ({
|
UserRepository: vi.fn().mockImplementation(function() { return {
|
||||||
enrichUserWithItsProfile: vi.fn(),
|
enrichUserWithItsProfile: vi.fn(),
|
||||||
})),
|
}; }),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
vi.mock("@calcom/features/ee/organizations/lib/orgDomains");
|
vi.mock("@calcom/features/ee/organizations/lib/orgDomains");
|
||||||
@@ -89,13 +89,12 @@ describe("getRoutedUrl", () => {
|
|||||||
const mockEnrichUserWithItsProfile = vi.fn().mockImplementation(async ({ user }) => user);
|
const mockEnrichUserWithItsProfile = vi.fn().mockImplementation(async ({ user }) => user);
|
||||||
const mockUserRepository = vi.mocked(UserRepository);
|
const mockUserRepository = vi.mocked(UserRepository);
|
||||||
if (mockUserRepository && typeof mockUserRepository.mockImplementation === "function") {
|
if (mockUserRepository && typeof mockUserRepository.mockImplementation === "function") {
|
||||||
mockUserRepository.mockImplementation(
|
mockUserRepository.mockImplementation(function () {
|
||||||
() =>
|
return {
|
||||||
({
|
enrichUserWithItsProfile: mockEnrichUserWithItsProfile,
|
||||||
enrichUserWithItsProfile: mockEnrichUserWithItsProfile,
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
} as any;
|
||||||
} as any)
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
vi.mocked(isAuthorizedToViewFormOnOrgDomain).mockReturnValue(true);
|
vi.mocked(isAuthorizedToViewFormOnOrgDomain).mockReturnValue(true);
|
||||||
vi.mocked(getSerializableForm).mockResolvedValue(mockSerializableForm as never);
|
vi.mocked(getSerializableForm).mockResolvedValue(mockSerializableForm as never);
|
||||||
|
|||||||
@@ -119,10 +119,10 @@ const mockResponse: Record<
|
|||||||
describe("handleResponse", () => {
|
describe("handleResponse", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.resetAllMocks();
|
vi.resetAllMocks();
|
||||||
vi.mocked(RoutingFormResponseRepository).mockImplementation(
|
vi.mocked(RoutingFormResponseRepository).mockImplementation(function () {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// 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 () => {
|
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", () => ({
|
vi.mock("@calcom/features/flags/features.repository", () => ({
|
||||||
FeaturesRepository: vi.fn().mockImplementation(() => ({
|
FeaturesRepository: vi.fn(function () {
|
||||||
checkIfFeatureIsEnabledGlobally: vi.fn().mockResolvedValue(false),
|
return {
|
||||||
})),
|
checkIfFeatureIsEnabledGlobally: vi.fn().mockResolvedValue(false),
|
||||||
|
};
|
||||||
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.spyOn(CalcomEmails, "sendOrganizationAdminNoSlotsNotification");
|
vi.spyOn(CalcomEmails, "sendOrganizationAdminNoSlotsNotification");
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ vi.mock("@calcom/emails/workflow-email-service", () => ({
|
|||||||
|
|
||||||
const mockGetBookingForCalEventBuilderFromUid = vi.fn();
|
const mockGetBookingForCalEventBuilderFromUid = vi.fn();
|
||||||
vi.mock("@calcom/features/bookings/repositories/BookingRepository", () => ({
|
vi.mock("@calcom/features/bookings/repositories/BookingRepository", () => ({
|
||||||
BookingRepository: vi.fn().mockImplementation(() => ({
|
BookingRepository: vi.fn().mockImplementation(function() { return {
|
||||||
getBookingForCalEventBuilderFromUid: mockGetBookingForCalEventBuilderFromUid,
|
getBookingForCalEventBuilderFromUid: mockGetBookingForCalEventBuilderFromUid,
|
||||||
})),
|
}; }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("@calcom/features/bookings/repositories/BookingSeatRepository", () => ({
|
vi.mock("@calcom/features/bookings/repositories/BookingSeatRepository", () => ({
|
||||||
@@ -17,9 +17,9 @@ vi.mock("@calcom/features/bookings/repositories/BookingSeatRepository", () => ({
|
|||||||
|
|
||||||
const mockHandleSendEmailWorkflowTask = vi.fn();
|
const mockHandleSendEmailWorkflowTask = vi.fn();
|
||||||
vi.mock("@calcom/features/ee/workflows/lib/service/EmailWorkflowService", () => ({
|
vi.mock("@calcom/features/ee/workflows/lib/service/EmailWorkflowService", () => ({
|
||||||
EmailWorkflowService: vi.fn().mockImplementation(() => ({
|
EmailWorkflowService: vi.fn().mockImplementation(function() { return {
|
||||||
handleSendEmailWorkflowTask: mockHandleSendEmailWorkflowTask,
|
handleSendEmailWorkflowTask: mockHandleSendEmailWorkflowTask,
|
||||||
})),
|
}; }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("@calcom/features/ee/workflows/repositories/WorkflowReminderRepository", () => ({
|
vi.mock("@calcom/features/ee/workflows/repositories/WorkflowReminderRepository", () => ({
|
||||||
|
|||||||
@@ -27,7 +27,9 @@ const mockUserRepository = {
|
|||||||
|
|
||||||
vi.mock("@calcom/features/users/repositories/UserRepository", () => {
|
vi.mock("@calcom/features/users/repositories/UserRepository", () => {
|
||||||
return {
|
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";
|
import { useCompatSearchParams } from "./useCompatSearchParams";
|
||||||
|
|
||||||
vi.mock("next/navigation", () => ({
|
vi.mock("next/navigation", () => ({
|
||||||
ReadonlyURLSearchParams: vi.fn((a) => a),
|
ReadonlyURLSearchParams: vi.fn().mockImplementation(function(a) { return a; }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe("useCompatSearchParams hook", () => {
|
describe("useCompatSearchParams hook", () => {
|
||||||
|
|||||||
@@ -64,7 +64,11 @@ describe("getServerErrorFromUnknown", () => {
|
|||||||
expect(result).toBeInstanceOf(HttpError);
|
expect(result).toBeInstanceOf(HttpError);
|
||||||
expect(result.statusCode).toBe(400);
|
expect(result.statusCode).toBe(400);
|
||||||
expect(result.message).toBe(stripeError.message);
|
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");
|
expect(result.name).toBe("HttpError");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -25,8 +25,8 @@
|
|||||||
"@types/node": "20.17.23",
|
"@types/node": "20.17.23",
|
||||||
"@types/react": "18.0.26",
|
"@types/react": "18.0.26",
|
||||||
"@types/react-dom": "18.2.6",
|
"@types/react-dom": "18.2.6",
|
||||||
"@vitejs/plugin-react": "2.2.0",
|
"@vitejs/plugin-react": "5.1.2",
|
||||||
"@vitejs/plugin-react-swc": "3.7.0",
|
"@vitejs/plugin-react-swc": "4.2.2",
|
||||||
"autoprefixer": "10.4.19",
|
"autoprefixer": "10.4.19",
|
||||||
"cssnano": "7.1.2",
|
"cssnano": "7.1.2",
|
||||||
"jest": "29.7.0",
|
"jest": "29.7.0",
|
||||||
@@ -37,8 +37,8 @@
|
|||||||
"postcss-prefixwrap": "1.46.0",
|
"postcss-prefixwrap": "1.46.0",
|
||||||
"ts-jest": "29.1.4",
|
"ts-jest": "29.1.4",
|
||||||
"typescript": "5.9.3",
|
"typescript": "5.9.3",
|
||||||
"vite": "5.4.21",
|
"vite": "6.4.1",
|
||||||
"vite-plugin-dts": "3.7.3",
|
"vite-plugin-dts": "4.5.4",
|
||||||
"vite-plugin-inspect": "0.8.4"
|
"vite-plugin-inspect": "0.8.4"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
|
|||||||
@@ -28,10 +28,10 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "20.17.23",
|
"@types/node": "20.17.23",
|
||||||
"@vitejs/plugin-react": "4.2.1",
|
"@vitejs/plugin-react": "5.1.2",
|
||||||
"typescript": "5.9.3",
|
"typescript": "5.9.3",
|
||||||
"vite": "5.4.21",
|
"vite": "6.4.1",
|
||||||
"vite-plugin-dts": "3.7.3",
|
"vite-plugin-dts": "4.5.4",
|
||||||
"vite-plugin-environment": "1.1.3"
|
"vite-plugin-environment": "1.1.3"
|
||||||
},
|
},
|
||||||
"exports": {
|
"exports": {
|
||||||
|
|||||||
+2
-2
@@ -14,9 +14,9 @@ vi.mock("@calcom/lib/hasEditPermissionForUser", () => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("@calcom/features/schedules/repositories/ScheduleRepository", () => ({
|
vi.mock("@calcom/features/schedules/repositories/ScheduleRepository", () => ({
|
||||||
ScheduleRepository: vi.fn().mockImplementation(() => ({
|
ScheduleRepository: vi.fn().mockImplementation(function() { return {
|
||||||
getDefaultScheduleId: vi.fn().mockResolvedValue(DEFAULT_SCHEDULE_ID),
|
getDefaultScheduleId: vi.fn().mockResolvedValue(DEFAULT_SCHEDULE_ID),
|
||||||
})),
|
}; }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
import { hasReadPermissionsForUserId } from "@calcom/lib/hasEditPermissionForUser";
|
import { hasReadPermissionsForUserId } from "@calcom/lib/hasEditPermissionForUser";
|
||||||
|
|||||||
@@ -58,9 +58,9 @@ describe("reportBookingHandler", () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
|
|
||||||
vi.mocked(BookingRepository).mockImplementation(() => mockBookingRepo);
|
vi.mocked(BookingRepository).mockImplementation(function() { return mockBookingRepo; });
|
||||||
vi.mocked(PrismaBookingReportRepository).mockImplementation(() => mockReportRepo);
|
vi.mocked(PrismaBookingReportRepository).mockImplementation(function() { return mockReportRepo; });
|
||||||
vi.mocked(BookingAccessService).mockImplementation(() => mockBookingAccessService);
|
vi.mocked(BookingAccessService).mockImplementation(function() { return mockBookingAccessService; });
|
||||||
mockReportRepo.createReport.mockResolvedValue({ id: "new-report" });
|
mockReportRepo.createReport.mockResolvedValue({ id: "new-report" });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -27,9 +27,9 @@ vi.mock("@calcom/features/profile/repositories/ProfileRepository", () => ({
|
|||||||
const mockFilterTeamsByEventTypeReadPermission = vi.fn();
|
const mockFilterTeamsByEventTypeReadPermission = vi.fn();
|
||||||
|
|
||||||
vi.mock("../teamAccessUseCase", () => ({
|
vi.mock("../teamAccessUseCase", () => ({
|
||||||
TeamAccessUseCase: vi.fn().mockImplementation(() => ({
|
TeamAccessUseCase: vi.fn().mockImplementation(function() { return {
|
||||||
filterTeamsByEventTypeReadPermission: mockFilterTeamsByEventTypeReadPermission,
|
filterTeamsByEventTypeReadPermission: mockFilterTeamsByEventTypeReadPermission,
|
||||||
})),
|
}; }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("@calcom/features/ee/organizations/lib/getBookerUrlServer", () => ({
|
vi.mock("@calcom/features/ee/organizations/lib/getBookerUrlServer", () => ({
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ describe("createEventPbacProcedure", () => {
|
|||||||
checkPermission: vi.fn(),
|
checkPermission: vi.fn(),
|
||||||
};
|
};
|
||||||
|
|
||||||
vi.mocked(PermissionCheckService).mockImplementation(() => mockPermissionCheckService as any);
|
vi.mocked(PermissionCheckService).mockImplementation(function() { return mockPermissionCheckService as any; });
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("personal events", () => {
|
describe("personal events", () => {
|
||||||
|
|||||||
@@ -15,7 +15,14 @@ vi.mock("@calcom/features/eventtypes/repositories/eventTypeRepository");
|
|||||||
describe("duplicateHandler", () => {
|
describe("duplicateHandler", () => {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const ctx = { user: { id: 1, profile: { id: 1 } } } as 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 }] };
|
const eventType = { id: 123, userId: 1, teamId: null, users: [{ id: 1 }] };
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@@ -23,27 +30,27 @@ describe("duplicateHandler", () => {
|
|||||||
prismaMock.eventType.findUnique.mockResolvedValue(eventType);
|
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(
|
const { EventTypeRepository } = await import(
|
||||||
"@calcom/features/eventtypes/repositories/eventTypeRepository"
|
"@calcom/features/eventtypes/repositories/eventTypeRepository"
|
||||||
);
|
);
|
||||||
vi.mocked(EventTypeRepository).mockImplementation(
|
vi.mocked(EventTypeRepository).mockImplementation(function () {
|
||||||
() =>
|
return {
|
||||||
({
|
create: vi.fn().mockRejectedValue(
|
||||||
create: vi.fn().mockRejectedValue(
|
new PrismaClientKnownRequestError("Unique constraint failed", {
|
||||||
new PrismaClientKnownRequestError("Unique constraint failed", {
|
code: "P2002",
|
||||||
code: "P2002",
|
clientVersion: "mockedVersion",
|
||||||
clientVersion: "mockedVersion",
|
})
|
||||||
})
|
),
|
||||||
),
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
} as any;
|
||||||
} as any)
|
});
|
||||||
);
|
|
||||||
|
|
||||||
await expect(duplicateHandler({ ctx, input })).rejects.toThrow(
|
await expect(duplicateHandler({ ctx, input })).rejects.toThrow(
|
||||||
new TRPCError({
|
new TRPCError({
|
||||||
code: "BAD_REQUEST",
|
code: "INTERNAL_SERVER_ERROR",
|
||||||
message: "Error duplicating event type PrismaClientKnownRequestError: Unique constraint failed",
|
message:
|
||||||
|
"Error duplicating event type PrismaClientKnownRequestError: Unique constraint failed",
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ import { TeamAccessUseCase } from "./teamAccessUseCase";
|
|||||||
|
|
||||||
// Mock the PermissionCheckService
|
// Mock the PermissionCheckService
|
||||||
vi.mock("@calcom/features/pbac/services/permission-check.service", () => ({
|
vi.mock("@calcom/features/pbac/services/permission-check.service", () => ({
|
||||||
PermissionCheckService: vi.fn().mockImplementation(() => ({
|
PermissionCheckService: vi.fn().mockImplementation(function() { return {
|
||||||
checkPermission: vi.fn(),
|
checkPermission: vi.fn(),
|
||||||
})),
|
}; }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe("TeamAccessUseCase", () => {
|
describe("TeamAccessUseCase", () => {
|
||||||
|
|||||||
+1
-1
@@ -45,7 +45,7 @@ describe("deleteWatchlistEntryHandler", () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
vi.mocked(getOrganizationWatchlistOperationsService).mockReturnValue(mockService as never);
|
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", () => {
|
describe("access control", () => {
|
||||||
|
|||||||
+6
-6
@@ -49,12 +49,12 @@ describe("dismissBookingReportHandler", () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
vi.mocked(PermissionCheckService).mockImplementation(
|
vi.mocked(PermissionCheckService).mockImplementation(function () {
|
||||||
() => mockPermissionCheckService as InstanceType<typeof PermissionCheckService>
|
return mockPermissionCheckService as InstanceType<typeof PermissionCheckService>;
|
||||||
);
|
});
|
||||||
vi.mocked(PrismaBookingReportRepository).mockImplementation(
|
vi.mocked(PrismaBookingReportRepository).mockImplementation(function () {
|
||||||
() => mockReportRepo as InstanceType<typeof PrismaBookingReportRepository>
|
return mockReportRepo as InstanceType<typeof PrismaBookingReportRepository>;
|
||||||
);
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("access control", () => {
|
describe("access control", () => {
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ describe("intentToCreateOrgHandler", () => {
|
|||||||
vi.resetAllMocks();
|
vi.resetAllMocks();
|
||||||
await prismock.reset();
|
await prismock.reset();
|
||||||
|
|
||||||
vi.mocked(OrganizationPaymentService).mockImplementation(() => {
|
vi.mocked(OrganizationPaymentService).mockImplementation(function () {
|
||||||
return {
|
return {
|
||||||
createOrganizationOnboarding: vi
|
createOrganizationOnboarding: vi
|
||||||
.fn()
|
.fn()
|
||||||
|
|||||||
+6
-6
@@ -81,12 +81,12 @@ describe("listBookingReportsHandler (Organization)", () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
vi.mocked(PermissionCheckService).mockImplementation(
|
vi.mocked(PermissionCheckService).mockImplementation(function () {
|
||||||
() => mockPermissionCheckService as InstanceType<typeof PermissionCheckService>
|
return mockPermissionCheckService as InstanceType<typeof PermissionCheckService>;
|
||||||
);
|
});
|
||||||
vi.mocked(PrismaBookingReportRepository).mockImplementation(
|
vi.mocked(PrismaBookingReportRepository).mockImplementation(function () {
|
||||||
() => mockReportRepo as InstanceType<typeof PrismaBookingReportRepository>
|
return mockReportRepo as InstanceType<typeof PrismaBookingReportRepository>;
|
||||||
);
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("access control", () => {
|
describe("access control", () => {
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ vi.mock("@calcom/prisma", () => ({
|
|||||||
// Mock FeaturesRepository
|
// Mock FeaturesRepository
|
||||||
const mockCheckIfTeamHasFeature = vi.fn();
|
const mockCheckIfTeamHasFeature = vi.fn();
|
||||||
vi.mock("@calcom/features/flags/features.repository", () => ({
|
vi.mock("@calcom/features/flags/features.repository", () => ({
|
||||||
FeaturesRepository: vi.fn().mockImplementation(() => ({
|
FeaturesRepository: vi.fn().mockImplementation(function() { return {
|
||||||
checkIfTeamHasFeature: mockCheckIfTeamHasFeature,
|
checkIfTeamHasFeature: mockCheckIfTeamHasFeature,
|
||||||
})),
|
}; }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Mock PBAC permissions
|
// Mock PBAC permissions
|
||||||
@@ -31,16 +31,18 @@ vi.mock("@calcom/features/pbac/lib/resource-permissions", () => ({
|
|||||||
// Mock PermissionCheckService
|
// Mock PermissionCheckService
|
||||||
const mockCheckPermission = vi.fn().mockResolvedValue(true);
|
const mockCheckPermission = vi.fn().mockResolvedValue(true);
|
||||||
vi.mock("@calcom/features/pbac/services/permission-check.service", () => ({
|
vi.mock("@calcom/features/pbac/services/permission-check.service", () => ({
|
||||||
PermissionCheckService: vi.fn().mockImplementation(() => ({
|
PermissionCheckService: vi.fn().mockImplementation(function() { return {
|
||||||
checkPermission: mockCheckPermission,
|
checkPermission: mockCheckPermission,
|
||||||
})),
|
}; }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Mock UserRepository
|
// Mock UserRepository
|
||||||
vi.mock("@calcom/features/users/repositories/UserRepository", () => ({
|
vi.mock("@calcom/features/users/repositories/UserRepository", () => ({
|
||||||
UserRepository: vi.fn().mockImplementation(() => ({
|
UserRepository: vi.fn().mockImplementation(function() {
|
||||||
enrichUserWithItsProfile: vi.fn().mockImplementation(({ user }) => user),
|
return {
|
||||||
})),
|
enrichUserWithItsProfile: vi.fn().mockImplementation(({ user }) => user),
|
||||||
|
};
|
||||||
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const ORGANIZATION_ID = 123;
|
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.
|
// 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.
|
// To keep this unit test isolated from the database layer, we stub this to always resolve falsey.
|
||||||
vi.mock("@calcom/features/selectedSlots/repositories/PrismaSelectedSlotRepository", () => ({
|
vi.mock("@calcom/features/selectedSlots/repositories/PrismaSelectedSlotRepository", () => ({
|
||||||
PrismaSelectedSlotRepository: vi.fn().mockImplementation(() => ({
|
PrismaSelectedSlotRepository: vi.fn().mockImplementation(function() { return {
|
||||||
findReservedByOthers: vi.fn().mockResolvedValue(null),
|
findReservedByOthers: vi.fn().mockResolvedValue(null),
|
||||||
})),
|
}; }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// A tiny helper to build a canned handler context with stubbed Prisma methods.
|
// A tiny helper to build a canned handler context with stubbed Prisma methods.
|
||||||
|
|||||||
+16
-12
@@ -47,23 +47,27 @@ vi.mock("@calcom/features/flags/features.repository");
|
|||||||
vi.mock("@calcom/features/membership/repositories/MembershipRepository");
|
vi.mock("@calcom/features/membership/repositories/MembershipRepository");
|
||||||
vi.mock("@calcom/features/pbac/services/permission.service", () => {
|
vi.mock("@calcom/features/pbac/services/permission.service", () => {
|
||||||
return {
|
return {
|
||||||
PermissionService: vi.fn().mockImplementation(() => ({
|
PermissionService: vi.fn().mockImplementation(function() {
|
||||||
validatePermission: vi.fn().mockReturnValue({ isValid: true }),
|
return {
|
||||||
validatePermissions: vi.fn().mockReturnValue({ isValid: true }),
|
validatePermission: vi.fn().mockReturnValue({ isValid: true }),
|
||||||
})),
|
validatePermissions: vi.fn().mockReturnValue({ isValid: true }),
|
||||||
|
};
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
vi.mock("@calcom/features/pbac/services/permission-check.service", () => {
|
vi.mock("@calcom/features/pbac/services/permission-check.service", () => {
|
||||||
return {
|
return {
|
||||||
PermissionCheckService: vi.fn().mockImplementation(() => ({
|
PermissionCheckService: vi.fn().mockImplementation(function() {
|
||||||
checkPermission: vi.fn().mockResolvedValue(true),
|
return {
|
||||||
checkPermissions: vi.fn().mockResolvedValue(true),
|
checkPermission: vi.fn().mockResolvedValue(true),
|
||||||
getUserPermissions: vi.fn().mockResolvedValue([]),
|
checkPermissions: vi.fn().mockResolvedValue(true),
|
||||||
getResourcePermissions: vi.fn().mockResolvedValue([]),
|
getUserPermissions: vi.fn().mockResolvedValue([]),
|
||||||
getTeamIdsWithPermission: vi.fn().mockResolvedValue([]),
|
getResourcePermissions: vi.fn().mockResolvedValue([]),
|
||||||
getTeamIdsWithPermissions: vi.fn().mockResolvedValue([]),
|
getTeamIdsWithPermission: vi.fn().mockResolvedValue([]),
|
||||||
})),
|
getTeamIdsWithPermissions: vi.fn().mockResolvedValue([]),
|
||||||
|
};
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -136,12 +136,11 @@ describe("Invite Member Utils", () => {
|
|||||||
describe("ensureAtleastAdminPermissions", () => {
|
describe("ensureAtleastAdminPermissions", () => {
|
||||||
it("It should throw an error if the user is not an admin of the ORG", async () => {
|
it("It should throw an error if the user is not an admin of the ORG", async () => {
|
||||||
const mockCheckPermission = vi.fn().mockResolvedValue(false);
|
const mockCheckPermission = vi.fn().mockResolvedValue(false);
|
||||||
vi.mocked(PermissionCheckService).mockImplementation(
|
vi.mocked(PermissionCheckService).mockImplementation(function () {
|
||||||
() =>
|
return {
|
||||||
({
|
checkPermission: mockCheckPermission,
|
||||||
checkPermission: mockCheckPermission,
|
} as any;
|
||||||
} as any)
|
});
|
||||||
);
|
|
||||||
|
|
||||||
await expect(ensureAtleastAdminPermissions({ userId: 1, teamId: 1, isOrg: true })).rejects.toThrow(
|
await expect(ensureAtleastAdminPermissions({ userId: 1, teamId: 1, isOrg: true })).rejects.toThrow(
|
||||||
"UNAUTHORIZED"
|
"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 () => {
|
it("It should NOT throw an error if the user is an admin of the ORG", async () => {
|
||||||
const mockCheckPermission = vi.fn().mockResolvedValue(true);
|
const mockCheckPermission = vi.fn().mockResolvedValue(true);
|
||||||
vi.mocked(PermissionCheckService).mockImplementation(
|
vi.mocked(PermissionCheckService).mockImplementation(function () {
|
||||||
() =>
|
return {
|
||||||
({
|
checkPermission: mockCheckPermission,
|
||||||
checkPermission: mockCheckPermission,
|
} as any;
|
||||||
} as any)
|
});
|
||||||
);
|
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
ensureAtleastAdminPermissions({ userId: 1, teamId: 1, isOrg: true })
|
ensureAtleastAdminPermissions({ userId: 1, teamId: 1, isOrg: true })
|
||||||
|
|||||||
+40
-24
@@ -44,9 +44,11 @@ describe("removeHostsFromEventTypesHandler", () => {
|
|||||||
|
|
||||||
it("throws UNAUTHORIZED if user does not have eventType.update permission", async () => {
|
it("throws UNAUTHORIZED if user does not have eventType.update permission", async () => {
|
||||||
const mockCheckPermission = vi.fn().mockResolvedValue(false);
|
const mockCheckPermission = vi.fn().mockResolvedValue(false);
|
||||||
(PermissionCheckService as any).mockImplementation(() => ({
|
(PermissionCheckService as any).mockImplementation(function () {
|
||||||
checkPermission: mockCheckPermission,
|
return {
|
||||||
}));
|
checkPermission: mockCheckPermission,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
removeHostsFromEventTypesHandler({
|
removeHostsFromEventTypesHandler({
|
||||||
@@ -70,9 +72,11 @@ describe("removeHostsFromEventTypesHandler", () => {
|
|||||||
|
|
||||||
it("deletes hosts when user has permission and all users are team members", async () => {
|
it("deletes hosts when user has permission and all users are team members", async () => {
|
||||||
const mockCheckPermission = vi.fn().mockResolvedValue(true);
|
const mockCheckPermission = vi.fn().mockResolvedValue(true);
|
||||||
(PermissionCheckService as any).mockImplementation(() => ({
|
(PermissionCheckService as any).mockImplementation(function () {
|
||||||
checkPermission: mockCheckPermission,
|
return {
|
||||||
}));
|
checkPermission: mockCheckPermission,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
// Mock that all userIds are valid team members
|
// Mock that all userIds are valid team members
|
||||||
(MembershipRepository.findAcceptedMembershipsByUserIdsInTeam as any).mockResolvedValue([
|
(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 () => {
|
it("only removes hosts for userIds that are team members (filters out non-members)", async () => {
|
||||||
const mockCheckPermission = vi.fn().mockResolvedValue(true);
|
const mockCheckPermission = vi.fn().mockResolvedValue(true);
|
||||||
(PermissionCheckService as any).mockImplementation(() => ({
|
(PermissionCheckService as any).mockImplementation(function () {
|
||||||
checkPermission: mockCheckPermission,
|
return {
|
||||||
}));
|
checkPermission: mockCheckPermission,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
// Mock that only userId 101 is a team member, 102 is not
|
// Mock that only userId 101 is a team member, 102 is not
|
||||||
(MembershipRepository.findAcceptedMembershipsByUserIdsInTeam as any).mockResolvedValue([
|
(MembershipRepository.findAcceptedMembershipsByUserIdsInTeam as any).mockResolvedValue([
|
||||||
@@ -161,9 +167,11 @@ describe("removeHostsFromEventTypesHandler", () => {
|
|||||||
|
|
||||||
it("handles empty userIds array", async () => {
|
it("handles empty userIds array", async () => {
|
||||||
const mockCheckPermission = vi.fn().mockResolvedValue(true);
|
const mockCheckPermission = vi.fn().mockResolvedValue(true);
|
||||||
(PermissionCheckService as any).mockImplementation(() => ({
|
(PermissionCheckService as any).mockImplementation(function () {
|
||||||
checkPermission: mockCheckPermission,
|
return {
|
||||||
}));
|
checkPermission: mockCheckPermission,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
// Empty array means no memberships to validate
|
// Empty array means no memberships to validate
|
||||||
(MembershipRepository.findAcceptedMembershipsByUserIdsInTeam as any).mockResolvedValue([]);
|
(MembershipRepository.findAcceptedMembershipsByUserIdsInTeam as any).mockResolvedValue([]);
|
||||||
@@ -200,9 +208,11 @@ describe("removeHostsFromEventTypesHandler", () => {
|
|||||||
|
|
||||||
it("handles empty eventTypeIds array", async () => {
|
it("handles empty eventTypeIds array", async () => {
|
||||||
const mockCheckPermission = vi.fn().mockResolvedValue(true);
|
const mockCheckPermission = vi.fn().mockResolvedValue(true);
|
||||||
(PermissionCheckService as any).mockImplementation(() => ({
|
(PermissionCheckService as any).mockImplementation(function () {
|
||||||
checkPermission: mockCheckPermission,
|
return {
|
||||||
}));
|
checkPermission: mockCheckPermission,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
// Mock that all userIds are valid team members
|
// Mock that all userIds are valid team members
|
||||||
(MembershipRepository.findAcceptedMembershipsByUserIdsInTeam as any).mockResolvedValue([
|
(MembershipRepository.findAcceptedMembershipsByUserIdsInTeam as any).mockResolvedValue([
|
||||||
@@ -242,9 +252,11 @@ describe("removeHostsFromEventTypesHandler", () => {
|
|||||||
|
|
||||||
it("returns count of 0 when no hosts match the criteria", async () => {
|
it("returns count of 0 when no hosts match the criteria", async () => {
|
||||||
const mockCheckPermission = vi.fn().mockResolvedValue(true);
|
const mockCheckPermission = vi.fn().mockResolvedValue(true);
|
||||||
(PermissionCheckService as any).mockImplementation(() => ({
|
(PermissionCheckService as any).mockImplementation(function () {
|
||||||
checkPermission: mockCheckPermission,
|
return {
|
||||||
}));
|
checkPermission: mockCheckPermission,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
// Mock that all userIds are valid team members
|
// Mock that all userIds are valid team members
|
||||||
(MembershipRepository.findAcceptedMembershipsByUserIdsInTeam as any).mockResolvedValue([
|
(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 () => {
|
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);
|
const mockCheckPermission = vi.fn().mockResolvedValue(true);
|
||||||
(PermissionCheckService as any).mockImplementation(() => ({
|
(PermissionCheckService as any).mockImplementation(function () {
|
||||||
checkPermission: mockCheckPermission,
|
return {
|
||||||
}));
|
checkPermission: mockCheckPermission,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
// User 999 is a valid team member
|
// User 999 is a valid team member
|
||||||
(MembershipRepository.findAcceptedMembershipsByUserIdsInTeam as any).mockResolvedValue([
|
(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 () => {
|
it("returns count of 0 when event types do not belong to the specified team", async () => {
|
||||||
const mockCheckPermission = vi.fn().mockResolvedValue(true);
|
const mockCheckPermission = vi.fn().mockResolvedValue(true);
|
||||||
(PermissionCheckService as any).mockImplementation(() => ({
|
(PermissionCheckService as any).mockImplementation(function () {
|
||||||
checkPermission: mockCheckPermission,
|
return {
|
||||||
}));
|
checkPermission: mockCheckPermission,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
// Mock that all userIds are valid team members
|
// Mock that all userIds are valid team members
|
||||||
(MembershipRepository.findAcceptedMembershipsByUserIdsInTeam as any).mockResolvedValue([
|
(MembershipRepository.findAcceptedMembershipsByUserIdsInTeam as any).mockResolvedValue([
|
||||||
|
|||||||
+1
-1
@@ -36,7 +36,7 @@ describe("PBACRemoveMemberService", () => {
|
|||||||
getTeamIdsWithPermission: vi.fn(),
|
getTeamIdsWithPermission: vi.fn(),
|
||||||
};
|
};
|
||||||
|
|
||||||
vi.mocked(PermissionCheckService).mockImplementation(() => mockPermissionCheckService as any);
|
vi.mocked(PermissionCheckService).mockImplementation(function() { return mockPermissionCheckService as any; });
|
||||||
|
|
||||||
service = new PBACRemoveMemberService();
|
service = new PBACRemoveMemberService();
|
||||||
});
|
});
|
||||||
|
|||||||
+1
-1
@@ -22,7 +22,7 @@ describe("RemoveMemberServiceFactory", () => {
|
|||||||
checkIfTeamHasFeature: vi.fn(),
|
checkIfTeamHasFeature: vi.fn(),
|
||||||
};
|
};
|
||||||
|
|
||||||
vi.mocked(FeaturesRepository).mockImplementation(() => mockFeaturesRepository as any);
|
vi.mocked(FeaturesRepository).mockImplementation(function() { return mockFeaturesRepository as any; });
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Service Creation", () => {
|
describe("Service Creation", () => {
|
||||||
|
|||||||
@@ -26,15 +26,15 @@ vi.mock("@calcom/prisma", () => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("@calcom/features/pbac/services/permission-check.service", () => ({
|
vi.mock("@calcom/features/pbac/services/permission-check.service", () => ({
|
||||||
PermissionCheckService: vi.fn().mockImplementation(() => ({
|
PermissionCheckService: vi.fn().mockImplementation(function() { return {
|
||||||
checkPermission: vi.fn(),
|
checkPermission: vi.fn(),
|
||||||
})),
|
}; }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("@calcom/features/ee/teams/repositories/TeamRepository", () => ({
|
vi.mock("@calcom/features/ee/teams/repositories/TeamRepository", () => ({
|
||||||
TeamRepository: vi.fn().mockImplementation(() => ({
|
TeamRepository: vi.fn().mockImplementation(function() { return {
|
||||||
isSlugAvailableForUpdate: vi.fn().mockResolvedValue(true),
|
isSlugAvailableForUpdate: vi.fn().mockResolvedValue(true),
|
||||||
})),
|
}; }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("@calcom/lib/server/avatar", () => ({
|
vi.mock("@calcom/lib/server/avatar", () => ({
|
||||||
@@ -64,12 +64,12 @@ describe("updateHandler - Permission Check Tests", () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
vi.mocked(PermissionCheckService).mockImplementation(
|
vi.mocked(PermissionCheckService).mockImplementation(function () {
|
||||||
() => mockPermissionCheckService as unknown as InstanceType<typeof PermissionCheckService>
|
return mockPermissionCheckService as unknown as InstanceType<typeof PermissionCheckService>;
|
||||||
);
|
});
|
||||||
vi.mocked(TeamRepository).mockImplementation(
|
vi.mocked(TeamRepository).mockImplementation(function () {
|
||||||
() => mockTeamRepository as unknown as InstanceType<typeof TeamRepository>
|
return mockTeamRepository as unknown as InstanceType<typeof TeamRepository>;
|
||||||
);
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Permission Check Service", () => {
|
describe("Permission Check Service", () => {
|
||||||
|
|||||||
@@ -28,9 +28,9 @@ vi.mock("@calcom/prisma", () => ({
|
|||||||
const mockCheckPermission = vi.fn();
|
const mockCheckPermission = vi.fn();
|
||||||
|
|
||||||
vi.mock("@calcom/features/pbac/services/permission-check.service", () => ({
|
vi.mock("@calcom/features/pbac/services/permission-check.service", () => ({
|
||||||
PermissionCheckService: vi.fn().mockImplementation(() => ({
|
PermissionCheckService: vi.fn().mockImplementation(function() { return {
|
||||||
checkPermission: mockCheckPermission,
|
checkPermission: mockCheckPermission,
|
||||||
})),
|
}; }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("../../../procedures/authedProcedure", () => ({
|
vi.mock("../../../procedures/authedProcedure", () => ({
|
||||||
|
|||||||
@@ -18,13 +18,12 @@ describe("isAuthorized", () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
mockCheckPermission = vi.fn();
|
mockCheckPermission = vi.fn();
|
||||||
mockPermissionCheckService.mockImplementation(
|
mockPermissionCheckService.mockImplementation(function () {
|
||||||
() =>
|
return {
|
||||||
({
|
checkPermission: mockCheckPermission,
|
||||||
checkPermission: mockCheckPermission,
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
} as any;
|
||||||
} as any)
|
});
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("null workflow", () => {
|
describe("null workflow", () => {
|
||||||
|
|||||||
@@ -7,11 +7,13 @@ import { Button, buttonClasses } from "./Button";
|
|||||||
|
|
||||||
const observeMock = vi.fn();
|
const observeMock = vi.fn();
|
||||||
|
|
||||||
window.ResizeObserver = vi.fn().mockImplementation(() => ({
|
window.ResizeObserver = vi.fn().mockImplementation(function() {
|
||||||
disconnect: vi.fn(),
|
return {
|
||||||
observe: observeMock,
|
disconnect: vi.fn(),
|
||||||
unobserve: vi.fn(),
|
observe: observeMock,
|
||||||
}));
|
unobserve: vi.fn(),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
vi.mock("../tooltip", async () => {
|
vi.mock("../tooltip", async () => {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// 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";
|
import { defineWorkspace } from "vitest/config";
|
||||||
|
|
||||||
const packagedEmbedTestsOnly = process.argv.includes("--packaged-embed-tests-only");
|
// Vitest 4.0 no longer allows custom CLI flags, so we use environment variables instead
|
||||||
const timeZoneDependentTestsOnly = process.argv.includes("--timeZoneDependentTestsOnly");
|
// eslint-disable-next-line turbo/no-undeclared-env-vars
|
||||||
const integrationTestsOnly = process.argv.includes("--integrationTestsOnly");
|
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
|
// eslint-disable-next-line turbo/no-undeclared-env-vars
|
||||||
const envTZ = process.env.TZ;
|
const envTZ = process.env.TZ;
|
||||||
if (timeZoneDependentTestsOnly && !envTZ) {
|
if (timeZoneDependentTestsOnly && !envTZ) {
|
||||||
|
|||||||
Reference in New Issue
Block a user