* Integrate creation/rescheduling booking audit * fix: add missing hostUserUuid to booking audit test data Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix-ci * feat: enhance booking audit with seat reference - Added support for seat reference in booking audit actions. - Updated localization for booking creation to include seat information. - Modified relevant services to pass attendee seat ID during booking creation. * fix: update test data to match schema requirements - Add seatReferenceUid: null to default mock audit log data - Add seatReferenceUid: null to multiple audit logs test case - Convert SEAT_RESCHEDULED test data to use numeric timestamps instead of ISO strings Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * Allow nullish seatReferenceUid * feat: enhance booking audit to support rescheduledBy information - Updated booking audit actions to include rescheduledBy details, allowing tracking of who rescheduled a booking. - Refactored related services to accommodate the new rescheduledBy parameter in booking events. - Adjusted type definitions and function signatures to reflect the changes in the booking audit context. * Avoid possible run time issue * Fix imoport path * fix failing test due to merge from main\ * Pass useruuid * chore: retrigger CI (flaky unit test) Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * feat: add context parameter to bulk audit methods for impersonation support - Add context parameter to queueBulkCreatedAudit and queueBulkRescheduledAudit in BookingAuditProducerService interface - Add context parameter to BookingAuditTaskerProducerService implementation - Add context parameter to onBulkBookingsCreated and onBulkBookingsRescheduled in BookingEventHandlerService - Update RegularBookingService.fireBookingEvents to accept and pass impersonation context - Update RecurringBookingService.fireBookingEvents to accept and pass impersonation context - Update handleSeats to accept and pass impersonation context Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * chore: Integrate mark-no-show booking audit Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: Simplify host no-show audit and add comment for attendee actor Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * feat: make impersonatedByUserUuid required with explicit null for non-impersonation cases Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * feat: integrate impersonatedByUserUuid into booking cancellation audit flow - Add impersonatedByUserUuid to CancelBookingInput and CancelBookingMeta types - Pass audit context with impersonatedBy to onBookingCancelled and onBulkBookingsCancelled - Update all cancel booking call sites to pass impersonatedByUserUuid: - Web app cancel route: uses session impersonatedBy - API v1 and v2: explicitly set to null (no impersonation support) Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * refactor: make impersonatedByUserUuid optional and remove explicit null assignments - Changed impersonatedByUserUuid from required (string | null) to optional (string?) - Removed explicit null assignments from API v1 and v2 endpoints - Keep impersonatedByUserUuid only where impersonation actually occurs (web app) Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * Apply suggestions from code review Rfemove unnecessary comment * fix: restore bookingMeta variable in createBookingForApiV1 Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: Make actionSource required with ValidActionSource type and remove unnecessary comments Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: Remove merge conflict markers from bookings.service.ts Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * feat: implement SYSTEM as a booking audit source for background tasks, including no-show triggers. * refactor: Move prisma query to BookingRepository for audit logging Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * Conflict resolution * refactor: introduce `handleMarkHostNoShow` for public viewer and standardize actor and action source parameters for no-show actions. * refactor: Combine HostNoShowUpdatedAuditActionService and AttendeeNoShowUpdatedAuditActionService into NoShowUpdatedActionService - Create new NoShowUpdatedAuditActionService with combined schema supporting both noShowHost and noShowAttendee as optional fields - Update BookingAuditActionServiceRegistry to use combined service with NO_SHOW_UPDATED action type - Update BookingAuditTaskerProducerService with single queueNoShowUpdatedAudit method - Update BookingAuditProducerService.interface.ts with combined method - Update BookingEventHandlerService with single onNoShowUpdated method - Update handleMarkNoShow.ts to use combined audit service - Update tasker tasks (triggerGuestNoShow, triggerHostNoShow) to use combined service - Add NO_SHOW_UPDATED to Prisma BookingAuditAction enum - Remove old separate HostNoShowUpdatedAuditActionService and AttendeeNoShowUpdatedAuditActionService files This allows a single API action (e.g., API V2 markAbsent) that updates both host and attendee no-show status to be logged as a single audit event. Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * chore: Add migration for NO_SHOW_UPDATED audit action enum value Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * refactor: Update no-show audit schema to use host and attendees array - Rename noShowHost to host and noShowAttendee to attendees (remove redundant prefix) - Change attendees from single value to array to support multiple attendees in single audit entry - Update handleMarkNoShow.ts to create single audit entry for all attendees - Update tasker tasks (triggerGuestNoShow, triggerHostNoShow) to use new schema - Update display data types to reflect new schema structure Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * Update schema to be more clear. Call onNoShowUpdated immediately after DB update as audit only cares about DB update, and this would avoid any accidental Audit update on DB change * chore: accommodate schema changes and fix type errors for no-show audit Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: Update migration to remove old no-show enum values Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: Use updated attendees in webhook payload for guest no-show Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: Remove duplicate imports and fix actor parameter in bookings.service.ts Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * refactor: Move booking query to BookingRepository and remove unused method Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * refactor: centralize no-show audit event firing and attendee fetching within `handleMarkNoShow` for improved clarity. * fix: Build attendeesNoShow as Record with attendee IDs as keys Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * Fix and add tests for handleMarkBoShow * refactor: Move prisma queries to AttendeeRepository and BookingRepository Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: Correct return type for updateNoShow method (noShow can be null) Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: Update handleMarkNoShow tests to mock new repository methods Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix triggerGuestNoShow * refactor: Move triggerGuestNoShow queries to AttendeeRepository and add unit tests - Add new methods to AttendeeRepository: - findByBookingId: Get attendees with id, email, noShow - findByBookingIdWithDetails: Get full attendee details - updateManyNoShowByBookingIdAndEmails: Update specific attendees - updateManyNoShowByBookingIdExcludingEmails: Update all except specific emails - Refactor triggerGuestNoShow.ts to use AttendeeRepository instead of direct Prisma calls - Add comprehensive unit tests for triggerGuestNoShow following handleMarkNoShow.test.ts pattern: - Mock repositories and external services - In-memory DB simulation - Test core functionality, audit logging, webhook payload, error handling, and edge cases Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * refactor: Move triggerHostNoShow queries to repositories and delete unit test file Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * refactor: Convert repository methods to use named parameters objects Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * refactor: Enhance no-show handling by consolidating audit logging and updating repository interactions - Refactor `buildResultPayload` to accept a structured argument for better clarity. - Update `updateAttendees` to use a named parameter object for improved readability. - Introduce `fireNoShowUpdatedEvent` to centralize no-show audit logging for both hosts and guests. - Remove redundant methods and streamline attendee retrieval in `AttendeeRepository`. - Add comprehensive unit tests for no-show event handling, ensuring accurate audit logging and webhook triggering. * test: Add tests for handleMarkHostNoShow guest actor and unmarking host no-show Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: update attendeesNoShow validation to handle numeric keys - Changed attendeesNoShow schema to use z.coerce.number() for key validation, ensuring string keys are correctly coerced to numbers. - Updated test to validate attendeesNoShow data using numeric key comparison, improving robustness of the audit data checks. * test: Add integration tests for NoShowUpdatedAuditActionService coerce fix Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * feat: add graceful error handling for audit log enrichment - Add hasError field to EnrichedAuditLog type - Create buildFallbackAuditLog() method for failed enrichments - Wrap enrichAuditLog() in try-catch to handle errors gracefully - Add booking_audit_action.error_processing translation key - Update BookingHistory.tsx to show warning icon for error logs - Hide 'Show details' button for logs with hasError - Add comprehensive test cases for error handling scenarios Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * feat: Enhance booking audit action services with new display fields and improved validation - Added "attendee_no_show_updated" and "no_show_updated" translations to common.json. - Updated IAuditActionService to include new methods for handling display fields and migration. - Enhanced NoShowUpdatedAuditActionService to differentiate between host and attendee no-show updates. - Improved ReassignmentAuditActionService to ensure consistent handling of audit data. - Refactored BookingAuditViewerService for better clarity and maintainability. * refactor: Use attendeeEmail instead of attendeeId as key in audit data and store host's userUuid - Updated schema to use attendee email as key instead of attendee ID because attendee records can be reused with different person's data - Store host's userUuid in audit data with format: host: { userUuid, noShow: { old, new } } - Updated fireNoShowUpdated to accept hostUserUuid parameter - Added uuid field to BookingRepository.findByUidIncludeEventTypeAttendeesAndUser - Updated NoShowUpdatedAuditActionService getDisplayFields to work with email-based keys - Added attendeeRepository to DI modules for BookingAuditTaskConsumer - Updated tests to match new schema format Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * test: Update integration tests to use new schema format with host.userUuid and email keys Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: correct audit schema for SYSTEM source and ensure attendee lookup by bookingId - Fix schema inconsistency: use host.userUuid format instead of hostNoShow - Add user.uuid to getBooking select for audit logging - Log warning when hostUserUuid is undefined but host no-show is being updated - Use email as key for attendeesNoShow (not attendee ID) to match schema - Fetch attendees by bookingId before updating to ensure correct scoping - Remove unused safeStringify import * refactor: Change attendeesNoShow schema from Record to Array format - Update NoShowUpdatedAuditActionService schema to use array format: attendeesNoShow: Array<{attendeeEmail: string, noShow: {old, new}}> - Update handleMarkNoShow.ts to build attendeesNoShow as array - Update common.ts fireNoShowUpdatedEvent to convert Map to array - Update all tests to use new array format with attendeeEmail property Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * refactor: Update attendeesNoShow schema to use array format in triggerNoShow tasks - Refactor `triggerGuestNoShow` and `triggerHostNoShow` to replace Map with array for `attendeesNoShowAudit`. - Update `fireNoShowUpdatedEvent` to handle the new array format for attendees. - Ensure consistent data structure across no-show audit logging for better clarity and maintainability. * fix: Update ReassignmentAuditActionService to use GetDisplayFieldsParams interface Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: Update ReassignmentAuditActionService tests to use GetDisplayFieldsParams interface Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: Use handleMarkAttendeeNoShow for API v2 mark absent endpoint - Export handleMarkAttendeeNoShow from platform-libraries - Update API v2 bookings service to use handleMarkAttendeeNoShow with actionSource - Add validation for userUuid before calling handleMarkAttendeeNoShow Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * refactor: Enhance display fields structure in booking audit components - Updated `BookingHistory.tsx` to allow for more flexible display fields, including optional raw values and arrays of values. - Introduced `DisplayFieldValue` component for rendering display fields, improving clarity and maintainability. - Adjusted `IAuditActionService` and `NoShowUpdatedAuditActionService` to align with the new display fields structure. - Ensured consistent handling of display fields across the booking audit service for better data representation. * fix: Remove debug code that duplicated first attendee in display fields Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * refactor: Update attendee repository methods to use structured parameters - Modified `updateNoShow`, `updateManyNoShowByBookingIdAndEmails`, and `updateManyNoShowByBookingIdExcludingEmails` methods to accept structured `where` and `data` parameters for better clarity and maintainability. - Updated calls to these methods throughout the codebase to reflect the new parameter structure. - Removed unused `findByIdWithNoShow` method and adjusted related logic to streamline attendee data retrieval. * feat: Add infrastructure for no-show audit integration - Add Prisma migrations for SYSTEM source and NO_SHOW_UPDATED audit action - Add NoShowUpdatedAuditActionService with array-based attendeesNoShow schema - Update BookingAuditActionServiceRegistry to include NO_SHOW_UPDATED - Update BookingAuditTaskConsumer and BookingAuditViewerService - Add AttendeeRepository methods for no-show queries - Update IAuditActionService interface with values array support - Update locales with no-show audit translation keys Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: Add NO_SHOW_UPDATED to BookingAuditAction and SYSTEM to ActionSource types Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: Remove HOST_NO_SHOW_UPDATED and ATTENDEE_NO_SHOW_UPDATED from BookingAuditAction type to match Prisma schema Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: Update BookingAuditActionSchema to use NO_SHOW_UPDATED instead of HOST_NO_SHOW_UPDATED and ATTENDEE_NO_SHOW_UPDATED Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * refactor: Remove deprecated no-show audit services and unify to NoShowUpdatedAuditActionService - Delete HostNoShowUpdatedAuditActionService and AttendeeNoShowUpdatedAuditActionService - Update BookingAuditProducerService.interface.ts to use queueNoShowUpdatedAudit - Update BookingAuditTaskerProducerService.ts to use queueNoShowUpdatedAudit - Update BookingEventHandlerService.ts to use onNoShowUpdated - Add integration tests for NoShowUpdatedAuditActionService Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: Update test mock to match new AttendeeRepository.updateNoShow signature Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * refactor: rename handleMarkAttendeeNoShow to handleMarkNoShow and update related types - Renamed `handleMarkAttendeeNoShow` to `handleMarkNoShow` for clarity. - Updated type definitions to reflect the new naming convention. - Modified the `markNoShow` handler to require `userUuid` and adjusted related logic. - Enhanced the `fireNoShowUpdatedEvent` to accommodate changes in event type structure. - Updated references across various files to ensure consistency with the new function name. * handle null value * fix: add explicit parentheses for operator precedence clarity Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * Fix cubic reported bug * feat: add impersonation audit support to no-show flow (#27601) Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * feat: add impersonatedByUserUuid context to all BookingEventHandler calls (#27602) - Add context parameter to confirm.handler.ts (onBulkBookingsRejected, onBookingRejected) - Add context parameter to requestReschedule.handler.ts (onRescheduleRequested) - Add context parameter to editLocation.handler.ts (onLocationChanged) - Add context parameter to addGuests.handler.ts (onAttendeeAdded) - Add context parameter to handleConfirmation.ts (onBulkBookingsAccepted, onBookingAccepted) - Update _router.tsx to pass impersonatedByUserUuid from session to handlers This ensures all BookingEventHandler method calls that have loggedInUser context now properly support impersonation tracking for audit logging. Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix: remove stray merge artifact in RegularBookingService Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: remove duplicate imports in BookingRepository Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: resolve type errors and duplicate declarations from merge Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: remove duplicate test assertions and duplicate test from merge artifacts Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: remove redundant ?? undefined from impersonatedByUserUuid Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: update impersonatedByUserUuid type to string | null for consistency Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: make impersonatedByUserUuid required in booking audit flows Changes impersonatedByUserUuid from optional (?: string | null) to required (: string | null) in all booking-related type definitions. This ensures audit-critical parameters are never accidentally omitted. Fixed all call sites to explicitly pass the value or null. Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: add impersonatedByUserUuid to remaining callers and tests Adds impersonatedByUserUuid: null to API v1, API v2, and test callers of handleCancelBooking that were missing the now-required parameter. Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: require impersonatedByUserUuid in DTOs and pass it across all booking flows (coalesce to null) Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: add impersonatedByUserUuid to remaining call sites (confirm, markNoShow, webhook, tests) Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: add impersonatedByUserUuid to confirm handler test and API v2 confirm/decline calls Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: derive impersonatedByUserUuid from session in reportBooking handler instead of hardcoding null Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: reorder spread to ensure impersonatedByUserUuid null fallback is not overwritten Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: add missing impersonatedByUserUuid to CalendarSyncService cancel and reschedule calls Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: update CalendarSyncService tests to expect impersonatedByUserUuid Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * ci: retrigger failed checks (attempt 1) Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * ci: retrigger failed checks (attempt 2) Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * ci: retrigger failed checks (attempt 3) Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * chore: bust prisma cache with comment change Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * ci: retrigger after cache bust (attempt 2) Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * ci: retrigger after cache bust (attempt 3) Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Co-authored-by: Volnei Munhoz <volnei@cal.com>
628 lines
20 KiB
TypeScript
628 lines
20 KiB
TypeScript
import {
|
|
createBookingScenario,
|
|
getOrganizer,
|
|
getScenarioData,
|
|
TestData,
|
|
mockSuccessfulVideoMeetingCreation,
|
|
} from "@calcom/testing/lib/bookingScenario/bookingScenario";
|
|
|
|
import { describe, it, beforeEach, vi, expect } from "vitest";
|
|
|
|
import * as handleConfirmationModule from "@calcom/features/bookings/lib/handleConfirmation";
|
|
import { distributedTracing } from "@calcom/lib/tracing/factory";
|
|
import { BookingStatus } from "@calcom/prisma/enums";
|
|
import { confirmHandler } from "@calcom/trpc/server/routers/viewer/bookings/confirm.handler";
|
|
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
|
|
import { makeUserActor } from "@calcom/features/booking-audit/lib/makeActor";
|
|
import { getBookingEventHandlerService } from "@calcom/features/bookings/di/BookingEventHandlerService.container";
|
|
|
|
vi.mock("@calcom/features/bookings/di/BookingEventHandlerService.container", () => {
|
|
const onBookingAccepted = vi.fn().mockResolvedValue(undefined);
|
|
const onBulkBookingsAccepted = vi.fn().mockResolvedValue(undefined);
|
|
const onBookingRejected = vi.fn().mockResolvedValue(undefined);
|
|
const onBulkBookingsRejected = vi.fn().mockResolvedValue(undefined);
|
|
|
|
// Create a single service instance that will be returned
|
|
const mockService = {
|
|
onBookingAccepted,
|
|
onBulkBookingsAccepted,
|
|
onBookingRejected,
|
|
onBulkBookingsRejected,
|
|
};
|
|
|
|
return {
|
|
getBookingEventHandlerService: vi.fn(() => mockService),
|
|
};
|
|
});
|
|
|
|
describe("confirmHandler", () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
describe("Booking Accepted", () => {
|
|
it("should pass hideCalendarNotes property to CalendarEvent when enabled", async () => {
|
|
vi.setSystemTime("2050-01-07T00:00:00Z");
|
|
|
|
const handleConfirmationSpy = vi.spyOn(handleConfirmationModule, "handleConfirmation");
|
|
|
|
const attendeeUser = getOrganizer({
|
|
email: "test@example.com",
|
|
name: "test name",
|
|
id: 102,
|
|
schedules: [TestData.schedules.IstWorkHours],
|
|
});
|
|
|
|
const organizer = getOrganizer({
|
|
name: "Organizer",
|
|
email: "organizer@example.com",
|
|
id: 101,
|
|
schedules: [TestData.schedules.IstWorkHours],
|
|
});
|
|
|
|
const uidOfBooking = "hideNotes123";
|
|
const iCalUID = `${uidOfBooking}@Cal.com`;
|
|
|
|
const plus1DateString = "2050-01-08";
|
|
|
|
await createBookingScenario(
|
|
getScenarioData({
|
|
eventTypes: [
|
|
{
|
|
id: 1,
|
|
slotInterval: 15,
|
|
length: 15,
|
|
locations: [],
|
|
hideCalendarNotes: true,
|
|
hideCalendarEventDetails: true,
|
|
requiresConfirmation: true,
|
|
users: [
|
|
{
|
|
id: 101,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
bookings: [
|
|
{
|
|
id: 101,
|
|
uid: uidOfBooking,
|
|
eventTypeId: 1,
|
|
status: BookingStatus.PENDING,
|
|
startTime: `${plus1DateString}T05:00:00.000Z`,
|
|
endTime: `${plus1DateString}T05:15:00.000Z`,
|
|
references: [],
|
|
iCalUID,
|
|
location: "integrations:daily",
|
|
attendees: [attendeeUser],
|
|
responses: {
|
|
name: attendeeUser.name,
|
|
email: attendeeUser.email,
|
|
notes: "Sensitive information",
|
|
},
|
|
user: { id: organizer.id },
|
|
},
|
|
],
|
|
organizer,
|
|
apps: [TestData.apps["daily-video"]],
|
|
})
|
|
);
|
|
|
|
mockSuccessfulVideoMeetingCreation({
|
|
metadataLookupKey: "dailyvideo",
|
|
});
|
|
|
|
const ctx = {
|
|
user: {
|
|
id: organizer.id,
|
|
name: organizer.name,
|
|
timeZone: organizer.timeZone,
|
|
username: organizer.username,
|
|
} as NonNullable<TrpcSessionUser>,
|
|
traceContext: distributedTracing.createTrace("test_confirm_handler"),
|
|
};
|
|
|
|
const res = await confirmHandler({
|
|
ctx,
|
|
input: {
|
|
bookingId: 101,
|
|
confirmed: true,
|
|
reason: "",
|
|
emailsEnabled: true,
|
|
actor: makeUserActor(ctx.user.uuid),
|
|
actionSource: "WEBAPP",
|
|
impersonatedByUserUuid: null,
|
|
},
|
|
});
|
|
|
|
expect(res?.status).toBe(BookingStatus.ACCEPTED);
|
|
expect(handleConfirmationSpy).toHaveBeenCalledTimes(1);
|
|
|
|
const handleConfirmationCall = handleConfirmationSpy.mock.calls[0][0];
|
|
const calendarEvent = handleConfirmationCall.evt;
|
|
|
|
expect(calendarEvent.hideCalendarNotes).toBe(true);
|
|
expect(calendarEvent.hideCalendarEventDetails).toBe(true);
|
|
});
|
|
|
|
it("should call BookingEventHandlerService.onBookingAccepted with correct arguments when confirming a booking", async () => {
|
|
vi.setSystemTime("2050-01-07T00:00:00Z");
|
|
|
|
const attendeeUser = getOrganizer({
|
|
email: "test@example.com",
|
|
name: "test name",
|
|
id: 102,
|
|
schedules: [TestData.schedules.IstWorkHours],
|
|
});
|
|
|
|
const organizer = getOrganizer({
|
|
name: "Organizer",
|
|
email: "organizer@example.com",
|
|
id: 101,
|
|
schedules: [TestData.schedules.IstWorkHours],
|
|
});
|
|
|
|
const uidOfBooking = "testBooking123";
|
|
const iCalUID = `${uidOfBooking}@Cal.com`;
|
|
|
|
const plus1DateString = "2050-01-08";
|
|
|
|
await createBookingScenario(
|
|
getScenarioData({
|
|
eventTypes: [
|
|
{
|
|
id: 1,
|
|
slotInterval: 15,
|
|
length: 15,
|
|
locations: [],
|
|
requiresConfirmation: true,
|
|
users: [
|
|
{
|
|
id: 101,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
bookings: [
|
|
{
|
|
id: 101,
|
|
uid: uidOfBooking,
|
|
eventTypeId: 1,
|
|
status: BookingStatus.PENDING,
|
|
startTime: `${plus1DateString}T05:00:00.000Z`,
|
|
endTime: `${plus1DateString}T05:15:00.000Z`,
|
|
references: [],
|
|
iCalUID,
|
|
location: "integrations:daily",
|
|
attendees: [attendeeUser],
|
|
responses: { name: attendeeUser.name, email: attendeeUser.email },
|
|
user: { id: organizer.id },
|
|
},
|
|
],
|
|
organizer,
|
|
apps: [TestData.apps["daily-video"]],
|
|
})
|
|
);
|
|
|
|
mockSuccessfulVideoMeetingCreation({
|
|
metadataLookupKey: "dailyvideo",
|
|
});
|
|
|
|
const testUserUuid = "test-uuid-101";
|
|
const ctx = {
|
|
user: {
|
|
id: organizer.id,
|
|
name: organizer.name,
|
|
timeZone: organizer.timeZone,
|
|
username: organizer.username,
|
|
uuid: testUserUuid,
|
|
} as NonNullable<TrpcSessionUser>,
|
|
traceContext: distributedTracing.createTrace("test_confirm_handler"),
|
|
};
|
|
|
|
const actor = makeUserActor(ctx.user.uuid);
|
|
|
|
const res = await confirmHandler({
|
|
ctx,
|
|
input: {
|
|
bookingId: 101,
|
|
confirmed: true,
|
|
reason: "",
|
|
emailsEnabled: true,
|
|
actor,
|
|
actionSource: "WEBAPP",
|
|
impersonatedByUserUuid: null,
|
|
},
|
|
});
|
|
|
|
expect(res?.status).toBe(BookingStatus.ACCEPTED);
|
|
|
|
// Get the mock service instance to access the mocks
|
|
const mockService = getBookingEventHandlerService();
|
|
expect(mockService.onBookingAccepted).toHaveBeenCalledTimes(1);
|
|
|
|
const callArgs = vi.mocked(mockService.onBookingAccepted).mock.calls[0][0];
|
|
expect(callArgs.bookingUid).toBe(uidOfBooking);
|
|
expect(callArgs.actor).toEqual(actor);
|
|
expect(callArgs.auditData).toEqual({
|
|
status: { old: BookingStatus.PENDING, new: BookingStatus.ACCEPTED },
|
|
});
|
|
expect(callArgs.source).toBe("WEBAPP");
|
|
expect(callArgs.organizationId).toBeNull();
|
|
});
|
|
|
|
it("should call BookingEventHandlerService.onBulkBookingsAccepted when confirming recurring bookings", async () => {
|
|
vi.setSystemTime("2050-01-07T00:00:00Z");
|
|
|
|
const attendeeUser = getOrganizer({
|
|
email: "test@example.com",
|
|
name: "test name",
|
|
id: 102,
|
|
schedules: [TestData.schedules.IstWorkHours],
|
|
});
|
|
|
|
const organizer = getOrganizer({
|
|
name: "Organizer",
|
|
email: "organizer@example.com",
|
|
id: 101,
|
|
schedules: [TestData.schedules.IstWorkHours],
|
|
});
|
|
|
|
const recurringEventId = "recurring123";
|
|
const uidOfBooking1 = "testBooking1";
|
|
const uidOfBooking2 = "testBooking2";
|
|
const iCalUID1 = `${uidOfBooking1}@Cal.com`;
|
|
const iCalUID2 = `${uidOfBooking2}@Cal.com`;
|
|
|
|
const plus1DateString = "2050-01-08";
|
|
const plus2DateString = "2050-01-09";
|
|
|
|
await createBookingScenario(
|
|
getScenarioData({
|
|
eventTypes: [
|
|
{
|
|
id: 1,
|
|
slotInterval: 15,
|
|
length: 15,
|
|
locations: [],
|
|
requiresConfirmation: true,
|
|
recurringEvent: { freq: 2, count: 3, interval: 1 },
|
|
users: [
|
|
{
|
|
id: 101,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
bookings: [
|
|
{
|
|
id: 101,
|
|
uid: uidOfBooking1,
|
|
eventTypeId: 1,
|
|
status: BookingStatus.PENDING,
|
|
startTime: `${plus1DateString}T05:00:00.000Z`,
|
|
endTime: `${plus1DateString}T05:15:00.000Z`,
|
|
references: [],
|
|
iCalUID: iCalUID1,
|
|
location: "integrations:daily",
|
|
attendees: [attendeeUser],
|
|
responses: { name: attendeeUser.name, email: attendeeUser.email },
|
|
user: { id: organizer.id },
|
|
recurringEventId,
|
|
},
|
|
{
|
|
id: 102,
|
|
uid: uidOfBooking2,
|
|
eventTypeId: 1,
|
|
status: BookingStatus.PENDING,
|
|
startTime: `${plus2DateString}T05:00:00.000Z`,
|
|
endTime: `${plus2DateString}T05:15:00.000Z`,
|
|
references: [],
|
|
iCalUID: iCalUID2,
|
|
location: "integrations:daily",
|
|
attendees: [attendeeUser],
|
|
responses: { name: attendeeUser.name, email: attendeeUser.email },
|
|
user: { id: organizer.id },
|
|
recurringEventId,
|
|
},
|
|
],
|
|
organizer,
|
|
apps: [TestData.apps["daily-video"]],
|
|
})
|
|
);
|
|
|
|
mockSuccessfulVideoMeetingCreation({
|
|
metadataLookupKey: "dailyvideo",
|
|
});
|
|
|
|
const testUserUuid = "test-uuid-101";
|
|
const ctx = {
|
|
user: {
|
|
id: organizer.id,
|
|
name: organizer.name,
|
|
timeZone: organizer.timeZone,
|
|
username: organizer.username,
|
|
uuid: testUserUuid,
|
|
} as NonNullable<TrpcSessionUser>,
|
|
traceContext: distributedTracing.createTrace("test_confirm_handler"),
|
|
};
|
|
|
|
const actor = makeUserActor(ctx.user.uuid);
|
|
|
|
const res = await confirmHandler({
|
|
ctx,
|
|
input: {
|
|
bookingId: 101,
|
|
recurringEventId,
|
|
confirmed: true,
|
|
reason: "",
|
|
emailsEnabled: true,
|
|
actor,
|
|
actionSource: "WEBAPP",
|
|
impersonatedByUserUuid: null,
|
|
},
|
|
});
|
|
|
|
expect(res?.status).toBe(BookingStatus.ACCEPTED);
|
|
|
|
// Get the mock service instance to access the mocks
|
|
const mockService = getBookingEventHandlerService();
|
|
expect(mockService.onBulkBookingsAccepted).toHaveBeenCalledTimes(1);
|
|
|
|
const callArgs = vi.mocked(mockService.onBulkBookingsAccepted).mock.calls[0][0];
|
|
expect(callArgs.bookings).toHaveLength(2);
|
|
expect(callArgs.bookings[0].bookingUid).toBe(uidOfBooking1);
|
|
expect(callArgs.bookings[0].auditData).toEqual({
|
|
status: { old: BookingStatus.PENDING, new: BookingStatus.ACCEPTED },
|
|
});
|
|
expect(callArgs.bookings[1].bookingUid).toBe(uidOfBooking2);
|
|
expect(callArgs.bookings[1].auditData).toEqual({
|
|
status: { old: BookingStatus.PENDING, new: BookingStatus.ACCEPTED },
|
|
});
|
|
expect(callArgs.actor).toEqual(actor);
|
|
expect(callArgs.source).toBe("WEBAPP");
|
|
expect(callArgs.organizationId).toBeNull();
|
|
expect(callArgs.operationId).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe("Booking Rejected", () => {
|
|
it("should call BookingEventHandlerService.onBookingRejected with correct arguments when rejecting a booking", async () => {
|
|
vi.setSystemTime("2050-01-07T00:00:00Z");
|
|
|
|
const attendeeUser = getOrganizer({
|
|
email: "test@example.com",
|
|
name: "test name",
|
|
id: 102,
|
|
schedules: [TestData.schedules.IstWorkHours],
|
|
});
|
|
|
|
const organizer = getOrganizer({
|
|
name: "Organizer",
|
|
email: "organizer@example.com",
|
|
id: 101,
|
|
schedules: [TestData.schedules.IstWorkHours],
|
|
});
|
|
|
|
const uidOfBooking = "testBooking456";
|
|
const iCalUID = `${uidOfBooking}@Cal.com`;
|
|
|
|
const plus1DateString = "2050-01-08";
|
|
|
|
await createBookingScenario(
|
|
getScenarioData({
|
|
eventTypes: [
|
|
{
|
|
id: 1,
|
|
slotInterval: 15,
|
|
length: 15,
|
|
locations: [],
|
|
requiresConfirmation: true,
|
|
users: [
|
|
{
|
|
id: 101,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
bookings: [
|
|
{
|
|
id: 103,
|
|
uid: uidOfBooking,
|
|
eventTypeId: 1,
|
|
status: BookingStatus.PENDING,
|
|
startTime: `${plus1DateString}T05:00:00.000Z`,
|
|
endTime: `${plus1DateString}T05:15:00.000Z`,
|
|
references: [],
|
|
iCalUID,
|
|
location: "integrations:daily",
|
|
attendees: [attendeeUser],
|
|
responses: { name: attendeeUser.name, email: attendeeUser.email },
|
|
user: { id: organizer.id },
|
|
},
|
|
],
|
|
organizer,
|
|
apps: [TestData.apps["daily-video"]],
|
|
})
|
|
);
|
|
|
|
const testUserUuid = "test-uuid-101";
|
|
const ctx = {
|
|
user: {
|
|
id: organizer.id,
|
|
name: organizer.name,
|
|
timeZone: organizer.timeZone,
|
|
username: organizer.username,
|
|
uuid: testUserUuid,
|
|
} as NonNullable<TrpcSessionUser>,
|
|
traceContext: distributedTracing.createTrace("test_confirm_handler"),
|
|
};
|
|
|
|
const actor = makeUserActor(ctx.user.uuid);
|
|
const rejectionReason = "Not available";
|
|
|
|
const res = await confirmHandler({
|
|
ctx,
|
|
input: {
|
|
bookingId: 103,
|
|
confirmed: false,
|
|
reason: rejectionReason,
|
|
emailsEnabled: false,
|
|
actor,
|
|
actionSource: "WEBAPP",
|
|
impersonatedByUserUuid: null,
|
|
},
|
|
});
|
|
|
|
expect(res?.status).toBe(BookingStatus.REJECTED);
|
|
|
|
// Get the mock service instance to access the mocks
|
|
const mockService = getBookingEventHandlerService();
|
|
expect(mockService.onBookingRejected).toHaveBeenCalledTimes(1);
|
|
|
|
const callArgs = vi.mocked(mockService.onBookingRejected).mock.calls[0][0];
|
|
expect(callArgs.bookingUid).toBe(uidOfBooking);
|
|
expect(callArgs.actor).toEqual(actor);
|
|
expect(callArgs.auditData).toEqual({
|
|
rejectionReason,
|
|
status: { old: BookingStatus.PENDING, new: BookingStatus.REJECTED },
|
|
});
|
|
expect(callArgs.source).toBe("WEBAPP");
|
|
expect(callArgs.organizationId).toBeNull();
|
|
});
|
|
|
|
it("should call BookingEventHandlerService.onBulkBookingsRejected when rejecting recurring bookings", async () => {
|
|
vi.setSystemTime("2050-01-07T00:00:00Z");
|
|
|
|
const attendeeUser = getOrganizer({
|
|
email: "test@example.com",
|
|
name: "test name",
|
|
id: 102,
|
|
schedules: [TestData.schedules.IstWorkHours],
|
|
});
|
|
|
|
const organizer = getOrganizer({
|
|
name: "Organizer",
|
|
email: "organizer@example.com",
|
|
id: 101,
|
|
schedules: [TestData.schedules.IstWorkHours],
|
|
});
|
|
|
|
const recurringEventId = "recurring456";
|
|
const uidOfBooking1 = "testBooking3";
|
|
const uidOfBooking2 = "testBooking4";
|
|
const iCalUID1 = `${uidOfBooking1}@Cal.com`;
|
|
const iCalUID2 = `${uidOfBooking2}@Cal.com`;
|
|
|
|
const plus1DateString = "2050-01-08";
|
|
const plus2DateString = "2050-01-09";
|
|
|
|
await createBookingScenario(
|
|
getScenarioData({
|
|
eventTypes: [
|
|
{
|
|
id: 1,
|
|
slotInterval: 15,
|
|
length: 15,
|
|
locations: [],
|
|
requiresConfirmation: true,
|
|
recurringEvent: { freq: 2, count: 3, interval: 1 },
|
|
users: [
|
|
{
|
|
id: 101,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
bookings: [
|
|
{
|
|
id: 104,
|
|
uid: uidOfBooking1,
|
|
eventTypeId: 1,
|
|
status: BookingStatus.PENDING,
|
|
startTime: `${plus1DateString}T05:00:00.000Z`,
|
|
endTime: `${plus1DateString}T05:15:00.000Z`,
|
|
references: [],
|
|
iCalUID: iCalUID1,
|
|
location: "integrations:daily",
|
|
attendees: [attendeeUser],
|
|
responses: { name: attendeeUser.name, email: attendeeUser.email },
|
|
user: { id: organizer.id },
|
|
recurringEventId,
|
|
},
|
|
{
|
|
id: 105,
|
|
uid: uidOfBooking2,
|
|
eventTypeId: 1,
|
|
status: BookingStatus.PENDING,
|
|
startTime: `${plus2DateString}T05:00:00.000Z`,
|
|
endTime: `${plus2DateString}T05:15:00.000Z`,
|
|
references: [],
|
|
iCalUID: iCalUID2,
|
|
location: "integrations:daily",
|
|
attendees: [attendeeUser],
|
|
responses: { name: attendeeUser.name, email: attendeeUser.email },
|
|
user: { id: organizer.id },
|
|
recurringEventId,
|
|
},
|
|
],
|
|
organizer,
|
|
apps: [TestData.apps["daily-video"]],
|
|
})
|
|
);
|
|
|
|
const testUserUuid = "test-uuid-101";
|
|
const ctx = {
|
|
user: {
|
|
id: organizer.id,
|
|
name: organizer.name,
|
|
timeZone: organizer.timeZone,
|
|
username: organizer.username,
|
|
uuid: testUserUuid,
|
|
} as NonNullable<TrpcSessionUser>,
|
|
traceContext: distributedTracing.createTrace("test_confirm_handler"),
|
|
};
|
|
|
|
const actor = makeUserActor(ctx.user.uuid);
|
|
const rejectionReason = "Organizer not available";
|
|
|
|
const res = await confirmHandler({
|
|
ctx,
|
|
input: {
|
|
bookingId: 104,
|
|
recurringEventId,
|
|
confirmed: false,
|
|
reason: rejectionReason,
|
|
emailsEnabled: false,
|
|
actor,
|
|
actionSource: "WEBAPP",
|
|
impersonatedByUserUuid: null,
|
|
},
|
|
});
|
|
|
|
expect(res?.status).toBe(BookingStatus.REJECTED);
|
|
|
|
// Get the mock service instance to access the mocks
|
|
const mockService = getBookingEventHandlerService();
|
|
expect(mockService.onBulkBookingsRejected).toHaveBeenCalledTimes(1);
|
|
|
|
const callArgs = vi.mocked(mockService.onBulkBookingsRejected).mock.calls[0][0];
|
|
expect(callArgs.bookings).toHaveLength(2);
|
|
expect(callArgs.bookings[0].bookingUid).toBe(uidOfBooking1);
|
|
expect(callArgs.bookings[0].auditData).toEqual({
|
|
rejectionReason,
|
|
status: { old: BookingStatus.PENDING, new: BookingStatus.REJECTED },
|
|
});
|
|
expect(callArgs.bookings[1].bookingUid).toBe(uidOfBooking2);
|
|
expect(callArgs.bookings[1].auditData).toEqual({
|
|
rejectionReason,
|
|
status: { old: BookingStatus.PENDING, new: BookingStatus.REJECTED },
|
|
});
|
|
expect(callArgs.actor).toEqual(actor);
|
|
expect(callArgs.source).toBe("WEBAPP");
|
|
expect(callArgs.organizationId).toBeNull();
|
|
expect(callArgs.operationId).toBeDefined();
|
|
});
|
|
});
|
|
});
|