Skip to content

Scheduling infrastructure for absolutely everyone.

fix: only fixed hosts added (#21407)

Anik Dhabal Babu041871f1b62e
diff --git a/packages/features/bookings/lib/handleNewBooking.ts b/packages/features/bookings/lib/handleNewBooking.ts
index f91a7131f4b..f2bd4d9e02e 100644
--- a/packages/features/bookings/lib/handleNewBooking.ts
+++ b/packages/features/bookings/lib/handleNewBooking.ts
@@ -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
diff --git a/packages/features/bookings/lib/handleNewBooking/test/buildEventForTeamEventType.test.ts b/packages/features/bookings/lib/handleNewBooking/test/buildEventForTeamEventType.test.ts
index e87a4eb4955..63601754eb5 100644
--- a/packages/features/bookings/lib/handleNewBooking/test/buildEventForTeamEventType.test.ts
+++ b/packages/features/bookings/lib/handleNewBooking/test/buildEventForTeamEventType.test.ts
@@ -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: "[email protected]" }),
+ baseUser({ id: 2, isFixed: false, email: "[email protected]" }),
baseUser({ id: 3, isFixed: true, email: "[email protected]" }),
],
organizerUser: { email: "[email protected]" },
@@ -119,7 +119,27 @@ describe("buildEventForTeamEventType", () => {
const memberEmails = teamArgs.members.map((m: any) => m.email);
expect(memberEmails).toContain("[email protected]");
- expect(memberEmails).not.toContain("[email protected]");
+ expect(memberEmails).toContain("[email protected]");
+ });
+
+ 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: "[email protected]" }),
+ baseUser({ id: 2, isFixed: false, email: "[email protected]" }),
+ baseUser({ id: 4, isFixed: false, email: "[email protected]" }),
+ ],
+ organizerUser: { email: "[email protected]" },
+ schedulingType: SchedulingType.ROUND_ROBIN,
+ });
+
+ const teamArgs = withTeamSpy.mock.calls[0][0];
+ const memberEmails = teamArgs.members.map((m: any) => m.email);
+
+ expect(memberEmails).toContain("[email protected]");
+ expect(memberEmails).toContain("[email protected]");
+ expect(memberEmails).not.toContain("[email protected]");
});
it("builds a team with fallback name and id", async () => {