fix: only fixed hosts added (#21407)

This commit is contained in:
Anik Dhabal Babu
2025-05-22 18:14:46 +00:00
committed by GitHub
parent 8c8ae127fe
commit 041871f1b6
2 changed files with 31 additions and 12 deletions
@@ -276,17 +276,16 @@ export const buildEventForTeamEventType = async ({
throw new Error("Scheduling type is required for team event type");
}
const teamDestinationCalendars: DestinationCalendar[] = [];
const fixedUsers = users.filter((user) => user.isFixed);
const nonFixedUsers = users.filter((user) => !user.isFixed);
const filteredUsers =
schedulingType === SchedulingType.ROUND_ROBIN
? [...fixedUsers, ...(nonFixedUsers.length > 0 ? [nonFixedUsers[0]] : [])]
: users;
// Organizer or user owner of this event type it's not listed as a team member.
const teamMemberPromises = users
.filter((user) => {
if (user.email === organizerUser.email) return false;
// Skip non-fixed users in ROUND_ROBIN team event
if (schedulingType === SchedulingType.ROUND_ROBIN && !user.isFixed) return false;
return true;
})
const teamMemberPromises = filteredUsers
.filter((user) => user.email !== organizerUser.email)
.map(async (user) => {
// TODO: Add back once EventManager tests are ready https://github.com/calcom/cal.com/pull/14610#discussion_r1567817120
// push to teamDestinationCalendars if it's a team event but collective only
@@ -104,11 +104,11 @@ describe("buildEventForTeamEventType", () => {
expect(withDestinationCalendarArgs).toHaveLength(0);
});
it("excludes non-fixed users for ROUND_ROBIN", async () => {
it("includes one non-fixed user for ROUND_ROBIN when fixed users exist", async () => {
await buildEventForTeamEventType({
existingEvent: {},
users: [
baseUser({ id: 2, isFixed: false, email: "notfixed@example.com" }),
baseUser({ id: 2, isFixed: false, email: "nonfixed@example.com" }),
baseUser({ id: 3, isFixed: true, email: "fixed@example.com" }),
],
organizerUser: { email: "organizer@example.com" },
@@ -119,7 +119,27 @@ describe("buildEventForTeamEventType", () => {
const memberEmails = teamArgs.members.map((m: any) => m.email);
expect(memberEmails).toContain("fixed@example.com");
expect(memberEmails).not.toContain("notfixed@example.com");
expect(memberEmails).toContain("nonfixed@example.com");
});
it("includes only the first non-fixed user for ROUND_ROBIN when multiple exist", async () => {
await buildEventForTeamEventType({
existingEvent: {},
users: [
baseUser({ id: 3, isFixed: true, email: "fixed@example.com" }),
baseUser({ id: 2, isFixed: false, email: "nonfixed1@example.com" }),
baseUser({ id: 4, isFixed: false, email: "nonfixed2@example.com" }),
],
organizerUser: { email: "organizer@example.com" },
schedulingType: SchedulingType.ROUND_ROBIN,
});
const teamArgs = withTeamSpy.mock.calls[0][0];
const memberEmails = teamArgs.members.map((m: any) => m.email);
expect(memberEmails).toContain("fixed@example.com");
expect(memberEmails).toContain("nonfixed1@example.com");
expect(memberEmails).not.toContain("nonfixed2@example.com");
});
it("builds a team with fallback name and id", async () => {