Files
Benny JooandDevin AI ab21c7f805 refactor: Cal.diy (#28903)
* 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>
2026-04-15 09:52:36 -03:00

282 lines
7.1 KiB
TypeScript

/* eslint-disable @typescript-eslint/no-explicit-any */
import CloseCom from "@calcom/lib/CloseCom";
import {
getCloseComContactIds,
getCloseComCustomActivityTypeFieldsIds,
getCloseComLeadId,
getCustomActivityTypeInstanceData,
} from "@calcom/lib/CloseComeUtils";
import { APP_NAME } from "@calcom/lib/constants";
import type { CalendarEvent } from "@calcom/types/Calendar";
import { afterEach, expect, test, vi } from "vitest";
vi.mock("@calcom/lib/CloseCom", () => ({
default: class {
constructor() {
/* Mock */
}
},
}));
vi.mock("@calcom/prisma", () => ({
default: {},
prisma: {},
}));
afterEach(() => {
vi.resetAllMocks();
});
// getCloseComLeadId
test("check generic lead generator: already exists", async () => {
CloseCom.prototype.lead = {
list: () => ({
data: [{ name: `From ${APP_NAME}`, id: "abc" }],
}),
} as any;
const closeCom = new CloseCom("someKey");
const id = await getCloseComLeadId(closeCom);
expect(id).toEqual("abc");
});
// getCloseComLeadId
test("check generic lead generator: doesn't exist", async () => {
CloseCom.prototype.lead = {
list: () => ({
data: [],
}),
create: () => ({ id: "def" }),
} as any;
const closeCom = new CloseCom("someKey");
const id = await getCloseComLeadId(closeCom);
expect(id).toEqual("def");
});
// getCloseComContactIds
test("retrieve contact IDs: all exist", async () => {
const attendees = [
{ email: "test1@example.com", id: "test1" },
{ email: "test2@example.com", id: "test2" },
];
const event = {
attendees,
} as { attendees: { email: string; name: string | null; id: string }[] };
CloseCom.prototype.contact = {
search: () => ({ data: attendees }),
} as any;
const closeCom = new CloseCom("someKey");
const contactIds = await getCloseComContactIds(event.attendees, closeCom, "leadId");
expect(contactIds).toEqual(["test1", "test2"]);
});
// getCloseComContactIds
test("retrieve contact IDs: some don't exist", async () => {
const attendees = [{ email: "test1@example.com", id: "test1" }, { email: "test2@example.com" }];
const event = {
attendees,
} as CalendarEvent;
CloseCom.prototype.contact = {
search: () => ({ data: [{ emails: [{ email: "test1@example.com" }], id: "test1" }] }),
create: () => ({ id: "test3" }),
} as any;
const closeCom = new CloseCom("someKey");
const contactIds = await getCloseComContactIds(event.attendees, closeCom, "leadId");
expect(contactIds).toEqual(["test1", "test3"]);
});
// getCloseComCustomActivityTypeFieldsIds
test("retrieve custom fields for custom activity type: type doesn't exist, no field created", async () => {
CloseCom.prototype.activity = {
type: {
get: () => [],
},
} as any;
CloseCom.prototype.customActivity = {
type: {
get: () => ({ data: [] }),
create: () => ({ id: "type1" }),
},
} as any;
CloseCom.prototype.customField = {
activity: {
create: (data: { name: string }) => ({ id: `field${data.name.length}${data.name[0]}` }),
},
} as any;
const closeCom = new CloseCom("someKey");
const contactIds = await getCloseComCustomActivityTypeFieldsIds(
[
["Attendees", "", true, true],
["Date & Time", "", true, true],
["Time Zone", "", true, true],
],
closeCom
);
expect(contactIds).toEqual({
activityType: "type1",
fields: ["field9A", "field11D", "field9T"],
});
});
// getCloseComCustomActivityTypeFieldsIds
test("retrieve custom fields for custom activity type: type exists, no field created", async () => {
CloseCom.prototype.activity = {
type: {
get: () => [],
},
} as any;
CloseCom.prototype.customActivity = {
type: {
get: () => ({ data: [{ id: "typeX", name: `${APP_NAME} Activity` }] }),
},
} as any;
CloseCom.prototype.customField = {
activity: {
get: () => ({ data: [{ id: "fieldY", custom_activity_type_id: "typeX", name: "Attendees" }] }),
create: (data: { name: string }) => ({ id: `field${data.name.length}${data.name[0]}` }),
},
} as any;
const closeCom = new CloseCom("someKey");
const contactIds = await getCloseComCustomActivityTypeFieldsIds(
[
["Attendees", "", true, true],
["Date & Time", "", true, true],
["Time Zone", "", true, true],
],
closeCom
);
expect(contactIds).toEqual({
activityType: "typeX",
fields: ["fieldY", "field11D", "field9T"],
});
});
// getCustomActivityTypeInstanceData
test("prepare data to create custom activity type instance: two attendees, no additional notes", async () => {
const attendees = [
{ email: "test1@example.com", id: "test1", timeZone: "America/Montevideo" },
{ email: "test2@example.com" },
];
const now = new Date();
const event = {
attendees,
startTime: now.toISOString(),
} as unknown as CalendarEvent;
CloseCom.prototype.activity = {
type: {
get: () => [],
},
} as any;
CloseCom.prototype.customActivity = {
type: {
get: () => ({ data: [] }),
create: () => ({ id: "type1" }),
},
} as any;
CloseCom.prototype.customField = {
activity: {
create: (data: { name: string }) => ({ id: `field${data.name.length}${data.name[0]}` }),
},
} as any;
CloseCom.prototype.lead = {
list: () => ({
data: [],
}),
create: () => ({ id: "def" }),
} as any;
const closeCom = new CloseCom("someKey");
const data = await getCustomActivityTypeInstanceData(
event,
[
["Attendees", "", true, true],
["Date & Time", "", true, true],
["Time Zone", "", true, true],
],
closeCom
);
expect(data).toEqual({
custom_activity_type_id: "type1",
lead_id: "def",
"custom.field9A": ["test3"],
"custom.field11D": now.toISOString(),
"custom.field9T": "America/Montevideo",
});
});
// getCustomActivityTypeInstanceData
test("prepare data to create custom activity type instance: one attendees, with additional notes", async () => {
const attendees = [{ email: "test1@example.com", id: "test1", timeZone: "America/Montevideo" }];
const now = new Date();
const event = {
attendees,
startTime: now.toISOString(),
additionalNotes: "Some comment!",
} as any;
CloseCom.prototype.activity = {
type: {
get: () => [],
},
} as any;
CloseCom.prototype.customActivity = {
type: {
get: () => ({ data: [] }),
create: () => ({ id: "type1" }),
},
} as any;
CloseCom.prototype.customField = {
activity: {
create: (data: { name: string }) => ({ id: `field${data.name.length}${data.name[0]}` }),
},
} as any;
CloseCom.prototype.lead = {
list: () => ({
data: [{ name: `From ${APP_NAME}`, id: "abc" }],
}),
} as any;
const closeCom = new CloseCom("someKey");
const data = await getCustomActivityTypeInstanceData(
event,
[
["Attendees", "", true, true],
["Date & Time", "", true, true],
["Time Zone", "", true, true],
],
closeCom
);
expect(data).toEqual({
custom_activity_type_id: "type1",
lead_id: "abc",
"custom.field9A": null,
"custom.field11D": now.toISOString(),
"custom.field9T": "America/Montevideo",
});
});