Files
calendar/packages/features/bookings/lib/buildEventUrlFromBooking.test.ts
Benny JooandGitHub e91bf53d80 refactor: Remove circular deps between @calcom/lib and @calcom/features [2] (#24438)
* move SystemField to features

* migrate workflow service

* merge two tests for team repository

* update imports and migrate team repository

* migrate delegation credential repository

* migrate credential repository

* migrate entityPermissionUtils

* migrate hashedLink service and repository

* migrate membership service

* update imports

* remove file

* migrate buildEventUrlFromBooking

* migrate getAllUserBookings to features

* update imports

* update organizationMock

* migrate slots

* migrate date-ranges to schedules dir

* migrate getAggregatedAvailability

* fix

* refactor

* migrate useCreateEventType hook to features

* migrate assignValueToUser

* migrate validateUsername to auth features

* migrate system field back to lib

* migrate getLabelValueMapFromResponses back to lib

* update imports

* use relative path

* fix type checks

* fix

* fix

* fix tests

* update gh codeowners

* fix

* fix
2025-10-17 06:48:08 -03:00

169 lines
4.6 KiB
TypeScript

import { constantsScenarios } from "@calcom/lib/__mocks__/constants";
import { describe, it, vi, expect, beforeEach } from "vitest";
import { getBrand } from "@calcom/features/ee/organizations/lib/getBrand";
import { buildEventUrlFromBooking } from "./buildEventUrlFromBooking";
vi.mock("@calcom/features/ee/organizations/lib/getBrand", () => ({
getBrand: vi.fn(),
}));
const WEBSITE_URL = "https://buildEventTest.example";
beforeEach(() => {
constantsScenarios.setWebsiteUrl(WEBSITE_URL);
});
describe("buildEventUrlFromBooking", () => {
describe("Non Organization", () => {
it("should correctly build the event URL for a team event booking", async () => {
const booking = {
eventType: {
slug: "30min",
team: {
slug: "engineering",
parentId: 123,
},
},
profileEnrichedBookingUser: {
profile: {
organizationId: null,
username: "john",
},
},
dynamicGroupSlugRef: null,
};
const expectedUrl = `${WEBSITE_URL}/team/engineering/30min`;
const result = await buildEventUrlFromBooking(booking);
expect(result).toBe(expectedUrl);
});
it("should correctly build the event URL for a dynamic group booking", async () => {
const booking = {
eventType: {
slug: "30min",
team: null,
},
profileEnrichedBookingUser: {
profile: {
organizationId: null,
username: "john",
},
},
dynamicGroupSlugRef: "john+jane",
};
const expectedUrl = `${WEBSITE_URL}/john+jane/30min`;
const result = await buildEventUrlFromBooking(booking);
expect(result).toBe(expectedUrl);
});
it("should correctly build the event URL for a personal booking", async () => {
const booking = {
eventType: {
slug: "30min",
team: null,
},
profileEnrichedBookingUser: {
profile: {
organizationId: null,
username: "john",
},
},
dynamicGroupSlugRef: null,
};
const expectedUrl = `${WEBSITE_URL}/john/30min`;
const result = await buildEventUrlFromBooking(booking);
expect(result).toBe(expectedUrl);
});
});
describe("Organization", () => {
const organizationId = 123;
const orgOrigin = "https://acme.cal.local";
beforeEach(() => {
getBrand.mockResolvedValue({
fullDomain: orgOrigin,
});
});
it("should correctly build the event URL for a team event booking", async () => {
const booking = {
eventType: {
slug: "30min",
team: {
slug: "engineering",
parentId: 123,
},
},
profileEnrichedBookingUser: {
profile: {
organizationId,
username: "john",
},
},
dynamicGroupSlugRef: null,
};
const expectedUrl = `${orgOrigin}/team/engineering/30min`;
const result = await buildEventUrlFromBooking(booking);
expect(result).toBe(expectedUrl);
});
it("should correctly build the event URL for a dynamic group booking", async () => {
const booking = {
eventType: {
slug: "30min",
team: null,
},
profileEnrichedBookingUser: {
profile: {
organizationId,
username: "john",
},
},
dynamicGroupSlugRef: "john+jane",
};
const expectedUrl = `${orgOrigin}/john+jane/30min`;
const result = await buildEventUrlFromBooking(booking);
expect(result).toBe(expectedUrl);
});
it("should correctly build the event URL for a personal booking", async () => {
const booking = {
eventType: {
slug: "30min",
team: null,
},
profileEnrichedBookingUser: {
profile: {
organizationId,
username: "john",
},
},
dynamicGroupSlugRef: null,
};
const expectedUrl = `${orgOrigin}/john/30min`;
const result = await buildEventUrlFromBooking(booking);
expect(result).toBe(expectedUrl);
});
});
it("should throw if the username isn't set", async () => {
const booking = {
eventType: {
slug: "30min",
team: null,
},
profileEnrichedBookingUser: {
profile: {
organizationId: null,
username: null,
},
},
dynamicGroupSlugRef: null,
};
await expect(() => buildEventUrlFromBooking(booking)).rejects.toThrow(
"No username found for booking user."
);
});
});