Files
calendar/packages/features/auth/__mocks__/getServerSession.mocks.ts
T
98b6d63164 refactor: apply biome formatting to packages/features (#27844)
* refactor: apply biome formatting to packages/features (batch 1 - small subdirs)

Format small subdirectories in packages/features: di, flags, holidays, oauth,
settings, users, assignment-reason, selectedCalendar, hashedLink, host, form,
form-builder, availability, data-table, pbac, schedules, troubleshooter,
eventtypes, calendar-subscription, and root-level files.

Also includes straggler apps/web BookEventForm.tsx.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: apply biome formatting to packages/features (batch 2 - medium subdirs)

Format medium subdirectories in packages/features: auth, credentials,
calendars, routing-forms, routing-trace, attributes, watchlist, calAIPhone,
tasker, and webhooks.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: apply biome formatting to packages/features (batch 3 - bookings + insights)

Format bookings and insights subdirectories in packages/features.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: apply biome formatting to packages/features (batch 4 - ee)

Format packages/features/ee subdirectory covering billing, workflows,
organizations, teams, managed-event-types, round-robin, dsync,
integration-attribute-sync, and payments.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: apply biome formatting to packages/features (batch 5 - booking-audit part 1)

Format booking-audit di, actions, common, dto, repository, and types
subdirectories in packages/features/booking-audit.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: apply biome formatting to packages/features (batch 6 - booking-audit part 2)

Format booking-audit service subdirectory in packages/features/booking-audit.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-11 15:47:14 +01:00

160 lines
3.5 KiB
TypeScript

import type { Mock } from "vitest";
import { vi } from "vitest";
import { mockDeep, mockReset, type DeepMockProxy } from "vitest-mock-extended";
import type { PrismaClient } from "@calcom/prisma";
import type { User } from "@calcom/prisma/client";
// Types
type LoggerInstance = {
warn: Mock;
error: Mock;
debug: Mock;
};
type LoggerMock = {
default: {
getSubLogger: () => LoggerInstance;
};
};
// JWT token structure used by NextAuth
interface MockToken {
sub: string;
email: string;
name: string;
exp: number;
belongsToActiveTeam: boolean;
org: null;
orgAwareUsername: string | null;
profileId: number | null;
upId: string;
impersonatedBy?: { id: number };
}
// Prisma mock instance
const prismaMock: DeepMockProxy<PrismaClient> = mockDeep<PrismaClient>();
function resetPrismaMock(): void {
mockReset(prismaMock);
}
function createLoggerMock(): LoggerMock {
const loggerInstance: LoggerInstance = {
warn: vi.fn(),
error: vi.fn(),
debug: vi.fn(),
};
return {
default: {
getSubLogger: (): LoggerInstance => loggerInstance,
},
};
}
function createPrismaMock(): { default: DeepMockProxy<PrismaClient> } {
return { default: prismaMock };
}
function createLicenseKeyMock(): {
LicenseKeySingleton: { getInstance: Mock };
} {
return {
LicenseKeySingleton: {
getInstance: vi.fn().mockResolvedValue({
checkLicense: vi.fn().mockResolvedValue(false),
}),
},
};
}
function createDeploymentRepositoryMock(): {
DeploymentRepository: new (_prisma: PrismaClient) => object;
} {
return {
DeploymentRepository: class MockDeploymentRepository {},
};
}
function createUserRepositoryMock(): {
UserRepository: new (
_prisma: PrismaClient
) => {
enrichUserWithTheProfile: (params: { user: User }) => Promise<User & { profile: null }>;
};
} {
return {
UserRepository: class MockUserRepository {
enrichUserWithTheProfile({ user }: { user: User }): Promise<User & { profile: null }> {
return Promise.resolve({
...user,
profile: null,
});
}
},
};
}
function createAvatarUrlMock(): { getUserAvatarUrl: Mock } {
return {
getUserAvatarUrl: vi.fn().mockReturnValue("https://example.com/avatar.png"),
};
}
function createSafeStringifyMock(): { safeStringify: Mock } {
return {
safeStringify: vi.fn().mockReturnValue("{}"),
};
}
function createGetTokenMock(): { getToken: Mock } {
return { getToken: vi.fn() };
}
// Creates a mock User with only the fields used by getServerSession
function createMockUser(overrides: Partial<User> = {}): User {
return {
id: 5,
email: "user@example.com",
name: "Test User",
username: "testuser",
emailVerified: new Date(),
completedOnboarding: true,
role: "USER",
avatarUrl: null,
locale: "en",
...overrides,
} as User;
}
function createMockToken(overrides: Partial<MockToken> = {}): MockToken {
return {
sub: "5",
email: "user@example.com",
name: "Test User",
exp: Math.floor(Date.now() / 1000) + 3600,
belongsToActiveTeam: false,
org: null,
orgAwareUsername: null,
profileId: null,
upId: "usr-5",
...overrides,
};
}
export type { MockToken };
export {
prismaMock,
resetPrismaMock,
createLoggerMock,
createPrismaMock,
createLicenseKeyMock,
createDeploymentRepositoryMock,
createUserRepositoryMock,
createAvatarUrlMock,
createSafeStringifyMock,
createGetTokenMock,
createMockUser,
createMockToken,
};