Files
cal.diy/packages/lib/bookings/getRoutedUsers.test.ts
T
06429e27fb test: Add Attributes Routing e2e and some more unit tests (#17032)
* 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 <[email protected]>

* 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 <[email protected]>
Co-authored-by: Keith Williams <[email protected]>
2024-10-09 22:47:16 +05:30

129 lines
4.8 KiB
TypeScript

import { describe, it, expect } from "vitest";
import {
getRoutedHostsWithContactOwnerAndFixedHosts,
getRoutedUsersWithContactOwnerAndFixedUsers,
} from "./getRoutedUsers";
describe("getRoutedHostsWithContactOwnerAndFixedHosts", () => {
const hosts = [
{ user: { id: 1, email: "[email protected]" }, isFixed: false },
{ user: { id: 2, email: "[email protected]" }, isFixed: true },
{ user: { id: 3, email: "[email protected]" }, isFixed: false },
{ user: { id: 4, email: "[email protected]" }, isFixed: false },
];
const hostsWithoutFixedHosts = hosts.map((host) => ({ ...host, isFixed: false }));
it("should return all hosts when routedTeamMemberIds is null", () => {
const result = getRoutedHostsWithContactOwnerAndFixedHosts({
routedTeamMemberIds: null,
hosts,
contactOwnerEmail: "[email protected]",
});
expect(result).toEqual(hosts);
});
it("should return all hosts when routedTeamMemberIds is empty - We don't want to enter a scenario where we have no team members to be booked", () => {
const result = getRoutedHostsWithContactOwnerAndFixedHosts({
routedTeamMemberIds: [],
hosts,
contactOwnerEmail: "[email protected]",
});
expect(result).toEqual(hosts);
});
it("should filter hosts based on routedTeamMemberIds, isFixed, and contactOwnerEmail", () => {
const result = getRoutedHostsWithContactOwnerAndFixedHosts({
routedTeamMemberIds: [1, 3],
hosts,
contactOwnerEmail: "[email protected]",
});
expect(result).toEqual([
{ user: { id: 1, email: "[email protected]" }, isFixed: false },
{ user: { id: 2, email: "[email protected]" }, isFixed: true },
{ user: { id: 3, email: "[email protected]" }, isFixed: false },
{ user: { id: 4, email: "[email protected]" }, isFixed: false },
]);
});
it("should return an empty array when no hosts match the criteria", () => {
const result = getRoutedHostsWithContactOwnerAndFixedHosts({
routedTeamMemberIds: [5],
hosts: hostsWithoutFixedHosts,
contactOwnerEmail: "[email protected]",
});
expect(result).toEqual([]);
});
it("should return fixed hosts even if routedTeamMemberIds and contactOwnerEmail are invalid ", () => {
const result = getRoutedHostsWithContactOwnerAndFixedHosts({
routedTeamMemberIds: [5],
hosts,
contactOwnerEmail: "[email protected]",
});
expect(result).toEqual([{ user: { id: 2, email: "[email protected]" }, isFixed: true }]);
});
});
describe("getRoutedUsersWithContactOwnerAndFixedUsers", () => {
const users = [
{ id: 1, email: "[email protected]", isFixed: false },
{ id: 2, email: "[email protected]", isFixed: true },
{ id: 3, email: "[email protected]", isFixed: false },
{ id: 4, email: "[email protected]", isFixed: false },
];
const usersWithoutFixedHosts = users.map((user) => ({ ...user, isFixed: false }));
it("should return all users when routedTeamMemberIds is null", () => {
const result = getRoutedUsersWithContactOwnerAndFixedUsers({
routedTeamMemberIds: null,
users,
contactOwnerEmail: "[email protected]",
});
expect(result).toEqual(users);
});
it("should return all users when routedTeamMemberIds is empty - We don't want to enter a scenario where we have no team members to be booked", () => {
const result = getRoutedUsersWithContactOwnerAndFixedUsers({
routedTeamMemberIds: [],
users,
contactOwnerEmail: "[email protected]",
});
expect(result).toEqual(users);
});
it("should filter users based on routedTeamMemberIds, isFixed, and contactOwnerEmail", () => {
const result = getRoutedUsersWithContactOwnerAndFixedUsers({
routedTeamMemberIds: [1, 3],
users,
contactOwnerEmail: "[email protected]",
});
expect(result).toEqual([
{ id: 1, email: "[email protected]", isFixed: false },
{ id: 2, email: "[email protected]", isFixed: true },
{ id: 3, email: "[email protected]", isFixed: false },
{ id: 4, email: "[email protected]", isFixed: false },
]);
});
it("should return an empty array when neither fixed, nor routedTeamMemberIds, nor contactOwnerEmail match", () => {
const result = getRoutedUsersWithContactOwnerAndFixedUsers({
routedTeamMemberIds: [5],
users: usersWithoutFixedHosts,
contactOwnerEmail: "[email protected]",
});
expect(result).toEqual([]);
});
it("should return fixed hosts even if routedTeamMemberIds and contactOwnerEmail are invalid ", () => {
const result = getRoutedUsersWithContactOwnerAndFixedUsers({
routedTeamMemberIds: [5],
users,
contactOwnerEmail: "[email protected]",
});
expect(result).toEqual([{ id: 2, email: "[email protected]", isFixed: true }]);
});
});