* fix: mock delegationCredential in getRoutedUsers test to prevent flaky worker shutdown errors The getRoutedUsers.test.ts file only tests the pure sync function getRoutedUsersWithContactOwnerAndFixedUsers, but importing getRoutedUsers.ts triggers a heavy transitive import chain: getRoutedUsers.ts -> @calcom/app-store/delegationCredential -> _utils/getCalendar -> calendar.services.generated (all calendar services) -> CalendarService.ts -> ics/tsdav Sometimes the vitest worker finishes tests and shuts down before all async module resolution completes, causing: Error: [vitest-worker]: Closing rpc while "fetch" was pending Mock @calcom/app-store/delegationCredential to cut off the import chain since the tested function doesn't use it. * Clean up comments in getRoutedUsers.test.ts Removed comments about mocking delegationCredential to improve code clarity.
76 lines
2.6 KiB
TypeScript
76 lines
2.6 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import { getRoutedUsersWithContactOwnerAndFixedUsers } from "./getRoutedUsers";
|
|
|
|
vi.mock("@calcom/prisma", () => {
|
|
return {
|
|
default: vi.fn(),
|
|
};
|
|
});
|
|
|
|
vi.mock("@calcom/app-store/delegationCredential", () => {
|
|
return {
|
|
enrichHostsWithDelegationCredentials: vi.fn().mockResolvedValue([]),
|
|
};
|
|
});
|
|
|
|
describe("getRoutedUsersWithContactOwnerAndFixedUsers", () => {
|
|
const users = [
|
|
{ id: 1, email: "user1@example.com", isFixed: false },
|
|
{ id: 2, email: "user2@example.com", isFixed: true },
|
|
{ id: 3, email: "user3@example.com", isFixed: false },
|
|
{ id: 4, email: "owner@example.com", 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: "owner@example.com",
|
|
});
|
|
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: "owner@example.com",
|
|
});
|
|
expect(result).toEqual(users);
|
|
});
|
|
|
|
it("should filter users based on routedTeamMemberIds, isFixed, and contactOwnerEmail", () => {
|
|
const result = getRoutedUsersWithContactOwnerAndFixedUsers({
|
|
routedTeamMemberIds: [1, 3],
|
|
users,
|
|
contactOwnerEmail: "owner@example.com",
|
|
});
|
|
expect(result).toEqual([
|
|
{ id: 1, email: "user1@example.com", isFixed: false },
|
|
{ id: 2, email: "user2@example.com", isFixed: true },
|
|
{ id: 3, email: "user3@example.com", isFixed: false },
|
|
{ id: 4, email: "owner@example.com", isFixed: false },
|
|
]);
|
|
});
|
|
|
|
it("should return an empty array when neither fixed, nor routedTeamMemberIds, nor contactOwnerEmail match", () => {
|
|
const result = getRoutedUsersWithContactOwnerAndFixedUsers({
|
|
routedTeamMemberIds: [5],
|
|
users: usersWithoutFixedHosts,
|
|
contactOwnerEmail: "nonexistent@example.com",
|
|
});
|
|
expect(result).toEqual([]);
|
|
});
|
|
|
|
it("should return fixed hosts even if routedTeamMemberIds and contactOwnerEmail are invalid ", () => {
|
|
const result = getRoutedUsersWithContactOwnerAndFixedUsers({
|
|
routedTeamMemberIds: [5],
|
|
users,
|
|
contactOwnerEmail: "nonexistent@example.com",
|
|
});
|
|
expect(result).toEqual([{ id: 2, email: "user2@example.com", isFixed: true }]);
|
|
});
|
|
});
|