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 <[email protected]> * 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 <[email protected]> * fix: fix remaining Vitest 4.0 constructor mock patterns Co-Authored-By: Volnei Munhoz <[email protected]> * fix: fix more Vitest 4.0 constructor mock patterns and exclude API v2 spec files Co-Authored-By: Volnei Munhoz <[email protected]> * fix: convert more arrow function mocks to regular functions for Vitest 4.0 Co-Authored-By: Volnei Munhoz <[email protected]> * 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 <[email protected]> * 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 <[email protected]> * fix: add React plugin, jsdom environment, and fix more constructor mocks for Vitest 4.0 Co-Authored-By: Volnei Munhoz <[email protected]> * fix: convert HostRepository PrismaClient mock to regular function for Vitest 4.0 Co-Authored-By: Volnei Munhoz <[email protected]> * fix: add useOrgBranding mock to React component tests for Vitest 4.0 Co-Authored-By: Volnei Munhoz <[email protected]> * fix: update TestFunction type for Vitest 4.0 compatibility Co-Authored-By: Volnei Munhoz <[email protected]> * fix: convert listBookingReports constructor mocks to regular functions for Vitest 4.0 Co-Authored-By: Volnei Munhoz <[email protected]> * fix: convert UserRepository constructor mock to regular function for Vitest 4.0 Co-Authored-By: Volnei Munhoz <[email protected]> * fix: convert OrganizationPaymentService constructor mock to regular function for Vitest 4.0 Co-Authored-By: Volnei Munhoz <[email protected]> * fix: convert more constructor mocks to regular functions for Vitest 4.0 Co-Authored-By: Volnei Munhoz <[email protected]> * fix: add apps/web path aliases to vitest config Co-Authored-By: Volnei Munhoz <[email protected]> * 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 <[email protected]> * fix: clear EventManager spy between tests for Vitest 4.0 compatibility Co-Authored-By: Volnei Munhoz <[email protected]> * fix: update TeamRepository mock pattern for Vitest 4.0 compatibility Co-Authored-By: Volnei Munhoz <[email protected]> * fix: convert RoutingFormResponseRepository mock to regular function for Vitest 4.0 Co-Authored-By: Volnei Munhoz <[email protected]> * fix: convert more constructor mocks to regular functions for Vitest 4.0 Co-Authored-By: Volnei Munhoz <[email protected]> * fix: fix mock reset and spy clear issues for Vitest 4.0 Co-Authored-By: Volnei Munhoz <[email protected]> * 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 <[email protected]> * 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 <[email protected]> * 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 <[email protected]> * fix: add @calcom/embed-snippet alias for CI compatibility Co-Authored-By: Volnei Munhoz <[email protected]> * 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 <[email protected]> * 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 <[email protected]> * 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 <[email protected]> * 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 <[email protected]> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
98 files changed
+2132
-1487
No files matched your search
@@ -23,9 +23,9 @@ const mockFindByEmailAndIncludeProfilesAndPassword = vi.fn();
|
||||
|
||||
vi.mock("@calcom/features/users/repositories/UserRepository", () => {
|
||||
return {
|
||||
UserRepository: vi.fn().mockImplementation(() => ({
|
||||
UserRepository: vi.fn().mockImplementation(function() { return {
|
||||
findByEmailAndIncludeProfilesAndPassword: mockFindByEmailAndIncludeProfilesAndPassword,
|
||||
})),
|
||||
}; }),
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
+3
-3
@@ -130,9 +130,9 @@ describe("BookingAuditAccessService - Permission Checks", () => {
|
||||
checkPermission: vi.fn(),
|
||||
};
|
||||
|
||||
vi.mocked(BookingRepository).mockImplementation(() => mockBookingRepository as unknown as BookingRepository);
|
||||
vi.mocked(MembershipRepository).mockImplementation(() => mockMembershipRepository as unknown as MembershipRepository);
|
||||
vi.mocked(PermissionCheckService).mockImplementation(() => mockPermissionCheckService as unknown as PermissionCheckService);
|
||||
vi.mocked(BookingRepository).mockImplementation(function() { return mockBookingRepository as unknown as BookingRepository; });
|
||||
vi.mocked(MembershipRepository).mockImplementation(function() { return mockMembershipRepository as unknown as MembershipRepository; });
|
||||
vi.mocked(PermissionCheckService).mockImplementation(function() { return mockPermissionCheckService as unknown as PermissionCheckService; });
|
||||
|
||||
service = new BookingAuditAccessService({
|
||||
bookingRepository: mockBookingRepository as unknown as BookingRepository,
|
||||
|
||||
+4
-4
@@ -144,10 +144,10 @@ describe("BookingAuditViewerService - Integration Tests", () => {
|
||||
error: vi.fn(),
|
||||
};
|
||||
|
||||
vi.mocked(BookingRepository).mockImplementation(() => mockBookingRepository as unknown as BookingRepository);
|
||||
vi.mocked(UserRepository).mockImplementation(() => mockUserRepository as unknown as UserRepository);
|
||||
vi.mocked(MembershipRepository).mockImplementation(() => mockMembershipRepository as unknown as MembershipRepository);
|
||||
vi.mocked(PermissionCheckService).mockImplementation(() => mockPermissionCheckService as unknown as PermissionCheckService);
|
||||
vi.mocked(BookingRepository).mockImplementation(function() { return mockBookingRepository as unknown as BookingRepository; });
|
||||
vi.mocked(UserRepository).mockImplementation(function() { return mockUserRepository as unknown as UserRepository; });
|
||||
vi.mocked(MembershipRepository).mockImplementation(function() { return mockMembershipRepository as unknown as MembershipRepository; });
|
||||
vi.mocked(PermissionCheckService).mockImplementation(function() { return mockPermissionCheckService as unknown as PermissionCheckService; });
|
||||
|
||||
service = new BookingAuditViewerService({
|
||||
bookingAuditRepository: mockBookingAuditRepository as unknown as IBookingAuditRepository,
|
||||
|
||||
+32
-38
@@ -11,9 +11,9 @@ import { UserRepository } from "@calcom/features/users/repositories/UserReposito
|
||||
|
||||
vi.mock("@calcom/features/users/repositories/UserRepository", () => {
|
||||
return {
|
||||
UserRepository: vi.fn().mockImplementation(() => ({
|
||||
UserRepository: vi.fn().mockImplementation(function() { return {
|
||||
enrichUserWithItsProfile: vi.fn(),
|
||||
})),
|
||||
}; }),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -25,12 +25,11 @@ describe("getAllCredentialsIncludeServiceAccountKey", () => {
|
||||
|
||||
const mockUserRepository = vi.mocked(UserRepository);
|
||||
if (mockUserRepository && typeof mockUserRepository.mockImplementation === "function") {
|
||||
mockUserRepository.mockImplementation(
|
||||
() =>
|
||||
({
|
||||
enrichUserWithItsProfile: mockEnrichUserWithItsProfile,
|
||||
} as any)
|
||||
);
|
||||
mockUserRepository.mockImplementation(function () {
|
||||
return {
|
||||
enrichUserWithItsProfile: mockEnrichUserWithItsProfile,
|
||||
} as InstanceType<typeof UserRepository>;
|
||||
});
|
||||
}
|
||||
|
||||
const getAllCredentialsIncludeServiceAccountKey = (await import("./getAllCredentials"))
|
||||
@@ -80,12 +79,11 @@ describe("getAllCredentialsIncludeServiceAccountKey", () => {
|
||||
|
||||
const mockUserRepository = vi.mocked(UserRepository);
|
||||
if (mockUserRepository && typeof mockUserRepository.mockImplementation === "function") {
|
||||
mockUserRepository.mockImplementation(
|
||||
() =>
|
||||
({
|
||||
enrichUserWithItsProfile: mockEnrichUserWithItsProfile,
|
||||
} as any)
|
||||
);
|
||||
mockUserRepository.mockImplementation(function () {
|
||||
return {
|
||||
enrichUserWithItsProfile: mockEnrichUserWithItsProfile,
|
||||
} as InstanceType<typeof UserRepository>;
|
||||
});
|
||||
}
|
||||
|
||||
const getAllCredentialsIncludeServiceAccountKey = (await import("./getAllCredentials"))
|
||||
@@ -164,12 +162,11 @@ describe("getAllCredentialsIncludeServiceAccountKey", () => {
|
||||
|
||||
const mockUserRepository = vi.mocked(UserRepository);
|
||||
if (mockUserRepository && typeof mockUserRepository.mockImplementation === "function") {
|
||||
mockUserRepository.mockImplementation(
|
||||
() =>
|
||||
({
|
||||
enrichUserWithItsProfile: mockEnrichUserWithItsProfile,
|
||||
} as any)
|
||||
);
|
||||
mockUserRepository.mockImplementation(function () {
|
||||
return {
|
||||
enrichUserWithItsProfile: mockEnrichUserWithItsProfile,
|
||||
} as InstanceType<typeof UserRepository>;
|
||||
});
|
||||
}
|
||||
|
||||
const getAllCredentialsIncludeServiceAccountKey = (await import("./getAllCredentials"))
|
||||
@@ -241,12 +238,11 @@ describe("getAllCredentialsIncludeServiceAccountKey", () => {
|
||||
|
||||
const mockUserRepository = vi.mocked(UserRepository);
|
||||
if (mockUserRepository && typeof mockUserRepository.mockImplementation === "function") {
|
||||
mockUserRepository.mockImplementation(
|
||||
() =>
|
||||
({
|
||||
enrichUserWithItsProfile: mockEnrichUserWithItsProfile,
|
||||
} as any)
|
||||
);
|
||||
mockUserRepository.mockImplementation(function () {
|
||||
return {
|
||||
enrichUserWithItsProfile: mockEnrichUserWithItsProfile,
|
||||
} as InstanceType<typeof UserRepository>;
|
||||
});
|
||||
}
|
||||
|
||||
const getAllCredentialsIncludeServiceAccountKey = (await import("./getAllCredentials"))
|
||||
@@ -346,12 +342,11 @@ describe("getAllCredentialsIncludeServiceAccountKey", () => {
|
||||
|
||||
const mockUserRepository = vi.mocked(UserRepository);
|
||||
if (mockUserRepository && typeof mockUserRepository.mockImplementation === "function") {
|
||||
mockUserRepository.mockImplementation(
|
||||
() =>
|
||||
({
|
||||
enrichUserWithItsProfile: mockEnrichUserWithItsProfile,
|
||||
} as any)
|
||||
);
|
||||
mockUserRepository.mockImplementation(function () {
|
||||
return {
|
||||
enrichUserWithItsProfile: mockEnrichUserWithItsProfile,
|
||||
} as InstanceType<typeof UserRepository>;
|
||||
});
|
||||
}
|
||||
|
||||
const crmCredential = {
|
||||
@@ -669,12 +664,11 @@ describe("getAllCredentialsIncludeServiceAccountKey", () => {
|
||||
|
||||
const mockUserRepository = vi.mocked(UserRepository);
|
||||
if (mockUserRepository && typeof mockUserRepository.mockImplementation === "function") {
|
||||
mockUserRepository.mockImplementation(
|
||||
() =>
|
||||
({
|
||||
enrichUserWithItsProfile: mockEnrichUserWithItsProfile,
|
||||
} as any)
|
||||
);
|
||||
mockUserRepository.mockImplementation(function () {
|
||||
return {
|
||||
enrichUserWithItsProfile: mockEnrichUserWithItsProfile,
|
||||
} as InstanceType<typeof UserRepository>;
|
||||
});
|
||||
}
|
||||
|
||||
const crmCredential = {
|
||||
|
||||
@@ -39,7 +39,7 @@ vi.mock("@calcom/features/users/repositories/UserRepository", async (importOrigi
|
||||
|
||||
return {
|
||||
...actual,
|
||||
UserRepository: vi.fn().mockImplementation((prisma) => {
|
||||
UserRepository: vi.fn(function (prisma) {
|
||||
const realInstance = new OriginalUserRepository(prisma);
|
||||
realInstance.findManyByEmailsWithEmailVerificationSettings =
|
||||
mockFindManyByEmailsWithEmailVerificationSettings;
|
||||
|
||||
+6
-4
@@ -25,10 +25,12 @@ vi.mock("@calcom/features/CalendarEventBuilder", () => {
|
||||
fromEvent: vi.fn().mockImplementation((_evt) => ({
|
||||
withDestinationCalendar: withDestinationCalendarSpy,
|
||||
withTeam: withTeamSpy,
|
||||
build: vi.fn().mockImplementation(() => ({
|
||||
destinationCalendar: [],
|
||||
team: {}, // <- you won't use this result anyway
|
||||
})),
|
||||
build: vi.fn().mockImplementation(function() {
|
||||
return {
|
||||
destinationCalendar: [],
|
||||
team: {}, // <- you won't use this result anyway
|
||||
};
|
||||
}),
|
||||
})),
|
||||
},
|
||||
};
|
||||
|
||||
@@ -33,9 +33,11 @@ describe("handleSeats", () => {
|
||||
|
||||
describe("Correct parameters being passed into handleSeats from handleNewBooking", () => {
|
||||
vi.mock("./handleSeats");
|
||||
|
||||
test("On new booking handleSeats is not called", async () => {
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
const spy = vi.spyOn(handleSeatsModule, "default");
|
||||
spy.mockClear();
|
||||
|
||||
const booker = getBooker({
|
||||
email: "[email protected]",
|
||||
@@ -97,6 +99,7 @@ describe("handleSeats", () => {
|
||||
|
||||
test("handleSeats is called when a new attendee is added", async () => {
|
||||
const spy = vi.spyOn(handleSeatsModule, "default");
|
||||
spy.mockClear();
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
|
||||
const booker = getBooker({
|
||||
@@ -242,6 +245,7 @@ describe("handleSeats", () => {
|
||||
|
||||
test("handleSeats is called on rescheduling a seated event", async () => {
|
||||
const spy = vi.spyOn(handleSeatsModule, "default");
|
||||
spy.mockClear();
|
||||
const handleNewBooking = getNewBookingHandler();
|
||||
|
||||
const booker = getBooker({
|
||||
|
||||
@@ -14,9 +14,9 @@ import { handleNoShowFee } from "./handleNoShowFee";
|
||||
vi.mock("@calcom/app-store/payment.services.generated", () => ({
|
||||
PaymentServiceMap: {
|
||||
stripepayment: Promise.resolve({
|
||||
PaymentService: vi.fn().mockImplementation(() => ({
|
||||
PaymentService: vi.fn().mockImplementation(function() { return {
|
||||
chargeCard: vi.fn(),
|
||||
})),
|
||||
}; }),
|
||||
}),
|
||||
},
|
||||
}));
|
||||
@@ -43,9 +43,9 @@ vi.mock("@calcom/features/membership/repositories/MembershipRepository", () => (
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/features/ee/teams/repositories/TeamRepository", () => ({
|
||||
TeamRepository: vi.fn().mockImplementation(() => ({
|
||||
TeamRepository: vi.fn().mockImplementation(function() { return {
|
||||
findParentOrganizationByTeamId: vi.fn(),
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/prisma", () => ({
|
||||
@@ -62,7 +62,7 @@ describe("handleNoShowFee", () => {
|
||||
};
|
||||
|
||||
const paymentServiceModule = await PaymentServiceMap.stripepayment;
|
||||
vi.mocked(paymentServiceModule.PaymentService).mockImplementation(() => mockPaymentService);
|
||||
vi.mocked(paymentServiceModule.PaymentService).mockImplementation(function() { return mockPaymentService; });
|
||||
});
|
||||
|
||||
const mockBooking = {
|
||||
@@ -211,7 +211,7 @@ describe("handleNoShowFee", () => {
|
||||
const mockTeamRepository = {
|
||||
findParentOrganizationByTeamId: vi.fn().mockResolvedValue({ id: 2 }),
|
||||
};
|
||||
vi.mocked(TeamRepository).mockImplementation(() => mockTeamRepository);
|
||||
vi.mocked(TeamRepository).mockImplementation(function() { return mockTeamRepository; });
|
||||
|
||||
const result = await handleNoShowFee({
|
||||
booking: teamBooking,
|
||||
|
||||
@@ -40,8 +40,8 @@ describe("BookingAccessService", () => {
|
||||
checkPermission: vi.fn(),
|
||||
};
|
||||
|
||||
vi.mocked(BookingRepository).mockImplementation(() => mockBookingRepo as any);
|
||||
vi.mocked(UserRepository).mockImplementation(() => mockUserRepo as any);
|
||||
vi.mocked(BookingRepository).mockImplementation(function() { return mockBookingRepo as any; });
|
||||
vi.mocked(UserRepository).mockImplementation(function() { return mockUserRepo as any; });
|
||||
|
||||
service = new BookingAccessService(mockPrismaClient);
|
||||
|
||||
|
||||
@@ -16,13 +16,15 @@ import { AIPhoneServiceProviderType } from "./interfaces/AIPhoneService.interfac
|
||||
vi.stubEnv("RETELL_AI_KEY", "test-api-key");
|
||||
|
||||
vi.mock("./providers/retellAI", () => ({
|
||||
RetellAIPhoneServiceProviderFactory: vi.fn().mockImplementation(() => ({
|
||||
create: vi.fn().mockReturnValue({
|
||||
setupConfiguration: vi.fn(),
|
||||
createPhoneCall: vi.fn(),
|
||||
createPhoneNumber: vi.fn(),
|
||||
}),
|
||||
})),
|
||||
RetellAIPhoneServiceProviderFactory: vi.fn().mockImplementation(function() {
|
||||
return {
|
||||
create: vi.fn().mockReturnValue({
|
||||
setupConfiguration: vi.fn(),
|
||||
createPhoneCall: vi.fn(),
|
||||
createPhoneNumber: vi.fn(),
|
||||
}),
|
||||
};
|
||||
}),
|
||||
}));
|
||||
|
||||
describe("AIPhoneServiceRegistry", () => {
|
||||
|
||||
+45
-41
@@ -19,50 +19,54 @@ vi.mock("@calcom/lib/logger", () => ({
|
||||
}));
|
||||
|
||||
vi.mock("./RetellSDKClient", () => ({
|
||||
RetellSDKClient: vi.fn().mockImplementation((logger) => ({
|
||||
logger,
|
||||
createLLM: vi.fn(),
|
||||
getLLM: vi.fn(),
|
||||
updateLLM: vi.fn(),
|
||||
deleteLLM: vi.fn(),
|
||||
createOutboundAgent: vi.fn(),
|
||||
getAgent: vi.fn(),
|
||||
updateAgent: vi.fn(),
|
||||
deleteAgent: vi.fn(),
|
||||
createPhoneNumber: vi.fn(),
|
||||
importPhoneNumber: vi.fn(),
|
||||
deletePhoneNumber: vi.fn(),
|
||||
getPhoneNumber: vi.fn(),
|
||||
updatePhoneNumber: vi.fn(),
|
||||
createPhoneCall: vi.fn(),
|
||||
})),
|
||||
RetellSDKClient: vi.fn().mockImplementation(function (logger) {
|
||||
return {
|
||||
logger,
|
||||
createLLM: vi.fn(),
|
||||
getLLM: vi.fn(),
|
||||
updateLLM: vi.fn(),
|
||||
deleteLLM: vi.fn(),
|
||||
createOutboundAgent: vi.fn(),
|
||||
getAgent: vi.fn(),
|
||||
updateAgent: vi.fn(),
|
||||
deleteAgent: vi.fn(),
|
||||
createPhoneNumber: vi.fn(),
|
||||
importPhoneNumber: vi.fn(),
|
||||
deletePhoneNumber: vi.fn(),
|
||||
getPhoneNumber: vi.fn(),
|
||||
updatePhoneNumber: vi.fn(),
|
||||
createPhoneCall: vi.fn(),
|
||||
};
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("./RetellAIPhoneServiceProvider", () => ({
|
||||
RetellAIPhoneServiceProvider: vi
|
||||
.fn()
|
||||
.mockImplementation((repository, agentRepository, phoneNumberRepository, transactionManager) => ({
|
||||
repository,
|
||||
agentRepository,
|
||||
phoneNumberRepository,
|
||||
transactionManager,
|
||||
setupConfiguration: vi.fn(),
|
||||
deleteConfiguration: vi.fn(),
|
||||
updateLLMConfiguration: vi.fn(),
|
||||
getLLMDetails: vi.fn(),
|
||||
getAgent: vi.fn(),
|
||||
updateAgent: vi.fn(),
|
||||
createPhoneCall: vi.fn(),
|
||||
createPhoneNumber: vi.fn(),
|
||||
deletePhoneNumber: vi.fn(),
|
||||
getPhoneNumber: vi.fn(),
|
||||
updatePhoneNumber: vi.fn(),
|
||||
importPhoneNumber: vi.fn(),
|
||||
})),
|
||||
.mockImplementation(function (repository, agentRepository, phoneNumberRepository, transactionManager) {
|
||||
return {
|
||||
repository,
|
||||
agentRepository,
|
||||
phoneNumberRepository,
|
||||
transactionManager,
|
||||
setupConfiguration: vi.fn(),
|
||||
deleteConfiguration: vi.fn(),
|
||||
updateLLMConfiguration: vi.fn(),
|
||||
getLLMDetails: vi.fn(),
|
||||
getAgent: vi.fn(),
|
||||
updateAgent: vi.fn(),
|
||||
createPhoneCall: vi.fn(),
|
||||
createPhoneNumber: vi.fn(),
|
||||
deletePhoneNumber: vi.fn(),
|
||||
getPhoneNumber: vi.fn(),
|
||||
updatePhoneNumber: vi.fn(),
|
||||
importPhoneNumber: vi.fn(),
|
||||
};
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("../adapters/PrismaAgentRepositoryAdapter", () => ({
|
||||
PrismaAgentRepositoryAdapter: vi.fn().mockImplementation(() => ({
|
||||
PrismaAgentRepositoryAdapter: vi.fn().mockImplementation(function() { return {
|
||||
canManageTeamResources: vi.fn(),
|
||||
findByIdWithUserAccess: vi.fn(),
|
||||
findByProviderAgentIdWithUserAccess: vi.fn(),
|
||||
@@ -73,11 +77,11 @@ vi.mock("../adapters/PrismaAgentRepositoryAdapter", () => ({
|
||||
findByIdWithCallAccess: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
linkOutboundAgentToWorkflow: vi.fn(),
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
vi.mock("../adapters/PrismaPhoneNumberRepositoryAdapter", () => ({
|
||||
PrismaPhoneNumberRepositoryAdapter: vi.fn().mockImplementation(() => ({
|
||||
PrismaPhoneNumberRepositoryAdapter: vi.fn().mockImplementation(function() { return {
|
||||
findByPhoneNumberAndUserId: vi.fn(),
|
||||
findByPhoneNumberAndTeamId: vi.fn(),
|
||||
findByIdAndUserId: vi.fn(),
|
||||
@@ -86,13 +90,13 @@ vi.mock("../adapters/PrismaPhoneNumberRepositoryAdapter", () => ({
|
||||
deletePhoneNumber: vi.fn(),
|
||||
updateSubscriptionStatus: vi.fn(),
|
||||
updateAgents: vi.fn(),
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
vi.mock("../adapters/PrismaTransactionAdapter", () => ({
|
||||
PrismaTransactionAdapter: vi.fn().mockImplementation(() => ({
|
||||
PrismaTransactionAdapter: vi.fn().mockImplementation(function() { return {
|
||||
executeInTransaction: vi.fn(),
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
describe("RetellAIPhoneServiceProviderFactory", () => {
|
||||
|
||||
@@ -34,10 +34,12 @@ vi.mock("@calcom/features/ee/payments/server/stripe", () => ({
|
||||
|
||||
const mockGetAllCredits = vi.fn();
|
||||
const mockHasAvailableCredits = vi.fn();
|
||||
const mockCreditService = vi.fn().mockImplementation(() => ({
|
||||
getAllCredits: mockGetAllCredits,
|
||||
hasAvailableCredits: mockHasAvailableCredits,
|
||||
}));
|
||||
const mockCreditService = vi.fn().mockImplementation(function() {
|
||||
return {
|
||||
getAllCredits: mockGetAllCredits,
|
||||
hasAvailableCredits: mockHasAvailableCredits,
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("@calcom/features/ee/billing/credit-service", () => ({
|
||||
CreditService: mockCreditService,
|
||||
@@ -849,9 +851,11 @@ describe("RetellAIService", () => {
|
||||
const { CreditService } = await import("@calcom/features/ee/billing/credit-service");
|
||||
|
||||
const mockHasAvailableCredits = vi.fn().mockResolvedValue(true);
|
||||
(CreditService as any).mockImplementation(() => ({
|
||||
hasAvailableCredits: mockHasAvailableCredits,
|
||||
}));
|
||||
(CreditService as any).mockImplementation(function() {
|
||||
return {
|
||||
hasAvailableCredits: mockHasAvailableCredits,
|
||||
};
|
||||
});
|
||||
|
||||
// Mock rate limiting like the working example
|
||||
vi.mocked(checkRateLimitAndThrowError).mockResolvedValueOnce(undefined as any);
|
||||
@@ -931,9 +935,11 @@ describe("RetellAIService", () => {
|
||||
|
||||
// Mock credit service to return false (no credits)
|
||||
const mockHasAvailableCredits = vi.fn().mockResolvedValue(false);
|
||||
(CreditService as any).mockImplementation(() => ({
|
||||
hasAvailableCredits: mockHasAvailableCredits,
|
||||
}));
|
||||
(CreditService as any).mockImplementation(function() {
|
||||
return {
|
||||
hasAvailableCredits: mockHasAvailableCredits,
|
||||
};
|
||||
});
|
||||
|
||||
await expect(
|
||||
service.createTestCall({
|
||||
@@ -952,9 +958,11 @@ describe("RetellAIService", () => {
|
||||
|
||||
// Mock sufficient credits to get past credit check
|
||||
const mockHasAvailableCredits = vi.fn().mockResolvedValue(true);
|
||||
(CreditService as any).mockImplementation(() => ({
|
||||
hasAvailableCredits: mockHasAvailableCredits,
|
||||
}));
|
||||
(CreditService as any).mockImplementation(function() {
|
||||
return {
|
||||
hasAvailableCredits: mockHasAvailableCredits,
|
||||
};
|
||||
});
|
||||
|
||||
(checkRateLimitAndThrowError as any).mockResolvedValue(undefined);
|
||||
|
||||
@@ -974,9 +982,11 @@ describe("RetellAIService", () => {
|
||||
|
||||
// Mock sufficient credits
|
||||
const mockHasAvailableCredits = vi.fn().mockResolvedValue(true);
|
||||
(CreditService as any).mockImplementation(() => ({
|
||||
hasAvailableCredits: mockHasAvailableCredits,
|
||||
}));
|
||||
(CreditService as any).mockImplementation(function() {
|
||||
return {
|
||||
hasAvailableCredits: mockHasAvailableCredits,
|
||||
};
|
||||
});
|
||||
|
||||
(checkRateLimitAndThrowError as any).mockResolvedValue(undefined);
|
||||
mockAgentRepository.findByIdWithCallAccess.mockResolvedValue(null);
|
||||
@@ -998,9 +1008,11 @@ describe("RetellAIService", () => {
|
||||
|
||||
// Mock sufficient credits
|
||||
const mockHasAvailableCredits = vi.fn().mockResolvedValue(true);
|
||||
(CreditService as any).mockImplementation(() => ({
|
||||
hasAvailableCredits: mockHasAvailableCredits,
|
||||
}));
|
||||
(CreditService as any).mockImplementation(function() {
|
||||
return {
|
||||
hasAvailableCredits: mockHasAvailableCredits,
|
||||
};
|
||||
});
|
||||
|
||||
(checkRateLimitAndThrowError as any).mockResolvedValue(undefined);
|
||||
mockAgentRepository.findByIdWithCallAccess.mockResolvedValue({
|
||||
|
||||
@@ -16,30 +16,32 @@ import type {
|
||||
let RetellSDKClient: typeof import("./RetellSDKClient").RetellSDKClient;
|
||||
|
||||
vi.mock("retell-sdk", () => ({
|
||||
Retell: vi.fn().mockImplementation(() => ({
|
||||
llm: {
|
||||
create: vi.fn(),
|
||||
retrieve: vi.fn(),
|
||||
update: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
},
|
||||
agent: {
|
||||
create: vi.fn(),
|
||||
retrieve: vi.fn(),
|
||||
update: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
},
|
||||
phoneNumber: {
|
||||
create: vi.fn(),
|
||||
import: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
retrieve: vi.fn(),
|
||||
update: vi.fn(),
|
||||
},
|
||||
call: {
|
||||
createPhoneCall: vi.fn(),
|
||||
},
|
||||
})),
|
||||
Retell: vi.fn().mockImplementation(function() {
|
||||
return {
|
||||
llm: {
|
||||
create: vi.fn(),
|
||||
retrieve: vi.fn(),
|
||||
update: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
},
|
||||
agent: {
|
||||
create: vi.fn(),
|
||||
retrieve: vi.fn(),
|
||||
update: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
},
|
||||
phoneNumber: {
|
||||
create: vi.fn(),
|
||||
import: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
retrieve: vi.fn(),
|
||||
update: vi.fn(),
|
||||
},
|
||||
call: {
|
||||
createPhoneCall: vi.fn(),
|
||||
},
|
||||
};
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/lib/logger", () => ({
|
||||
@@ -107,7 +109,7 @@ describe("RetellSDKClient", () => {
|
||||
},
|
||||
};
|
||||
|
||||
(Retell as any).mockImplementation(() => mockRetellInstance);
|
||||
(Retell as any).mockImplementation(function() { return mockRetellInstance; });
|
||||
});
|
||||
|
||||
describe("constructor", () => {
|
||||
|
||||
+20
-12
@@ -26,9 +26,11 @@ describe("CallService", () => {
|
||||
const { CreditService } = await import("@calcom/features/ee/billing/credit-service");
|
||||
const { checkRateLimitAndThrowError } = await import("@calcom/lib/checkRateLimitAndThrowError");
|
||||
|
||||
vi.mocked(CreditService).mockImplementation(() => ({
|
||||
hasAvailableCredits: vi.fn().mockResolvedValue(true),
|
||||
}));
|
||||
vi.mocked(CreditService).mockImplementation(function () {
|
||||
return {
|
||||
hasAvailableCredits: vi.fn().mockResolvedValue(true),
|
||||
};
|
||||
});
|
||||
|
||||
vi.mocked(checkRateLimitAndThrowError).mockResolvedValue(undefined);
|
||||
|
||||
@@ -233,9 +235,11 @@ describe("CallService", () => {
|
||||
mocks.mockRetellRepository.createPhoneCall.mockResolvedValue(createMockCall());
|
||||
|
||||
const { CreditService } = await import("@calcom/features/ee/billing/credit-service");
|
||||
vi.mocked(CreditService).mockImplementation(() => ({
|
||||
getAllCredits: vi.fn().mockRejectedValue(new TestError("Credit service unavailable")),
|
||||
}));
|
||||
vi.mocked(CreditService).mockImplementation(function () {
|
||||
return {
|
||||
getAllCredits: vi.fn().mockRejectedValue(new TestError("Credit service unavailable")),
|
||||
};
|
||||
});
|
||||
|
||||
await expect(service.createTestCall(validTestCallData)).rejects.toThrow(
|
||||
"Unable to validate credits. Please try again."
|
||||
@@ -247,9 +251,11 @@ describe("CallService", () => {
|
||||
mocks.mockRetellRepository.createPhoneCall.mockResolvedValue(createMockCall());
|
||||
|
||||
const { CreditService } = await import("@calcom/features/ee/billing/credit-service");
|
||||
vi.mocked(CreditService).mockImplementation(() => ({
|
||||
hasAvailableCredits: vi.fn().mockResolvedValue(false),
|
||||
}));
|
||||
vi.mocked(CreditService).mockImplementation(function () {
|
||||
return {
|
||||
hasAvailableCredits: vi.fn().mockResolvedValue(false),
|
||||
};
|
||||
});
|
||||
|
||||
await expect(service.createTestCall(validTestCallData)).rejects.toThrow(
|
||||
"Insufficient credits to make test call. Please purchase more credits."
|
||||
@@ -261,9 +267,11 @@ describe("CallService", () => {
|
||||
mocks.mockRetellRepository.createPhoneCall.mockResolvedValue(createMockCall());
|
||||
|
||||
const { CreditService } = await import("@calcom/features/ee/billing/credit-service");
|
||||
vi.mocked(CreditService).mockImplementation(() => ({
|
||||
hasAvailableCredits: vi.fn().mockResolvedValue(false),
|
||||
}));
|
||||
vi.mocked(CreditService).mockImplementation(function () {
|
||||
return {
|
||||
hasAvailableCredits: vi.fn().mockResolvedValue(false),
|
||||
};
|
||||
});
|
||||
|
||||
await expect(service.createTestCall(validTestCallData)).rejects.toThrow(
|
||||
"Insufficient credits to make test call. Please purchase more credits."
|
||||
|
||||
+5
-3
@@ -94,9 +94,11 @@ describe("GoogleCalendarSubscriptionAdapter", () => {
|
||||
};
|
||||
|
||||
const { CalendarAuth } = await import("../__mocks__/CalendarAuth");
|
||||
vi.mocked(CalendarAuth).mockImplementation(() => ({
|
||||
getClient: vi.fn().mockResolvedValue(mockClient),
|
||||
}));
|
||||
vi.mocked(CalendarAuth).mockImplementation(function() {
|
||||
return {
|
||||
getClient: vi.fn().mockResolvedValue(mockClient),
|
||||
};
|
||||
});
|
||||
|
||||
adapter = new GoogleCalendarSubscriptionAdapter();
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -27,9 +27,9 @@ vi.mock("@calcom/features/credentials/repositories/CredentialRepository", () =>
|
||||
|
||||
vi.mock("@calcom/features/users/repositories/UserRepository", () => {
|
||||
return {
|
||||
UserRepository: vi.fn().mockImplementation(() => ({
|
||||
UserRepository: vi.fn().mockImplementation(function() { return {
|
||||
getUserOrganizationAndTeams: vi.fn(),
|
||||
})),
|
||||
}; }),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -123,7 +123,7 @@ describe("CredentialAccessService", () => {
|
||||
}),
|
||||
};
|
||||
|
||||
vi.mocked(UserRepository).mockImplementation(() => mockUserRepo as any);
|
||||
vi.mocked(UserRepository).mockImplementation(function() { return mockUserRepo as any; });
|
||||
|
||||
const service = new CredentialAccessService();
|
||||
await expect(
|
||||
@@ -168,7 +168,7 @@ describe("CredentialAccessService", () => {
|
||||
}),
|
||||
};
|
||||
|
||||
vi.mocked(UserRepository).mockImplementation(() => mockUserRepo as any);
|
||||
vi.mocked(UserRepository).mockImplementation(function() { return mockUserRepo as any; });
|
||||
|
||||
const service = new CredentialAccessService();
|
||||
await expect(
|
||||
@@ -207,7 +207,7 @@ describe("CredentialAccessService", () => {
|
||||
}),
|
||||
};
|
||||
|
||||
vi.mocked(UserRepository).mockImplementation(() => mockUserRepo as any);
|
||||
vi.mocked(UserRepository).mockImplementation(function() { return mockUserRepo as any; });
|
||||
|
||||
const service = new CredentialAccessService();
|
||||
await expect(
|
||||
@@ -273,7 +273,7 @@ describe("CredentialAccessService", () => {
|
||||
}),
|
||||
};
|
||||
|
||||
vi.mocked(UserRepository).mockImplementation(() => mockUserRepo as any);
|
||||
vi.mocked(UserRepository).mockImplementation(function() { return mockUserRepo as any; });
|
||||
|
||||
const service = new CredentialAccessService();
|
||||
const error = await service
|
||||
|
||||
@@ -34,7 +34,7 @@ describe("autoLock", () => {
|
||||
beforeEach(() => {
|
||||
// Reset all mocks before each test
|
||||
vi.clearAllMocks();
|
||||
vi.mocked(RedisService).mockImplementation(() => mockRedis as any);
|
||||
vi.mocked(RedisService).mockImplementation(function() { return mockRedis as any; });
|
||||
|
||||
// Mock environment variables
|
||||
process.env.UPSTASH_REDIS_REST_TOKEN = "test-token";
|
||||
|
||||
@@ -130,7 +130,7 @@ describe("CreditService", () => {
|
||||
let creditService: CreditService;
|
||||
|
||||
beforeEach(async () => {
|
||||
vi.restoreAllMocks();
|
||||
vi.resetAllMocks();
|
||||
|
||||
mockStripe.prices.retrieve.mockResolvedValue({ id: "price_123", unit_amount: 1000 });
|
||||
mockStripe.customers.create.mockResolvedValue({ id: "cus_123" });
|
||||
@@ -469,7 +469,7 @@ describe("CreditService", () => {
|
||||
members: [{ accepted: true }],
|
||||
}),
|
||||
};
|
||||
vi.mocked(TeamRepository).mockImplementation(() => mockTeamRepo as unknown as TeamRepository);
|
||||
vi.mocked(TeamRepository).mockImplementation(function() { return mockTeamRepo as unknown as TeamRepository; });
|
||||
|
||||
const mockTeamBillingService = {
|
||||
getSubscriptionStatus: vi.fn().mockResolvedValue(SubscriptionStatus.TRIALING),
|
||||
@@ -493,7 +493,7 @@ describe("CreditService", () => {
|
||||
members: [{ accepted: true }, { accepted: true }, { accepted: true }],
|
||||
}),
|
||||
};
|
||||
vi.mocked(TeamRepository).mockImplementation(() => mockTeamRepo as unknown as TeamRepository);
|
||||
vi.mocked(TeamRepository).mockImplementation(function() { return mockTeamRepo as unknown as TeamRepository; });
|
||||
|
||||
const mockTeamBillingService = {
|
||||
getSubscriptionStatus: vi.fn().mockResolvedValue(SubscriptionStatus.ACTIVE),
|
||||
@@ -524,7 +524,7 @@ describe("CreditService", () => {
|
||||
members: [{ accepted: true }, { accepted: true }],
|
||||
}),
|
||||
};
|
||||
vi.mocked(TeamRepository).mockImplementation(() => mockTeamRepo as unknown as TeamRepository);
|
||||
vi.mocked(TeamRepository).mockImplementation(function() { return mockTeamRepo as unknown as TeamRepository; });
|
||||
|
||||
const mockTeamBillingService = {
|
||||
getSubscriptionStatus: vi.fn().mockResolvedValue(SubscriptionStatus.ACTIVE),
|
||||
@@ -549,7 +549,7 @@ describe("CreditService", () => {
|
||||
members: [{ accepted: true }, { accepted: true }, { accepted: true }],
|
||||
}),
|
||||
};
|
||||
vi.mocked(TeamRepository).mockImplementation(() => mockTeamRepo as unknown as TeamRepository);
|
||||
vi.mocked(TeamRepository).mockImplementation(function() { return mockTeamRepo as unknown as TeamRepository; });
|
||||
|
||||
const mockTeamBillingService = {
|
||||
getSubscriptionStatus: vi.fn().mockResolvedValue(SubscriptionStatus.ACTIVE),
|
||||
@@ -841,9 +841,14 @@ describe("CreditService", () => {
|
||||
{ teamId: 2 },
|
||||
]);
|
||||
|
||||
vi.spyOn(TeamRepository.prototype, "findTeamsForCreditCheck").mockResolvedValue([
|
||||
{ id: 2, isOrganization: false, parentId: null, parent: null },
|
||||
]);
|
||||
const mockTeamRepoInstance = {
|
||||
findTeamsForCreditCheck: vi.fn().mockResolvedValue([
|
||||
{ id: 2, isOrganization: false, parentId: null, parent: null },
|
||||
]),
|
||||
};
|
||||
vi.mocked(TeamRepository).mockImplementation(function () {
|
||||
return mockTeamRepoInstance as unknown as TeamRepository;
|
||||
});
|
||||
|
||||
vi.mocked(CreditsRepository.findCreditBalance).mockResolvedValue({
|
||||
id: "2",
|
||||
@@ -876,10 +881,15 @@ describe("CreditService", () => {
|
||||
{ teamId: 2 },
|
||||
]);
|
||||
|
||||
vi.spyOn(TeamRepository.prototype, "findTeamsForCreditCheck").mockResolvedValue([
|
||||
{ id: 1, isOrganization: true, parentId: null, parent: null },
|
||||
{ id: 2, isOrganization: false, parentId: null, parent: null },
|
||||
]);
|
||||
const mockTeamRepoInstance = {
|
||||
findTeamsForCreditCheck: vi.fn().mockResolvedValue([
|
||||
{ id: 1, isOrganization: true, parentId: null, parent: null },
|
||||
{ id: 2, isOrganization: false, parentId: null, parent: null },
|
||||
]),
|
||||
};
|
||||
vi.mocked(TeamRepository).mockImplementation(function () {
|
||||
return mockTeamRepoInstance as unknown as TeamRepository;
|
||||
});
|
||||
|
||||
vi.mocked(CreditsRepository.findCreditBalance).mockResolvedValue({
|
||||
id: "1",
|
||||
@@ -910,10 +920,15 @@ describe("CreditService", () => {
|
||||
{ teamId: 2 },
|
||||
]);
|
||||
|
||||
vi.spyOn(TeamRepository.prototype, "findTeamsForCreditCheck").mockResolvedValue([
|
||||
{ id: 1, isOrganization: true, parentId: null, parent: null },
|
||||
{ id: 2, isOrganization: false, parentId: null, parent: null },
|
||||
]);
|
||||
const mockTeamRepoInstance = {
|
||||
findTeamsForCreditCheck: vi.fn().mockResolvedValue([
|
||||
{ id: 1, isOrganization: true, parentId: null, parent: null },
|
||||
{ id: 2, isOrganization: false, parentId: null, parent: null },
|
||||
]),
|
||||
};
|
||||
vi.mocked(TeamRepository).mockImplementation(function () {
|
||||
return mockTeamRepoInstance as unknown as TeamRepository;
|
||||
});
|
||||
|
||||
vi.mocked(CreditsRepository.findCreditBalance).mockResolvedValue({
|
||||
id: "1",
|
||||
@@ -944,9 +959,14 @@ describe("CreditService", () => {
|
||||
{ teamId: 2 },
|
||||
]);
|
||||
|
||||
vi.spyOn(TeamRepository.prototype, "findTeamsForCreditCheck").mockResolvedValue([
|
||||
{ id: 2, isOrganization: false, parentId: null, parent: null },
|
||||
]);
|
||||
const mockTeamRepoInstance = {
|
||||
findTeamsForCreditCheck: vi.fn().mockResolvedValue([
|
||||
{ id: 2, isOrganization: false, parentId: null, parent: null },
|
||||
]),
|
||||
};
|
||||
vi.mocked(TeamRepository).mockImplementation(function () {
|
||||
return mockTeamRepoInstance as unknown as TeamRepository;
|
||||
});
|
||||
|
||||
vi.mocked(CreditsRepository.findCreditBalance).mockResolvedValue({
|
||||
id: "2",
|
||||
|
||||
@@ -48,9 +48,9 @@ vi.mock("./removeUserFromOrg", () => ({
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/features/users/repositories/UserRepository", () => ({
|
||||
UserRepository: vi.fn().mockImplementation(() => ({
|
||||
UserRepository: vi.fn().mockImplementation(function() { return {
|
||||
isAMemberOfOrganization: vi.fn().mockResolvedValue(false),
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
async function createMockOrganization({ id, name, slug }: { id: number; name: string; slug: string }) {
|
||||
@@ -191,12 +191,11 @@ describe("handleUserEvents", () => {
|
||||
};
|
||||
|
||||
const { UserRepository } = await import("@calcom/features/users/repositories/UserRepository");
|
||||
vi.mocked(UserRepository).mockImplementation(
|
||||
() =>
|
||||
({
|
||||
isAMemberOfOrganization: vi.fn().mockResolvedValue(true),
|
||||
} as unknown as InstanceType<typeof UserRepository>)
|
||||
);
|
||||
vi.mocked(UserRepository).mockImplementation(function () {
|
||||
return {
|
||||
isAMemberOfOrganization: vi.fn().mockResolvedValue(true),
|
||||
} as unknown as InstanceType<typeof UserRepository>;
|
||||
});
|
||||
|
||||
await expect(handleUserEvents(event, organizationId)).resolves.not.toThrow();
|
||||
});
|
||||
@@ -292,12 +291,11 @@ describe("handleUserEvents", () => {
|
||||
};
|
||||
|
||||
const { UserRepository } = await import("@calcom/features/users/repositories/UserRepository");
|
||||
vi.mocked(UserRepository).mockImplementation(
|
||||
() =>
|
||||
({
|
||||
isAMemberOfOrganization: vi.fn().mockResolvedValue(false),
|
||||
} as unknown as InstanceType<typeof UserRepository>)
|
||||
);
|
||||
vi.mocked(UserRepository).mockImplementation(function () {
|
||||
return {
|
||||
isAMemberOfOrganization: vi.fn().mockResolvedValue(false),
|
||||
} as unknown as InstanceType<typeof UserRepository>;
|
||||
});
|
||||
|
||||
const inviteExistingUserToOrg = (await import("./users/inviteExistingUserToOrg")).default;
|
||||
const sendExistingUserTeamInviteEmails = (
|
||||
@@ -377,12 +375,11 @@ describe("handleUserEvents", () => {
|
||||
};
|
||||
|
||||
const { UserRepository } = await import("@calcom/features/users/repositories/UserRepository");
|
||||
vi.mocked(UserRepository).mockImplementation(
|
||||
() =>
|
||||
({
|
||||
isAMemberOfOrganization: vi.fn().mockResolvedValue(true),
|
||||
} as unknown as InstanceType<typeof UserRepository>)
|
||||
);
|
||||
vi.mocked(UserRepository).mockImplementation(function () {
|
||||
return {
|
||||
isAMemberOfOrganization: vi.fn().mockResolvedValue(true),
|
||||
} as unknown as InstanceType<typeof UserRepository>;
|
||||
});
|
||||
|
||||
const { assignValueToUserInOrgBulk } = await import("./assignValueToUser");
|
||||
|
||||
|
||||
@@ -179,7 +179,10 @@ type ConferenceResult = {
|
||||
const mockEventManagerReschedule = async (config?: MockEventManagerConfig) => {
|
||||
const EventManager = (await import("@calcom/features/bookings/lib/EventManager")).default;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const spy = vi.spyOn(EventManager.prototype as any, "reschedule");
|
||||
const existingSpy = vi.spyOn(EventManager.prototype as any, "reschedule");
|
||||
// Clear any existing mock calls from previous tests
|
||||
existingSpy.mockClear();
|
||||
const spy = existingSpy;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
spy.mockImplementation(async (event: any) => {
|
||||
|
||||
@@ -64,6 +64,8 @@ describe("roundRobinReassignment test", () => {
|
||||
const EventManager = (await import("@calcom/features/bookings/lib/EventManager")).default;
|
||||
|
||||
const eventManagerSpy = vi.spyOn(EventManager.prototype as any, "reschedule");
|
||||
// Clear any existing mock calls from previous tests
|
||||
eventManagerSpy.mockClear();
|
||||
eventManagerSpy.mockResolvedValue({ referencesToCreate: [] });
|
||||
|
||||
const users = testUsers;
|
||||
@@ -197,6 +199,8 @@ describe("roundRobinReassignment test", () => {
|
||||
const EventManager = (await import("@calcom/features/bookings/lib/EventManager")).default;
|
||||
|
||||
const eventManagerSpy = vi.spyOn(EventManager.prototype as any, "reschedule");
|
||||
// Clear any existing mock calls from previous tests
|
||||
eventManagerSpy.mockClear();
|
||||
|
||||
const users = testUsers;
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ const mockTeamRepo = {
|
||||
throw new Error(`Team with id ${id} not found`);
|
||||
}),
|
||||
};
|
||||
vi.mocked(TeamRepository).mockImplementation(() => mockTeamRepo);
|
||||
vi.mocked(TeamRepository).mockImplementation(function() { return mockTeamRepo; });
|
||||
|
||||
vi.mocked(deleteDomain).mockImplementation(async (slug) => {
|
||||
database.domains.delete(slug);
|
||||
|
||||
@@ -61,7 +61,7 @@ describe("TeamService", () => {
|
||||
const mockTeamRepo = {
|
||||
deleteById: vi.fn().mockResolvedValue(mockDeletedTeam),
|
||||
} as Pick<TeamRepository, "deleteById">;
|
||||
vi.mocked(TeamRepository).mockImplementation(() => mockTeamRepo);
|
||||
vi.mocked(TeamRepository).mockImplementation(function() { return mockTeamRepo; });
|
||||
|
||||
const result = await TeamService.delete({ id: 1 });
|
||||
|
||||
|
||||
@@ -19,9 +19,9 @@ vi.mock("@calcom/features/profile/lib/hideBranding", () => ({
|
||||
|
||||
const mockWorkflowReminderCreate = vi.fn();
|
||||
vi.mock("@calcom/features/ee/workflows/repositories/WorkflowReminderRepository", () => ({
|
||||
WorkflowReminderRepository: vi.fn().mockImplementation(() => ({
|
||||
WorkflowReminderRepository: vi.fn().mockImplementation(function() { return {
|
||||
create: mockWorkflowReminderCreate,
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/prisma", () => ({
|
||||
|
||||
@@ -18,10 +18,10 @@ vi.mock("../reminders/providers/twilioProvider", () => ({
|
||||
|
||||
const mockChargeCredits = vi.fn().mockResolvedValue({ teamId: 1 });
|
||||
vi.mock("@calcom/features/ee/billing/credit-service", () => ({
|
||||
CreditService: vi.fn().mockImplementation(() => ({
|
||||
CreditService: vi.fn().mockImplementation(function() { return {
|
||||
chargeCredits: mockChargeCredits,
|
||||
calculateCreditsFromPrice: vi.fn().mockReturnValue(1),
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
const mockFindFirst = vi.fn();
|
||||
|
||||
@@ -14,7 +14,7 @@ vi.mock("@calcom/prisma", () => {
|
||||
return {
|
||||
__esModule: true,
|
||||
default: mockPrisma,
|
||||
PrismaClient: vi.fn(() => mockPrisma),
|
||||
PrismaClient: vi.fn().mockImplementation(function() { return mockPrisma; }),
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -35,8 +35,8 @@ describe("getEventTypePermissions", () => {
|
||||
getResourcePermissions: vi.fn(),
|
||||
};
|
||||
|
||||
vi.mocked(FeaturesRepository).mockImplementation(() => mockFeaturesRepository as any);
|
||||
vi.mocked(PermissionCheckService).mockImplementation(() => mockPermissionCheckService as any);
|
||||
vi.mocked(FeaturesRepository).mockImplementation(function() { return mockFeaturesRepository as any; });
|
||||
vi.mocked(PermissionCheckService).mockImplementation(function() { return mockPermissionCheckService as any; });
|
||||
|
||||
prisma.membership.findFirst = vi.fn();
|
||||
prisma.team.findUnique = vi.fn();
|
||||
@@ -546,8 +546,8 @@ describe("getEventTypePermissions", () => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
// Re-initialize mocks after clearing
|
||||
vi.mocked(FeaturesRepository).mockImplementation(() => mockFeaturesRepository as any);
|
||||
vi.mocked(PermissionCheckService).mockImplementation(() => mockPermissionCheckService as any);
|
||||
vi.mocked(FeaturesRepository).mockImplementation(function() { return mockFeaturesRepository as any; });
|
||||
vi.mocked(PermissionCheckService).mockImplementation(function() { return mockPermissionCheckService as any; });
|
||||
prisma.membership.findFirst = vi.fn();
|
||||
prisma.team.findUnique = vi.fn();
|
||||
|
||||
|
||||
@@ -42,9 +42,9 @@ describe("getResourcePermissions", () => {
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
vi.mocked(FeaturesRepository).mockImplementation(() => mockFeaturesRepository as any);
|
||||
vi.mocked(FeaturesRepository).mockImplementation(function() { return mockFeaturesRepository as any; });
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
vi.mocked(PermissionCheckService).mockImplementation(() => mockPermissionCheckService as any);
|
||||
vi.mocked(PermissionCheckService).mockImplementation(function() { return mockPermissionCheckService as any; });
|
||||
});
|
||||
|
||||
describe("when PBAC is disabled", () => {
|
||||
|
||||
@@ -26,9 +26,9 @@ vi.mock("@calcom/lib/checkRateLimitAndThrowError");
|
||||
vi.mock("@calcom/features/routing-forms/repositories/PrismaRoutingFormRepository");
|
||||
vi.mock("@calcom/features/users/repositories/UserRepository", () => {
|
||||
return {
|
||||
UserRepository: vi.fn().mockImplementation(() => ({
|
||||
UserRepository: vi.fn().mockImplementation(function() { return {
|
||||
enrichUserWithItsProfile: vi.fn(),
|
||||
})),
|
||||
}; }),
|
||||
};
|
||||
});
|
||||
vi.mock("@calcom/features/ee/organizations/lib/orgDomains");
|
||||
@@ -89,13 +89,12 @@ describe("getRoutedUrl", () => {
|
||||
const mockEnrichUserWithItsProfile = vi.fn().mockImplementation(async ({ user }) => user);
|
||||
const mockUserRepository = vi.mocked(UserRepository);
|
||||
if (mockUserRepository && typeof mockUserRepository.mockImplementation === "function") {
|
||||
mockUserRepository.mockImplementation(
|
||||
() =>
|
||||
({
|
||||
enrichUserWithItsProfile: mockEnrichUserWithItsProfile,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} as any)
|
||||
);
|
||||
mockUserRepository.mockImplementation(function () {
|
||||
return {
|
||||
enrichUserWithItsProfile: mockEnrichUserWithItsProfile,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} as any;
|
||||
});
|
||||
}
|
||||
vi.mocked(isAuthorizedToViewFormOnOrgDomain).mockReturnValue(true);
|
||||
vi.mocked(getSerializableForm).mockResolvedValue(mockSerializableForm as never);
|
||||
|
||||
@@ -119,10 +119,10 @@ const mockResponse: Record<
|
||||
describe("handleResponse", () => {
|
||||
beforeEach(() => {
|
||||
vi.resetAllMocks();
|
||||
vi.mocked(RoutingFormResponseRepository).mockImplementation(
|
||||
vi.mocked(RoutingFormResponseRepository).mockImplementation(function () {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
() => mockRoutingFormResponseRepository as any
|
||||
);
|
||||
return mockRoutingFormResponseRepository as any;
|
||||
});
|
||||
});
|
||||
|
||||
it("should throw an Error for missing required fields", async () => {
|
||||
|
||||
@@ -19,9 +19,11 @@ vi.mock("@calcom/features/redis/RedisService", () => {
|
||||
});
|
||||
|
||||
vi.mock("@calcom/features/flags/features.repository", () => ({
|
||||
FeaturesRepository: vi.fn().mockImplementation(() => ({
|
||||
checkIfFeatureIsEnabledGlobally: vi.fn().mockResolvedValue(false),
|
||||
})),
|
||||
FeaturesRepository: vi.fn(function () {
|
||||
return {
|
||||
checkIfFeatureIsEnabledGlobally: vi.fn().mockResolvedValue(false),
|
||||
};
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.spyOn(CalcomEmails, "sendOrganizationAdminNoSlotsNotification");
|
||||
|
||||
@@ -6,9 +6,9 @@ vi.mock("@calcom/emails/workflow-email-service", () => ({
|
||||
|
||||
const mockGetBookingForCalEventBuilderFromUid = vi.fn();
|
||||
vi.mock("@calcom/features/bookings/repositories/BookingRepository", () => ({
|
||||
BookingRepository: vi.fn().mockImplementation(() => ({
|
||||
BookingRepository: vi.fn().mockImplementation(function() { return {
|
||||
getBookingForCalEventBuilderFromUid: mockGetBookingForCalEventBuilderFromUid,
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/features/bookings/repositories/BookingSeatRepository", () => ({
|
||||
@@ -17,9 +17,9 @@ vi.mock("@calcom/features/bookings/repositories/BookingSeatRepository", () => ({
|
||||
|
||||
const mockHandleSendEmailWorkflowTask = vi.fn();
|
||||
vi.mock("@calcom/features/ee/workflows/lib/service/EmailWorkflowService", () => ({
|
||||
EmailWorkflowService: vi.fn().mockImplementation(() => ({
|
||||
EmailWorkflowService: vi.fn().mockImplementation(function() { return {
|
||||
handleSendEmailWorkflowTask: mockHandleSendEmailWorkflowTask,
|
||||
})),
|
||||
}; }),
|
||||
}));
|
||||
|
||||
vi.mock("@calcom/features/ee/workflows/repositories/WorkflowReminderRepository", () => ({
|
||||
|
||||
@@ -27,7 +27,9 @@ const mockUserRepository = {
|
||||
|
||||
vi.mock("@calcom/features/users/repositories/UserRepository", () => {
|
||||
return {
|
||||
UserRepository: vi.fn().mockImplementation(() => mockUserRepository),
|
||||
UserRepository: vi.fn(function () {
|
||||
return mockUserRepository;
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user