* Initial commit * routingForm to Booking a particular team member working * Happy path working * Fixes * Fix router query params forwarding * Add basicConfig within app * Tests * More tests * Update packages/app-store/routing-forms/components/SingleForm.tsx Co-authored-by: Omar López <zomars@me.com> * WIP * Fix lint issues * Fix tests -TS and add new logic * Add getEventTypeRedirectUrl tests * Remove booking title changes code * More changes * Add tests for getRoutedUsers * More tests * Update testUtils.ts --------- Co-authored-by: Omar López <zomars@me.com> Co-authored-by: Keith Williams <keithwillcode@gmail.com>
91 lines
3.2 KiB
TypeScript
91 lines
3.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import type { GetAvailabilityUser } from "@calcom/core/getUserAvailability";
|
|
|
|
import { getUsersWithCredentialsConsideringContactOwner } from "./util";
|
|
|
|
describe("getUsersWithCredentialsConsideringContactOwner", () => {
|
|
const createMockUser = (email: string): GetAvailabilityUser => ({
|
|
id: Math.random(),
|
|
email,
|
|
name: email.split("@")[0],
|
|
username: email.split("@")[0],
|
|
timeZone: "UTC",
|
|
weekStart: "Monday",
|
|
defaultScheduleId: null,
|
|
bufferTime: 0,
|
|
locale: "en",
|
|
});
|
|
|
|
it("should return all hosts when contact owner does not exist", () => {
|
|
const hosts = [
|
|
{ isFixed: true, user: createMockUser("host1@example.com") },
|
|
{ isFixed: false, user: createMockUser("host2@example.com") },
|
|
];
|
|
const result = getUsersWithCredentialsConsideringContactOwner({
|
|
contactOwnerEmail: "nonexistent@example.com",
|
|
hosts,
|
|
});
|
|
expect(result).toHaveLength(2);
|
|
expect(result.map((u) => u.email)).toEqual(["host1@example.com", "host2@example.com"]);
|
|
});
|
|
|
|
it("should return all hosts when contact owner is a fixed host", () => {
|
|
const hosts = [
|
|
{ isFixed: true, user: createMockUser("host1@example.com") },
|
|
{ isFixed: false, user: createMockUser("host2@example.com") },
|
|
];
|
|
const result = getUsersWithCredentialsConsideringContactOwner({
|
|
contactOwnerEmail: "host1@example.com",
|
|
hosts,
|
|
});
|
|
expect(result).toHaveLength(2);
|
|
expect(result.map((u) => u.email)).toEqual(["host1@example.com", "host2@example.com"]);
|
|
});
|
|
|
|
it("should return contact owner and fixed hosts when contact owner is not fixed", () => {
|
|
const hosts = [
|
|
{ isFixed: true, user: createMockUser("host1@example.com") },
|
|
{ isFixed: false, user: createMockUser("host2@example.com") },
|
|
{ isFixed: false, user: createMockUser("contactowner@example.com") },
|
|
];
|
|
const result = getUsersWithCredentialsConsideringContactOwner({
|
|
contactOwnerEmail: "contactowner@example.com",
|
|
hosts,
|
|
});
|
|
expect(result).toHaveLength(2);
|
|
expect(result.map((u) => u.email)).toEqual(["host1@example.com", "contactowner@example.com"]);
|
|
});
|
|
|
|
it("should return all hosts when contactOwnerEmail is null", () => {
|
|
const hosts = [
|
|
{ isFixed: true, user: createMockUser("host1@example.com") },
|
|
{ isFixed: false, user: createMockUser("host2@example.com") },
|
|
];
|
|
const result = getUsersWithCredentialsConsideringContactOwner({
|
|
contactOwnerEmail: null,
|
|
hosts,
|
|
});
|
|
expect(result).toHaveLength(2);
|
|
expect(result.map((u) => u.email)).toEqual(["host1@example.com", "host2@example.com"]);
|
|
});
|
|
|
|
it("should return only fixed hosts when there's no contact owner", () => {
|
|
const hosts = [
|
|
{ isFixed: true, user: createMockUser("host1@example.com") },
|
|
{ isFixed: false, user: createMockUser("host2@example.com") },
|
|
{ isFixed: true, user: createMockUser("host3@example.com") },
|
|
];
|
|
const result = getUsersWithCredentialsConsideringContactOwner({
|
|
contactOwnerEmail: null,
|
|
hosts,
|
|
});
|
|
expect(result).toHaveLength(3);
|
|
expect(result.map((u) => u.email)).toEqual([
|
|
"host1@example.com",
|
|
"host2@example.com",
|
|
"host3@example.com",
|
|
]);
|
|
});
|
|
});
|