e04a394e1c
* fix: remove IS_PRODUCTION gate from BookingAuditProducer Remove the IS_PRODUCTION check that was preventing booking audits from being queued in production. Audits are still properly gated by: 1. Organization check: Audits are skipped for non-organization bookings (organizationId === null) 2. Feature flag: The BookingAuditTaskConsumer checks if the 'booking-audit' feature is enabled for the organization via featuresRepository.checkIfTeamHasFeature() The IS_PRODUCTION gate was intentionally added to prevent logs from being created in production while the action data versioning was being actively reviewed and finalized. Without proper versioning handling, the Booking History UI could crash when encountering unversioned data. Now that the versioning system is in place, this gate can be safely removed. Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: revert formatting, keep only IS_PRODUCTION removal Reverts the unintended formatting changes from the previous commit. Only removes the IS_PRODUCTION gate without changing indentation. Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * feat: add booking-audit feature flag check in producer to avoid unnecessary task creation - Query booking-audit and booking-email-sms-tasker flags in parallel before fireBookingEvents - Pass isBookingAuditEnabled through BookingEventHandler to producer's queueTask method - Add conditional check in queueTask with debug log when skipping audit - Reuse pre-queried isBookingEmailSmsTaskerEnabled flag instead of querying again Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * feat: make isBookingAuditEnabled required and pass it through all booking audit flows - Make isBookingAuditEnabled a required property in BookingAuditProducerService interface - Update all BookingEventHandler methods to require isBookingAuditEnabled - Add feature flag check in all flows that call booking audit: - handleSeats (seat booking/rescheduling) - RecurringBookingService (bulk bookings) - handleCancelBooking (booking cancellation) - handleConfirmation (booking acceptance) - roundRobinReassignment (automatic reassignment) - roundRobinManualReassignment (manual reassignment) - trpc handlers: addGuests, confirm, editLocation, requestReschedule - Skip queueing audit tasks when feature is disabled with debug logging Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: add featuresRepository dependency to RecurringBookingService DI module Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * refactor: make isBookingAuditEnabled optional for non-main flows Keep feature flag check only in main flows (handleSeats, RegularBookingService, RecurringBookingService) which are frequently triggered. For other flows (handleCancelBooking, handleConfirmation, roundRobinReassignment, etc.), rely on the existing consumer-level check. Changes: - Revert feature flag check from non-main flows - Make isBookingAuditEnabled optional in interface for non-main flow methods - Keep isBookingAuditEnabled required for main flow methods (queueCreatedAudit, queueRescheduledAudit, queueSeatBookedAudit, queueSeatRescheduledAudit, queueBulkCreatedAudit, queueBulkRescheduledAudit) - Update BookingEventHandlerService to use required params for main flows and optional for non-main flows Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * refactor: remove isBookingAuditEnabled from non-main flow methods Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * feat: make isBookingAuditEnabled required in all BookingEventHandlerService methods - Add isBookingAuditEnabled as required parameter in all BookingAuditProducerService interface methods - Update BookingAuditTaskerProducerService to use simplified check (!params.isBookingAuditEnabled) - Update BookingEventHandlerService to require isBookingAuditEnabled in all methods - Update all callers to query booking-audit feature flag and pass isBookingAuditEnabled: - handleCancelBooking - handleConfirmation - roundRobinReassignment - roundRobinManualReassignment - addGuests.handler - confirm.handler - editLocation.handler - requestReschedule.handler - Inject featuresRepository in API V2's booking-location.service.ts Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * test: update roundRobinReassignment tests to include isBookingAuditEnabled Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * test: update roundRobinManualReassignment tests to include isBookingAuditEnabled Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: inject featuresRepository in API V2 RecurringBookingService Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: import PrismaWorkerModule for PrismaFeaturesRepository dependency Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: use booking's organization for feature flag check in addGuests handler Use booking.user?.profiles?.[0]?.organizationId instead of user.organizationId to check the booking-audit feature flag. This ensures the feature flag is checked against the booking's organization rather than the actor's organization, which is consistent with other handlers in this PR. Addresses Cubic AI review feedback (confidence 9/10). Co-Authored-By: unknown <> * Add comment * fix: use user.organizationId for feature flag check in addGuests handler Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: use booking's organizationId for feature flag check in addGuests handler Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: revert to user.organizationId for feature flag check in addGuests handler Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: add isBookingAuditEnabled to onNoShowUpdated calls after main merge Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: add isBookingAuditEnabled to onNoShowUpdated calls and update tests Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
706 lines
23 KiB
TypeScript
706 lines
23 KiB
TypeScript
import prismaMock from "@calcom/testing/lib/__mocks__/prisma";
|
|
import {
|
|
addWorkflowReminders,
|
|
createBookingScenario,
|
|
getDate,
|
|
getMockBookingAttendee,
|
|
getScenarioData,
|
|
TestData,
|
|
} from "@calcom/testing/lib/bookingScenario/bookingScenario";
|
|
import { getBookingEventHandlerService } from "@calcom/features/bookings/di/BookingEventHandlerService.container";
|
|
import { BookingRepository } from "@calcom/features/bookings/repositories/BookingRepository";
|
|
import { BookingStatus, SchedulingType, WorkflowMethods } from "@calcom/prisma/enums";
|
|
import {
|
|
expectBookingToBeInDatabase,
|
|
expectSuccessfulRoundRobinReschedulingEmails,
|
|
expectWorkflowToBeTriggered,
|
|
} from "@calcom/testing/lib/bookingScenario/expects";
|
|
import { setupAndTeardown } from "@calcom/testing/lib/bookingScenario/setupAndTeardown";
|
|
import { test } from "@calcom/testing/lib/fixtures/fixtures";
|
|
import { parse } from "node-html-parser";
|
|
import { v4 as uuidv4 } from "uuid";
|
|
import { beforeEach, describe, expect, vi } from "vitest";
|
|
import type { BookingEventHandlerService } from "../../bookings/lib/onBookingEvents/BookingEventHandlerService";
|
|
|
|
vi.mock("@calcom/features/bookings/lib/EventManager");
|
|
vi.mock("@calcom/features/bookings/di/BookingEventHandlerService.container", () => ({
|
|
getBookingEventHandlerService: vi.fn(),
|
|
}));
|
|
|
|
const testDestinationCalendar = {
|
|
integration: "test-calendar",
|
|
externalId: "test-calendar",
|
|
};
|
|
|
|
const testUsers = [
|
|
{
|
|
id: 1,
|
|
name: "user-1",
|
|
timeZone: "Asia/Kolkata",
|
|
username: "host-1",
|
|
email: "host1@test.com",
|
|
schedules: [TestData.schedules.IstWorkHours],
|
|
destinationCalendar: testDestinationCalendar,
|
|
uuid: "uuid-1",
|
|
},
|
|
{
|
|
id: 2,
|
|
name: "user-2",
|
|
timeZone: "Asia/Kolkata",
|
|
username: "host-2",
|
|
email: "host2@test.com",
|
|
schedules: [TestData.schedules.IstWorkHours],
|
|
uuid: "uuid-2",
|
|
},
|
|
{
|
|
id: 3,
|
|
name: "user-3",
|
|
timeZone: "Asia/Kolkata",
|
|
username: "host-3",
|
|
email: "host3@test.com",
|
|
schedules: [TestData.schedules.IstWorkHours],
|
|
uuid: "uuid-3",
|
|
},
|
|
];
|
|
|
|
describe("roundRobinReassignment test", () => {
|
|
setupAndTeardown();
|
|
|
|
beforeEach(() => {
|
|
// Set up default mock for BookingEventHandlerService
|
|
const mockOnReassignment = vi.fn().mockResolvedValue(undefined);
|
|
vi.mocked(getBookingEventHandlerService).mockReturnValue({
|
|
onReassignment: mockOnReassignment,
|
|
} as unknown as BookingEventHandlerService);
|
|
});
|
|
|
|
test("reassign new round robin organizer", async ({ emails }) => {
|
|
const roundRobinReassignment = (await import("./roundRobinReassignment")).default;
|
|
const EventManager = (await import("@calcom/features/bookings/lib/EventManager")).default;
|
|
|
|
const eventManagerSpy = vi.spyOn(EventManager.prototype as any, "reschedule");
|
|
// Clear any existing mock calls from previous tests
|
|
eventManagerSpy.mockClear();
|
|
eventManagerSpy.mockResolvedValue({ referencesToCreate: [] });
|
|
|
|
const users = testUsers;
|
|
const originalHost = users[0];
|
|
const newHost = users[1];
|
|
// Assume we are using the RR fairness algorithm. Add an extra booking for user[2] to ensure user[1] is the new host
|
|
|
|
const { dateString: dateStringPlusOne } = getDate({ dateIncrement: 1 });
|
|
const { dateString: dateStringMinusOne } = getDate({ dateIncrement: -1 });
|
|
const { dateString: dateStringPlusTwo } = getDate({ dateIncrement: 2 });
|
|
|
|
const bookingToReassignUid = "booking-to-reassign";
|
|
|
|
const bookingData = await createBookingScenario(
|
|
getScenarioData({
|
|
workflows: [
|
|
{
|
|
userId: originalHost.id,
|
|
trigger: "NEW_EVENT",
|
|
action: "EMAIL_HOST",
|
|
template: "REMINDER",
|
|
activeEventTypeId: 1,
|
|
},
|
|
],
|
|
eventTypes: [
|
|
{
|
|
id: 1,
|
|
slug: "round-robin-event",
|
|
schedulingType: SchedulingType.ROUND_ROBIN,
|
|
length: 45,
|
|
users: users.map((user) => {
|
|
return {
|
|
id: user.id,
|
|
};
|
|
}),
|
|
hosts: users.map((user) => {
|
|
return {
|
|
userId: user.id,
|
|
isFixed: false,
|
|
};
|
|
}),
|
|
},
|
|
],
|
|
bookings: [
|
|
{
|
|
id: 123,
|
|
eventTypeId: 1,
|
|
userId: originalHost.id,
|
|
uid: bookingToReassignUid,
|
|
status: BookingStatus.ACCEPTED,
|
|
startTime: `${dateStringPlusOne}T05:00:00.000Z`,
|
|
endTime: `${dateStringPlusOne}T05:15:00.000Z`,
|
|
attendees: [
|
|
getMockBookingAttendee({
|
|
id: 2,
|
|
name: "attendee",
|
|
email: "attendee@test.com",
|
|
locale: "en",
|
|
timeZone: "Asia/Kolkata",
|
|
}),
|
|
],
|
|
},
|
|
{
|
|
id: 456,
|
|
eventTypeId: 1,
|
|
userId: users[2].id,
|
|
uid: bookingToReassignUid,
|
|
status: BookingStatus.ACCEPTED,
|
|
startTime: `${dateStringMinusOne}T05:00:00.000Z`,
|
|
endTime: `${dateStringMinusOne}T05:15:00.000Z`,
|
|
attendees: [
|
|
getMockBookingAttendee({
|
|
id: 2,
|
|
name: "attendee",
|
|
email: "attendee@test.com",
|
|
locale: "en",
|
|
timeZone: "Asia/Kolkata",
|
|
}),
|
|
],
|
|
},
|
|
],
|
|
organizer: originalHost,
|
|
usersApartFromOrganizer: users.slice(1),
|
|
})
|
|
);
|
|
await addWorkflowReminders([
|
|
{
|
|
bookingUid: bookingToReassignUid,
|
|
method: WorkflowMethods.EMAIL,
|
|
scheduledDate: dateStringPlusTwo,
|
|
scheduled: true,
|
|
workflowStepId: 1,
|
|
workflowId: 1,
|
|
},
|
|
]);
|
|
|
|
await roundRobinReassignment({
|
|
bookingId: 123,
|
|
orgId: null,
|
|
reassignedById: originalHost.id,
|
|
actionSource: "WEBAPP",
|
|
reassignedByUuid: originalHost.uuid,
|
|
});
|
|
|
|
expect(eventManagerSpy).toBeCalledTimes(1);
|
|
// Triggers moving to new host within event manager
|
|
expect(eventManagerSpy).toHaveBeenCalledWith(
|
|
expect.any(Object),
|
|
bookingToReassignUid,
|
|
undefined,
|
|
true,
|
|
expect.arrayContaining([expect.objectContaining(testDestinationCalendar)]),
|
|
undefined,
|
|
true
|
|
);
|
|
|
|
// Use equal fairness rr algorithm
|
|
expectBookingToBeInDatabase({
|
|
uid: bookingToReassignUid,
|
|
userId: newHost.id,
|
|
});
|
|
|
|
expectSuccessfulRoundRobinReschedulingEmails({
|
|
prevOrganizer: originalHost,
|
|
newOrganizer: newHost,
|
|
emails,
|
|
});
|
|
|
|
expectWorkflowToBeTriggered({ emailsToReceive: [newHost.email], emails });
|
|
});
|
|
|
|
// TODO: add fixed hosts test
|
|
test("Reassign round robin host with fixed host as organizer", async () => {
|
|
const roundRobinReassignment = (await import("./roundRobinReassignment")).default;
|
|
const EventManager = (await import("@calcom/features/bookings/lib/EventManager")).default;
|
|
|
|
const eventManagerSpy = vi.spyOn(EventManager.prototype as any, "reschedule");
|
|
// Clear any existing mock calls from previous tests
|
|
eventManagerSpy.mockClear();
|
|
|
|
const users = testUsers;
|
|
|
|
const bookingToReassignUid = "booking-to-reassign";
|
|
|
|
const fixedHost = users[0];
|
|
const currentRRHost = users[1];
|
|
const newHost = users[2];
|
|
// Assume we are using the RR fairness algorithm. Add an extra booking for user[2] to ensure user[1] is the new host
|
|
const { dateString: dateStringPlusOne } = getDate({ dateIncrement: 1 });
|
|
|
|
await createBookingScenario(
|
|
getScenarioData({
|
|
workflows: [
|
|
{
|
|
userId: fixedHost.id,
|
|
trigger: "NEW_EVENT",
|
|
action: "EMAIL_HOST",
|
|
template: "REMINDER",
|
|
activeEventTypeId: 1,
|
|
},
|
|
],
|
|
eventTypes: [
|
|
{
|
|
id: 1,
|
|
slug: "round-robin-event",
|
|
schedulingType: SchedulingType.ROUND_ROBIN,
|
|
length: 45,
|
|
users: users.map((user) => {
|
|
return {
|
|
id: user.id,
|
|
};
|
|
}),
|
|
hosts: users.map((user) => {
|
|
return {
|
|
userId: user.id,
|
|
isFixed: !!(user.id === fixedHost.id),
|
|
};
|
|
}),
|
|
},
|
|
],
|
|
bookings: [
|
|
{
|
|
id: 123,
|
|
eventTypeId: 1,
|
|
userId: fixedHost.id,
|
|
uid: bookingToReassignUid,
|
|
status: BookingStatus.ACCEPTED,
|
|
startTime: `${dateStringPlusOne}T05:00:00.000Z`,
|
|
endTime: `${dateStringPlusOne}T05:15:00.000Z`,
|
|
attendees: [
|
|
getMockBookingAttendee({
|
|
id: 1,
|
|
name: "attendee",
|
|
email: "attendee@test.com",
|
|
locale: "en",
|
|
timeZone: "Asia/Kolkata",
|
|
}),
|
|
getMockBookingAttendee({
|
|
id: currentRRHost.id,
|
|
name: currentRRHost.name,
|
|
email: currentRRHost.email,
|
|
locale: "en",
|
|
timeZone: currentRRHost.timeZone,
|
|
}),
|
|
],
|
|
},
|
|
],
|
|
organizer: fixedHost,
|
|
usersApartFromOrganizer: users.slice(1),
|
|
})
|
|
);
|
|
|
|
await roundRobinReassignment({
|
|
bookingId: 123,
|
|
orgId: null,
|
|
reassignedById: fixedHost.id,
|
|
});
|
|
|
|
expect(eventManagerSpy).toBeCalledTimes(1);
|
|
// Triggers moving to new host within event manager
|
|
expect(eventManagerSpy).toHaveBeenCalledWith(
|
|
expect.any(Object),
|
|
bookingToReassignUid,
|
|
undefined,
|
|
false,
|
|
[],
|
|
undefined,
|
|
false
|
|
);
|
|
|
|
// Ensure organizer stays the same
|
|
expectBookingToBeInDatabase({
|
|
uid: bookingToReassignUid,
|
|
userId: 1,
|
|
});
|
|
|
|
const bookingRepo = new BookingRepository(prismaMock);
|
|
const attendees = await bookingRepo.getBookingAttendees(123);
|
|
|
|
expect(attendees.some((attendee) => attendee.email === currentRRHost.email)).toBe(false);
|
|
|
|
expect(attendees.some((attendee) => attendee.email === newHost.email)).toBe(true);
|
|
});
|
|
|
|
test("should not expose other attendees in updated email when seatsShowAttendees is disabled for seated round-robin event", async ({
|
|
emails,
|
|
}) => {
|
|
const roundRobinReassignment = (await import("./roundRobinReassignment")).default;
|
|
const EventManager = (await import("@calcom/features/bookings/lib/EventManager")).default;
|
|
|
|
const eventManagerSpy = vi.spyOn(EventManager.prototype as any, "reschedule");
|
|
eventManagerSpy.mockClear();
|
|
eventManagerSpy.mockResolvedValue({ referencesToCreate: [] });
|
|
|
|
const users = testUsers;
|
|
const originalHost = users[0];
|
|
const newHost = users[1];
|
|
|
|
const { dateString: dateStringPlusOne } = getDate({ dateIncrement: 1 });
|
|
const { dateString: dateStringMinusOne } = getDate({ dateIncrement: -1 });
|
|
|
|
const bookingToReassignUid = "seated-booking-to-reassign";
|
|
const attendee1Email = "attendee1@test.com";
|
|
const attendee2Email = "attendee2@test.com";
|
|
const attendee3Email = "attendee3@test.com";
|
|
|
|
await createBookingScenario(
|
|
getScenarioData({
|
|
eventTypes: [
|
|
{
|
|
id: 1,
|
|
slug: "round-robin-seated-event",
|
|
schedulingType: SchedulingType.ROUND_ROBIN,
|
|
length: 45,
|
|
seatsPerTimeSlot: 5,
|
|
seatsShowAttendees: false,
|
|
users: users.map((user) => ({ id: user.id })),
|
|
hosts: users.map((user) => ({ userId: user.id, isFixed: false })),
|
|
},
|
|
],
|
|
bookings: [
|
|
{
|
|
id: 123,
|
|
eventTypeId: 1,
|
|
userId: originalHost.id,
|
|
uid: bookingToReassignUid,
|
|
status: BookingStatus.ACCEPTED,
|
|
startTime: `${dateStringPlusOne}T05:00:00.000Z`,
|
|
endTime: `${dateStringPlusOne}T05:15:00.000Z`,
|
|
attendees: [
|
|
{
|
|
...getMockBookingAttendee({
|
|
id: 2,
|
|
name: "Attendee 1",
|
|
email: attendee1Email,
|
|
locale: "en",
|
|
timeZone: "Asia/Kolkata",
|
|
}),
|
|
bookingSeat: {
|
|
referenceUid: uuidv4(),
|
|
data: {},
|
|
},
|
|
},
|
|
{
|
|
...getMockBookingAttendee({
|
|
id: 3,
|
|
name: "Attendee 2",
|
|
email: attendee2Email,
|
|
locale: "en",
|
|
timeZone: "Asia/Kolkata",
|
|
}),
|
|
bookingSeat: {
|
|
referenceUid: uuidv4(),
|
|
data: {},
|
|
},
|
|
},
|
|
{
|
|
...getMockBookingAttendee({
|
|
id: 4,
|
|
name: "Attendee 3",
|
|
email: attendee3Email,
|
|
locale: "en",
|
|
timeZone: "Asia/Kolkata",
|
|
}),
|
|
bookingSeat: {
|
|
referenceUid: uuidv4(),
|
|
data: {},
|
|
},
|
|
},
|
|
],
|
|
},
|
|
{
|
|
id: 456,
|
|
eventTypeId: 1,
|
|
userId: users[2].id,
|
|
uid: "other-booking",
|
|
status: BookingStatus.ACCEPTED,
|
|
startTime: `${dateStringMinusOne}T05:00:00.000Z`,
|
|
endTime: `${dateStringMinusOne}T05:15:00.000Z`,
|
|
attendees: [
|
|
getMockBookingAttendee({
|
|
id: 5,
|
|
name: "attendee",
|
|
email: "attendee@test.com",
|
|
locale: "en",
|
|
timeZone: "Asia/Kolkata",
|
|
}),
|
|
],
|
|
},
|
|
],
|
|
organizer: originalHost,
|
|
usersApartFromOrganizer: users.slice(1),
|
|
})
|
|
);
|
|
|
|
await roundRobinReassignment({
|
|
bookingId: 123,
|
|
orgId: null,
|
|
reassignedById: originalHost.id,
|
|
actionSource: "WEBAPP",
|
|
reassignedByUuid: originalHost.uuid,
|
|
});
|
|
|
|
expect(eventManagerSpy).toBeCalledTimes(1);
|
|
|
|
// Verify that updated emails were sent to all attendees
|
|
const updatedEmails = emails.get().filter((email) => {
|
|
const subject = email.subject || "";
|
|
return subject.includes("updated") || subject.includes("event_type_has_been_updated");
|
|
});
|
|
|
|
// Check that each attendee received an email
|
|
expect(updatedEmails.some((email) => email.to.includes(attendee1Email))).toBe(true);
|
|
expect(updatedEmails.some((email) => email.to.includes(attendee2Email))).toBe(true);
|
|
expect(updatedEmails.some((email) => email.to.includes(attendee3Email))).toBe(true);
|
|
|
|
// Verify that each attendee's email does not contain other attendees' information
|
|
const attendee1EmailContent = updatedEmails.find((email) => email.to.includes(attendee1Email));
|
|
if (attendee1EmailContent) {
|
|
const emailHtml = parse(attendee1EmailContent.html);
|
|
const emailText = emailHtml.innerText;
|
|
|
|
// Should not contain other attendees' emails or names
|
|
expect(emailText).not.toContain(attendee2Email);
|
|
expect(emailText).not.toContain(attendee3Email);
|
|
expect(emailText).not.toContain("Attendee 2");
|
|
expect(emailText).not.toContain("Attendee 3");
|
|
// Should contain their own info
|
|
expect(emailText).toContain("Attendee 1");
|
|
}
|
|
|
|
const attendee2EmailContent = updatedEmails.find((email) => email.to.includes(attendee2Email));
|
|
if (attendee2EmailContent) {
|
|
const emailHtml = parse(attendee2EmailContent.html);
|
|
const emailText = emailHtml.innerText;
|
|
|
|
// Should not contain other attendees' emails or names
|
|
expect(emailText).not.toContain(attendee1Email);
|
|
expect(emailText).not.toContain(attendee3Email);
|
|
expect(emailText).not.toContain("Attendee 1");
|
|
expect(emailText).not.toContain("Attendee 3");
|
|
// Should contain their own info
|
|
expect(emailText).toContain("Attendee 2");
|
|
}
|
|
|
|
const attendee3EmailContent = updatedEmails.find((email) => email.to.includes(attendee3Email));
|
|
if (attendee3EmailContent) {
|
|
const emailHtml = parse(attendee3EmailContent.html);
|
|
const emailText = emailHtml.innerText;
|
|
|
|
// Should not contain other attendees' emails or names
|
|
expect(emailText).not.toContain(attendee1Email);
|
|
expect(emailText).not.toContain(attendee2Email);
|
|
expect(emailText).not.toContain("Attendee 1");
|
|
expect(emailText).not.toContain("Attendee 2");
|
|
// Should contain their own info
|
|
expect(emailText).toContain("Attendee 3");
|
|
}
|
|
});
|
|
});
|
|
|
|
describe("roundRobinReassignment - Audit Data Verification", () => {
|
|
setupAndTeardown();
|
|
|
|
test("should call BookingEventHandlerService.onReassignment with correct audit data when organizer changes", async () => {
|
|
const roundRobinReassignment = (await import("./roundRobinReassignment")).default;
|
|
const EventManager = (await import("@calcom/features/bookings/lib/EventManager")).default;
|
|
|
|
const eventManagerSpy = vi.spyOn(EventManager.prototype as any, "reschedule");
|
|
eventManagerSpy.mockClear();
|
|
eventManagerSpy.mockResolvedValue({ referencesToCreate: [] });
|
|
|
|
const mockOnReassignment = vi.fn().mockResolvedValue(undefined);
|
|
vi.mocked(getBookingEventHandlerService).mockReturnValue({
|
|
onReassignment: mockOnReassignment,
|
|
} as any);
|
|
|
|
const users = testUsers;
|
|
const originalHost = users[0];
|
|
const newHost = users[1];
|
|
const reassigningUser = users[0]; // originalHost is doing the reassignment
|
|
|
|
const { dateString: dateStringPlusOne } = getDate({ dateIncrement: 1 });
|
|
const { dateString: dateStringMinusOne } = getDate({ dateIncrement: -1 });
|
|
const { dateString: dateStringPlusTwo } = getDate({ dateIncrement: 2 });
|
|
|
|
const bookingToReassignUid = "booking-audit-test";
|
|
|
|
await createBookingScenario(
|
|
getScenarioData({
|
|
eventTypes: [
|
|
{
|
|
id: 1,
|
|
slug: "round-robin-event",
|
|
schedulingType: SchedulingType.ROUND_ROBIN,
|
|
length: 45,
|
|
users: users.map((user) => ({ id: user.id })),
|
|
hosts: users.map((user) => ({ userId: user.id, isFixed: false })),
|
|
},
|
|
],
|
|
bookings: [
|
|
{
|
|
id: 123,
|
|
eventTypeId: 1,
|
|
userId: originalHost.id,
|
|
uid: bookingToReassignUid,
|
|
status: BookingStatus.ACCEPTED,
|
|
startTime: `${dateStringPlusOne}T05:00:00.000Z`,
|
|
endTime: `${dateStringPlusOne}T05:15:00.000Z`,
|
|
attendees: [
|
|
getMockBookingAttendee({
|
|
id: 2,
|
|
name: "attendee",
|
|
email: "attendee@test.com",
|
|
locale: "en",
|
|
timeZone: "Asia/Kolkata",
|
|
}),
|
|
],
|
|
},
|
|
{
|
|
id: 456,
|
|
eventTypeId: 1,
|
|
userId: users[2].id,
|
|
uid: "other-booking",
|
|
status: BookingStatus.ACCEPTED,
|
|
startTime: `${dateStringMinusOne}T05:00:00.000Z`,
|
|
endTime: `${dateStringMinusOne}T05:15:00.000Z`,
|
|
attendees: [
|
|
getMockBookingAttendee({
|
|
id: 2,
|
|
name: "attendee",
|
|
email: "attendee@test.com",
|
|
locale: "en",
|
|
timeZone: "Asia/Kolkata",
|
|
}),
|
|
],
|
|
},
|
|
],
|
|
organizer: originalHost,
|
|
usersApartFromOrganizer: users.slice(1),
|
|
})
|
|
);
|
|
|
|
await roundRobinReassignment({
|
|
bookingId: 123,
|
|
orgId: null,
|
|
reassignedById: reassigningUser.id,
|
|
actionSource: "WEBAPP",
|
|
reassignedByUuid: reassigningUser.uuid,
|
|
});
|
|
|
|
expect(mockOnReassignment).toHaveBeenCalledTimes(1);
|
|
expect(mockOnReassignment).toHaveBeenCalledWith({
|
|
bookingUid: bookingToReassignUid,
|
|
actor: { identifiedBy: "user", userUuid: reassigningUser.uuid },
|
|
organizationId: null,
|
|
source: "WEBAPP",
|
|
auditData: {
|
|
organizerUuid: { old: originalHost.uuid, new: newHost.uuid },
|
|
reassignmentReason: null,
|
|
reassignmentType: "roundRobin",
|
|
},
|
|
isBookingAuditEnabled: false,
|
|
});
|
|
});
|
|
|
|
test("should call BookingEventHandlerService.onReassignment with correct audit data when only attendee changes (fixed host scenario)", async () => {
|
|
const roundRobinReassignment = (await import("./roundRobinReassignment")).default;
|
|
const EventManager = (await import("@calcom/features/bookings/lib/EventManager")).default;
|
|
|
|
const eventManagerSpy = vi.spyOn(EventManager.prototype as any, "reschedule");
|
|
eventManagerSpy.mockClear();
|
|
eventManagerSpy.mockResolvedValue({ referencesToCreate: [] });
|
|
|
|
const mockOnReassignment = vi.fn().mockResolvedValue(undefined);
|
|
vi.mocked(getBookingEventHandlerService).mockReturnValue({
|
|
onReassignment: mockOnReassignment,
|
|
} as any);
|
|
|
|
const users = testUsers;
|
|
const fixedHost = users[0];
|
|
const currentRRHost = users[1];
|
|
const newHost = users[2];
|
|
const reassigningUser = fixedHost;
|
|
|
|
const { dateString: dateStringPlusOne } = getDate({ dateIncrement: 1 });
|
|
|
|
const bookingToReassignUid = "booking-audit-fixed-host-test";
|
|
|
|
await createBookingScenario(
|
|
getScenarioData({
|
|
eventTypes: [
|
|
{
|
|
id: 1,
|
|
slug: "round-robin-event",
|
|
schedulingType: SchedulingType.ROUND_ROBIN,
|
|
length: 45,
|
|
users: users.map((user) => ({ id: user.id })),
|
|
hosts: users.map((user) => ({
|
|
userId: user.id,
|
|
isFixed: user.id === fixedHost.id,
|
|
})),
|
|
},
|
|
],
|
|
bookings: [
|
|
{
|
|
id: 123,
|
|
eventTypeId: 1,
|
|
userId: fixedHost.id,
|
|
uid: bookingToReassignUid,
|
|
status: BookingStatus.ACCEPTED,
|
|
startTime: `${dateStringPlusOne}T05:00:00.000Z`,
|
|
endTime: `${dateStringPlusOne}T05:15:00.000Z`,
|
|
attendees: [
|
|
getMockBookingAttendee({
|
|
id: 1,
|
|
name: "attendee",
|
|
email: "attendee@test.com",
|
|
locale: "en",
|
|
timeZone: "Asia/Kolkata",
|
|
}),
|
|
getMockBookingAttendee({
|
|
id: currentRRHost.id,
|
|
name: currentRRHost.name,
|
|
email: currentRRHost.email,
|
|
locale: "en",
|
|
timeZone: currentRRHost.timeZone,
|
|
}),
|
|
],
|
|
},
|
|
],
|
|
organizer: fixedHost,
|
|
usersApartFromOrganizer: users.slice(1),
|
|
})
|
|
);
|
|
|
|
await roundRobinReassignment({
|
|
bookingId: 123,
|
|
orgId: null,
|
|
reassignedById: reassigningUser.id,
|
|
actionSource: "WEBAPP",
|
|
reassignedByUuid: reassigningUser.uuid,
|
|
});
|
|
|
|
expect(mockOnReassignment).toHaveBeenCalledTimes(1);
|
|
const callArgs = mockOnReassignment.mock.calls[0][0];
|
|
expect(callArgs.bookingUid).toBe(bookingToReassignUid);
|
|
expect(callArgs.actor).toEqual({ identifiedBy: "user", userUuid: reassigningUser.uuid });
|
|
expect(callArgs.organizationId).toBe(null);
|
|
expect(callArgs.source).toBe("WEBAPP");
|
|
expect(callArgs.isBookingAuditEnabled).toBe(false);
|
|
// organizerUuid should NOT be included when organizer hasn't changed (fixed host scenario)
|
|
expect(callArgs.auditData.organizerUuid).toBeUndefined();
|
|
expect(callArgs.auditData.reassignmentType).toBe("roundRobin");
|
|
expect(callArgs.auditData.reassignmentReason).toBe(null);
|
|
expect(callArgs.auditData.hostAttendeeUpdated).toBeDefined();
|
|
expect(callArgs.auditData.hostAttendeeUpdated?.withUserUuid).toEqual({
|
|
old: currentRRHost.uuid,
|
|
new: newHost.uuid,
|
|
});
|
|
});
|
|
});
|