* feat: Cal.diy — community-driven MIT-licensed fork of Cal.com This squashed commit contains all Cal.diy changes applied on top of calcom/cal.com main: - Rebrand Cal.com to Cal.diy across the entire codebase - Remove Enterprise Edition (EE) features, license checks, and AGPL restrictions - Switch license from AGPL-3.0 to MIT - Remove docs/ directory (migrated to Nextra at cal.diy) - Remove dead code: org tests, EE tips, platform nav, premium username, SAML/SSO, etc. - Clean up .env.example for self-hosted Cal.diy - Update Docker image references to calcom/cal.diy - Update README, CONTRIBUTING.md, and issue templates for Cal.diy community fork - Add PR welcome bot for Cal.diy contributors - Fix API v2 breaking changes oasdiff ignore entries - Replace Blacksmith CI runners with default GitHub Actions 3893 files changed, 20789 insertions(+), 411020 deletions(-) Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * refactor: remove org-specific /organizations/:orgId endpoints from API v2 atoms controllers (#1701) Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix: revert Cal.diy Inc to Cal.com, Inc. in license files, copyright notices, and package metadata (#1702) Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * rip out org related comments in api v2 --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
150 lines
3.2 KiB
TypeScript
150 lines
3.2 KiB
TypeScript
import type { PrismaClient } from "@calcom/prisma";
|
|
import type { User } from "@calcom/prisma/client";
|
|
import type { Mock } from "vitest";
|
|
import { vi } from "vitest";
|
|
import { type DeepMockProxy, mockDeep, mockReset } from "vitest-mock-extended";
|
|
|
|
// 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 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,
|
|
createUserRepositoryMock,
|
|
createAvatarUrlMock,
|
|
createSafeStringifyMock,
|
|
createGetTokenMock,
|
|
createMockUser,
|
|
createMockToken,
|
|
};
|