Files
calendar/packages/features/bookings/lib/handleNewBooking/test/getLocationValueForDb.test.ts
T
Benny JooandGitHub bb68cd73ef refactor: circular deps between app store and lib [6] (#23971)
* move delegation credential repository to features

* mv credential repository to features

* update imports

* mv

* fix

* fix

* fix

* fix

* fix

* update imports

* update imports

* update eslint rule

* fix

* fix

* mv getConnectedDestinationCalendars

* fix import errors

* mv getCalendarsEvents

* remove getUsersCredentials

* wip

* revert eslint rule change for now

* fix type checks

* fix

* format

* cleanup

* fix

* fix

* fix

* fix

* fix tests

* migrate getUserAvailability

* migrate

* fix tests

* fix type checks

* fix

* fix

* migrate crmManager

* update imports

* migrate raqbUtils to appstore

* migrate getLuckyUser to features

* migrate findTeamMembersMatchingAttributeLogic to appstore

* update imports

* fix

* fix

* fix test

* fix unit tests

* fix

* fix

* add eslint config
2025-10-09 14:02:12 +00:00

174 lines
5.1 KiB
TypeScript

import { describe, it, expect, vi } from "vitest";
import type { Prisma } from "@calcom/prisma/client";
import type { CredentialForCalendarService } from "@calcom/types/Credential";
import { _getLocationValuesForDb } from "../getLocationValuesForDb";
vi.mock("@calcom/prisma/zod-utils", () => ({
userMetadata: { parse: (metadata: any) => metadata },
}));
vi.mock("@calcom/app-store/delegationCredential", () => ({
getFirstDelegationConferencingCredentialAppLocation: ({
credentials,
}: {
credentials: CredentialForCalendarService[];
}) => (credentials[0] && (credentials[0] as any).__test__appLink) || null,
}));
type TestUser = {
username: string | null;
metadata: Prisma.JsonValue;
credentials: CredentialForCalendarService[];
};
describe("_getLocationValuesForDb", () => {
it("returns the provided location for single user bookings", () => {
const users: TestUser[] = [
{
username: "alice",
metadata: {},
credentials: [],
},
];
const result = _getLocationValuesForDb({
dynamicUserList: ["alice"],
users,
location: "https://meet.example.com/alice",
});
expect(result.locationBodyString).toBe("https://meet.example.com/alice");
expect(result.organizerOrFirstDynamicGroupMemberDefaultLocationUrl).toBeUndefined();
});
it("uses the first group member's default conferencing appLink if set", () => {
const users: TestUser[] = [
{
username: "bob",
metadata: {
defaultConferencingApp: {
appSlug: "zoom",
appLink: "https://zoom.us/bob",
},
},
credentials: [],
},
{
username: "carol",
metadata: {},
credentials: [],
},
];
const result = _getLocationValuesForDb({
dynamicUserList: ["bob", "carol"],
users,
location: "https://meet.example.com/group",
});
expect(result.locationBodyString).toBe("https://zoom.us/bob");
expect(result.organizerOrFirstDynamicGroupMemberDefaultLocationUrl).toBe("https://zoom.us/bob");
});
it("uses the first group member's first delegation credential's conferencing app if no preference is set", () => {
const users: TestUser[] = [
{
username: "dave",
metadata: {},
credentials: [
{
__test__appLink: "https://meet.google.com/dave",
} as unknown as CredentialForCalendarService,
],
},
{
username: "eve",
metadata: {},
credentials: [],
},
];
const result = _getLocationValuesForDb({
dynamicUserList: ["dave", "eve"],
users,
location: "https://meet.example.com/group",
});
expect(result.locationBodyString).toBe("https://meet.google.com/dave");
expect(result.organizerOrFirstDynamicGroupMemberDefaultLocationUrl).toBe("https://meet.google.com/dave");
});
it("falls back to provided location if no preferences or credentials are set", () => {
const users: TestUser[] = [
{
username: "frank",
metadata: {},
credentials: [],
},
{
username: "grace",
metadata: {},
credentials: [],
},
];
const result = _getLocationValuesForDb({
dynamicUserList: ["frank", "grace"],
users,
location: "https://meet.example.com/group",
});
expect(result.locationBodyString).toBe("https://meet.example.com/group");
expect(result.organizerOrFirstDynamicGroupMemberDefaultLocationUrl).toBeNull();
});
it("falls back to provided location if preference is set but has no appLink", () => {
const users: TestUser[] = [
{
username: "frank",
metadata: {
defaultConferencingApp: {
appSlug: "daily-video",
},
},
credentials: [],
},
{
username: "grace",
metadata: {},
credentials: [],
},
];
const result = _getLocationValuesForDb({
dynamicUserList: ["frank", "grace"],
users,
location: "https://meet.example.com/group",
});
expect(result.locationBodyString).toBe("https://meet.example.com/group");
expect(result.organizerOrFirstDynamicGroupMemberDefaultLocationUrl).toBeNull();
});
it("sorts users according to dynamicUserList before picking the first member", () => {
const users: TestUser[] = [
{
username: "zara",
metadata: {
defaultConferencingApp: {
appSlug: "teams",
appLink: "https://teams.microsoft.com/zara",
},
},
credentials: [],
},
{
username: "yanni",
metadata: {},
credentials: [],
},
];
// yanni is first in dynamicUserList, but zara is first in users array
const result = _getLocationValuesForDb({
dynamicUserList: ["yanni", "zara"],
users,
location: "https://meet.example.com/group",
});
// After sorting, yanni is first, has no preference, so fallback to location
expect(result.locationBodyString).toBe("https://meet.example.com/group");
expect(result.organizerOrFirstDynamicGroupMemberDefaultLocationUrl).toBeNull();
});
});