Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
- uses: ./.github/actions/yarn-install
- uses: ./.github/actions/cache-db
- name: Run Tests
run: yarn test -- --integrationTestsOnly
run: VITEST_MODE=integration yarn test
# TODO: Generate test results so we can upload them
# - name: Upload Test Results
# if: ${{ always() }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ jobs:
- uses: ./.github/actions/yarn-install
- run: yarn test -- --no-isolate
# We could add different timezones here that we need to run our tests in
- run: TZ=America/Los_Angeles yarn test -- --timeZoneDependentTestsOnly --no-isolate
- run: TZ=America/Los_Angeles VITEST_MODE=timezone yarn test -- --no-isolate
4 changes: 2 additions & 2 deletions apps/api/v1/lib/helpers/verifyApiKey.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ describe("Verify API key - Unit Tests", () => {
verifyKeyByHashedKey: vi.fn(),
} as unknown as ApiKeyService;

vi.mocked(ApiKeyService).mockImplementation(() => mockApiKeyService);
vi.mocked(PrismaApiKeyRepository).mockImplementation(() => ({} as unknown as PrismaApiKeyRepository));
vi.mocked(ApiKeyService).mockImplementation(function() { return mockApiKeyService; });
vi.mocked(PrismaApiKeyRepository).mockImplementation(function() { return {} as unknown as PrismaApiKeyRepository; });

vi.mocked(isAdminGuard).mockReset();
vi.mocked(isLockedOrBlocked).mockReset();
Expand Down
44 changes: 23 additions & 21 deletions apps/api/v1/test/lib/bookings/_post.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ vi.mock("@calcom/features/webhooks/lib/sendOrSchedulePayload", () => ({

const mockFindOriginalRescheduledBooking = vi.fn();
vi.mock("@calcom/features/bookings/repositories/BookingRepository", () => ({
BookingRepository: vi.fn().mockImplementation(() => ({
BookingRepository: vi.fn().mockImplementation(function() { return {
findOriginalRescheduledBooking: mockFindOriginalRescheduledBooking,
})),
}; }),
}));

vi.mock("@calcom/features/watchlist/operations/check-if-users-are-blocked.controller", () => ({
Expand All @@ -87,23 +87,25 @@ vi.mock("@calcom/features/di/containers/QualifiedHosts", () => ({
}));

vi.mock("@calcom/features/bookings/lib/EventManager", () => ({
default: vi.fn().mockImplementation(() => ({
reschedule: vi.fn().mockResolvedValue({
results: [],
referencesToCreate: [],
}),
create: vi.fn().mockResolvedValue({
results: [],
referencesToCreate: [],
}),
update: vi.fn().mockResolvedValue({
results: [],
referencesToCreate: [],
}),
createAllCalendarEvents: vi.fn().mockResolvedValue([]),
updateAllCalendarEvents: vi.fn().mockResolvedValue([]),
deleteEventsAndMeetings: vi.fn().mockResolvedValue([]),
})),
default: vi.fn().mockImplementation(function() {
return {
reschedule: vi.fn().mockResolvedValue({
results: [],
referencesToCreate: [],
}),
create: vi.fn().mockResolvedValue({
results: [],
referencesToCreate: [],
}),
update: vi.fn().mockResolvedValue({
results: [],
referencesToCreate: [],
}),
createAllCalendarEvents: vi.fn().mockResolvedValue([]),
updateAllCalendarEvents: vi.fn().mockResolvedValue([]),
deleteEventsAndMeetings: vi.fn().mockResolvedValue([]),
};
}),
placeholderCreatedEvent: {
results: [],
referencesToCreate: [],
Expand Down Expand Up @@ -146,10 +148,10 @@ vi.mock("@calcom/features/profile/repositories/ProfileRepository", () => ({
},
}));
vi.mock("@calcom/features/flags/features.repository", () => ({
FeaturesRepository: vi.fn().mockImplementation(() => ({
FeaturesRepository: vi.fn().mockImplementation(function() { return {
checkIfFeatureIsEnabledGlobally: vi.fn().mockResolvedValue(false),
checkIfTeamHasFeature: vi.fn().mockResolvedValue(false),
})),
}; }),
}));

vi.mock("@calcom/features/webhooks/lib/getWebhooks", () => ({
Expand Down
4 changes: 2 additions & 2 deletions apps/api/v1/test/lib/users/_post.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ vi.mock("@calcom/features/watchlist/operations/check-if-email-in-watchlist.contr

const mockCreate = vi.fn();
vi.mock("@calcom/features/users/repositories/UserRepository", () => ({
UserRepository: vi.fn().mockImplementation(() => ({
UserRepository: vi.fn().mockImplementation(function() { return {
create: mockCreate,
})),
}; }),
}));

vi.mock("@calcom/lib/auth/hashPassword", () => ({
Expand Down
4 changes: 2 additions & 2 deletions apps/api/v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@
"@nestjs/jwt": "10.2.0",
"@nestjs/passport": "10.0.3",
"@nestjs/platform-express": "10.4.20",
"@nestjs/swagger": "7.3.0",
"@nestjs/swagger": "7.4.2",
"@nestjs/throttler": "6.2.1",
"@sentry/nestjs": "9.46.0",
"@sentry/node": "9.46.0",
"@sentry/profiling-node": "9.46.0",
"@snyk/protect": "latest",
"axios": "1.13.2",
"body-parser": "1.20.2",
"body-parser": "1.20.3",
"bull": "4.15.1",
"class-transformer": "0.5.1",
"class-validator": "0.14.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { handleCreateSelectedCalendars, isSameEmail } from "../route";
const getPrimaryCalendarMock = vi.fn();
vi.mock("@calcom/app-store/googlecalendar/lib/CalendarService", () => {
return {
default: vi.fn().mockImplementation(() => ({
default: vi.fn().mockImplementation(function() { return {
getPrimaryCalendar: getPrimaryCalendarMock,
})),
}; }),
};
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ const mockQueuedFormResponse = {

describe("queuedResponseHandler", () => {
beforeEach(() => {
vi.mocked(RoutingFormResponseRepository).mockImplementation(
() => mockRoutingFormResponseRepository as any
);
vi.mocked(RoutingFormResponseRepository).mockImplementation(function () {
return mockRoutingFormResponseRepository as any;
});
});

it("should process a queued form response", async () => {
Expand Down
11 changes: 7 additions & 4 deletions apps/web/app/api/social/og/image/__tests__/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import { getOGImageVersion } from "@calcom/lib/OgImages";
import { GET } from "../route";

vi.mock("next/og", () => ({
ImageResponse: vi.fn().mockImplementation(() => ({
ImageResponse: vi.fn().mockImplementation(function() { return {
body: new ReadableStream({
start(controller) {
controller.enqueue(new Uint8Array([1, 2, 3, 4]));
controller.close();
},
}),
})),
}; }),
}));

vi.mock("@calcom/lib/OgImages", async (importOriginal) => {
Expand Down Expand Up @@ -102,8 +102,11 @@ describe("GET /api/social/og/image", () => {
});

describe("Server errors (500 Internal Server Error)", () => {
test("returns 500 when font loading fails", async () => {
vi.mocked(global.fetch).mockRejectedValue(new Error("Font loading failed"));
test("returns 500 when ImageResponse throws", async () => {
const { ImageResponse } = await import("next/og");
vi.mocked(ImageResponse).mockImplementation(function () {
throw new Error("ImageResponse failed");
});

const request = createNextRequest(
"http://example.com/api/social/og/image?type=meeting&title=Test&meetingProfileName=John"
Expand Down
12 changes: 6 additions & 6 deletions apps/web/app/api/webhooks/retell-ai/__tests__/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ const mockSendCreditBalanceLimitReachedEmails = vi.fn();
const mockSendCreditBalanceLowWarningEmails = vi.fn();

vi.mock("@calcom/features/ee/billing/credit-service", () => ({
CreditService: vi.fn().mockImplementation(() => ({
CreditService: vi.fn().mockImplementation(function() { return {
hasAvailableCredits: mockHasAvailableCredits,
chargeCredits: mockChargeCredits,
})),
}; }),
}));

vi.mock("@calcom/emails/email-manager", () => ({
Expand All @@ -92,15 +92,15 @@ const mockFindByPhoneNumber = vi.fn();
const mockFindByProviderAgentId = vi.fn();

vi.mock("@calcom/features/calAIPhone/repositories/PrismaPhoneNumberRepository", () => ({
PrismaPhoneNumberRepository: vi.fn().mockImplementation(() => ({
PrismaPhoneNumberRepository: vi.fn().mockImplementation(function() { return {
findByPhoneNumber: mockFindByPhoneNumber,
})),
}; }),
}));

vi.mock("@calcom/features/calAIPhone/repositories/PrismaAgentRepository", () => ({
PrismaAgentRepository: vi.fn().mockImplementation(() => ({
PrismaAgentRepository: vi.fn().mockImplementation(function() { return {
findByProviderAgentId: mockFindByProviderAgentId,
})),
}; }),
}));

vi.mock("next/server", () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ vi.mock("@calcom/lib/hooks/useLocale", () => ({
useLocale: vi.fn(() => ({ t: (key: string) => key })),
}));

vi.mock("@calcom/features/ee/organizations/context/provider", () => ({
useOrgBranding: vi.fn(() => null),
}));

let findTeamMembersMatchingAttributeLogicResponse: {
result: { users: { email: string }[] } | null;
checkedFallback: boolean;
Expand Down
4 changes: 4 additions & 0 deletions apps/web/components/dialog/__tests__/RerouteDialog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ vi.mock("@calcom/lib/hooks/useLocale", () => ({
useLocale: vi.fn(() => ({ t: (key: string) => key })),
}));

vi.mock("@calcom/features/ee/organizations/context/provider", () => ({
useOrgBranding: vi.fn(() => null),
}));

vi.mock("@calcom/web/lib/hooks/useRouterQuery", () => ({
default: vi.fn(() => {
return {
Expand Down
8 changes: 8 additions & 0 deletions apps/web/modules/users/views/users-public-view.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ vi.mock("@calcom/lib/constants", async () => {
return await vi.importActual("@calcom/lib/constants");
});

vi.mock("@calcom/ee/organizations/lib/orgDomains", () => ({
getOrgFullOrigin: vi.fn(),
}));

vi.mock("@calcom/lib/hooks/useRouterQuery", () => ({
useRouterQuery: vi.fn(),
}));

function mockedUserPageComponentProps(props: Partial<React.ComponentProps<typeof UserPage>>) {
return {
themeBasis: "dark",
Expand Down
4 changes: 2 additions & 2 deletions apps/web/test/lib/checkBookingLimits.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { validateIntervalLimitOrder } from "@calcom/lib/intervalLimits/validateI

const mockCountBookingsByEventTypeAndDateRange = vi.fn();
vi.mock("@calcom/features/bookings/repositories/BookingRepository", () => ({
BookingRepository: vi.fn().mockImplementation(() => ({
BookingRepository: vi.fn().mockImplementation(function() { return {
countBookingsByEventTypeAndDateRange: mockCountBookingsByEventTypeAndDateRange,
})),
}; }),
}));

type Mockdata = {
Expand Down
4 changes: 2 additions & 2 deletions apps/web/test/lib/checkDurationLimits.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { validateIntervalLimitOrder } from "@calcom/lib/intervalLimits/validateI

const mockGetTotalBookingDuration = vi.fn();
vi.mock("@calcom/features/bookings/repositories/BookingRepository", () => ({
BookingRepository: vi.fn().mockImplementation(() => ({
BookingRepository: vi.fn().mockImplementation(function() { return {
getTotalBookingDuration: mockGetTotalBookingDuration,
})),
}; }),
}));

type MockData = {
Expand Down
16 changes: 9 additions & 7 deletions apps/web/test/lib/getSchedule/restrictionSchedule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ import { setupAndTeardown } from "./setupAndTeardown";

// Mock the FeaturesRepository to enable restriction-schedule feature
vi.mock("@calcom/features/flags/features.repository", () => ({
FeaturesRepository: vi.fn().mockImplementation(() => ({
checkIfTeamHasFeature: vi.fn().mockResolvedValue(true),
checkIfFeatureIsEnabledGlobally: vi.fn().mockResolvedValue(true),
getAllFeatures: vi.fn().mockResolvedValue([]),
getFeatureFlagMap: vi.fn().mockResolvedValue({}),
checkIfUserHasFeature: vi.fn().mockResolvedValue(true),
})),
FeaturesRepository: vi.fn().mockImplementation(function() {
return {
checkIfTeamHasFeature: vi.fn().mockResolvedValue(true),
checkIfFeatureIsEnabledGlobally: vi.fn().mockResolvedValue(true),
getAllFeatures: vi.fn().mockResolvedValue([]),
getFeatureFlagMap: vi.fn().mockResolvedValue({}),
checkIfUserHasFeature: vi.fn().mockResolvedValue(true),
};
}),
}));

type ScheduleScenario = {
Expand Down
52 changes: 21 additions & 31 deletions apps/web/test/utils/bookingScenario/test.ts
Original file line number Diff line number Diff line change
@@ -1,81 +1,71 @@
import { createOrganization } from "@calcom/web/test/utils/bookingScenario/bookingScenario";

import type { TestFunction } from "vitest";

import { WEBSITE_URL } from "@calcom/lib/constants";
import { test } from "@calcom/web/test/fixtures/fixtures";
import type { Fixtures } from "@calcom/web/test/fixtures/fixtures";

type OrgContext = {
org: {
organization: { id: number | null };
urlOrigin?: string;
} | null;
};

const WEBSITE_PROTOCOL = new URL(WEBSITE_URL).protocol;
const _testWithAndWithoutOrg = (
description: Parameters<typeof testWithAndWithoutOrg>[0],
fn: Parameters<typeof testWithAndWithoutOrg>[1],
timeout: Parameters<typeof testWithAndWithoutOrg>[2],
description: string,
fn: (context: Fixtures & OrgContext) => Promise<void> | void,
timeout: number | undefined,
mode: "only" | "skip" | "run" = "run"
) => {
): void => {
const t = mode === "only" ? test.only : mode === "skip" ? test.skip : test;
t(
`${description} - With org`,
async ({ emails, sms, task, onTestFailed, expect, skip, onTestFinished }) => {
async ({ emails, sms }) => {
const org = await createOrganization({
name: "Test Org",
slug: "testorg",
});

await fn({
task,
onTestFailed,
expect,
emails,
sms,
skip,
org: {
organization: org,
urlOrigin: `${WEBSITE_PROTOCOL}//${org.slug}.cal.local:3000`,
},
onTestFinished,
});
},
timeout
);

t(
`${description}`,
async ({ emails, sms, task, onTestFailed, expect, skip, onTestFinished }) => {
async ({ emails, sms }) => {
await fn({
emails,
sms,
task,
onTestFailed,
expect,
skip,
org: null,
onTestFinished,
});
},
timeout
);
};

type TestFunctionWithOrg = (context: Fixtures & OrgContext) => Promise<void> | void;

export const testWithAndWithoutOrg = (
description: string,
fn: TestFunction<
Fixtures & {
org: {
organization: { id: number | null };
urlOrigin?: string;
} | null;
}
>,
fn: TestFunctionWithOrg,
timeout?: number
) => {
): void => {
_testWithAndWithoutOrg(description, fn, timeout, "run");
};

testWithAndWithoutOrg.only = ((description, fn, timeout) => {
testWithAndWithoutOrg.only = ((description: string, fn: TestFunctionWithOrg, timeout?: number): void => {
_testWithAndWithoutOrg(description, fn, timeout, "only");
}) as typeof _testWithAndWithoutOrg;
}) as typeof testWithAndWithoutOrg;

testWithAndWithoutOrg.skip = ((description, fn, timeout) => {
testWithAndWithoutOrg.skip = ((description: string, fn: TestFunctionWithOrg, timeout?: number): void => {
_testWithAndWithoutOrg(description, fn, timeout, "skip");
}) as typeof _testWithAndWithoutOrg;
}) as typeof testWithAndWithoutOrg;
Loading
Loading