Files
MorganGitHubDevin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
6eafb4b4bc feat: skip platform billing for non-platform-managed users (#27521)
* feat: skip platform billing for non-platform-managed users

- Add isPlatformManaged to user select in saveBooking and findBookingQuery
- Update 2024-04-15 booking controller to check isPlatformManaged before billing
- Update 2024-08-13 bookings service billBooking methods to check isPlatformManaged
- Update buildDryRunBooking to include isPlatformManaged in user object

Co-Authored-By: [email protected] <[email protected]>

* test: update buildDryRunBooking test to include uuid and isPlatformManaged fields

Co-Authored-By: [email protected] <[email protected]>

* refactor: simplify to only check isPlatformManaged in normal booking flow

Co-Authored-By: [email protected] <[email protected]>

* test: add E2E tests for billing behavior based on isPlatformManaged flag

Co-Authored-By: [email protected] <[email protected]>

* chore: only trigger platform billing for platform user bookingd

* test: add E2E tests for cancel and recurring booking billing behavior

Co-Authored-By: [email protected] <[email protected]>

* fix: correct expected status code for cancel booking endpoint (201 instead of 200)

Co-Authored-By: [email protected] <[email protected]>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-02-03 12:51:29 +02:00

110 lines
3.1 KiB
TypeScript

import { describe, it, expect, vi } from "vitest";
import { BookingStatus, CreationSource } from "@calcom/prisma/enums";
import { buildDryRunBooking } from "../../service/RegularBookingService";
vi.mock("@calcom/prisma", () => ({
default: {}, // empty object as default export
prisma: {},
}));
describe("buildDryRunBooking", () => {
const baseOrganizerUser = {
id: 1,
uuid: "test-uuid-123",
name: "Test User",
username: "testuser",
email: "[email protected]",
timeZone: "America/New_York",
credentials: [
{
abc: "xyz",
},
],
};
const baseInputs = {
eventTypeId: 10,
organizerUser: baseOrganizerUser,
eventName: "Test Event",
startTime: "2024-01-01T10:00:00.000Z",
endTime: "2024-01-01T11:00:00.000Z",
contactOwnerFromReq: "[email protected]",
contactOwnerEmail: "[email protected]",
allHostUsers: [{ id: 1 }, { id: 2 }],
isManagedEventType: false,
};
it("should build a dry run booking with all provided details and nothing more than that", () => {
const { booking, troubleshooterData } = buildDryRunBooking(baseInputs);
const { user, ...bookingExceptUser } = booking;
expect(user).toEqual({
id: baseOrganizerUser.id,
uuid: baseOrganizerUser.uuid,
name: baseOrganizerUser.name,
username: baseOrganizerUser.username,
email: baseOrganizerUser.email,
timeZone: baseOrganizerUser.timeZone,
isPlatformManaged: false,
});
expect(bookingExceptUser).toEqual({
id: -101,
uid: "DRY_RUN_UID",
iCalUID: "DRY_RUN_ICAL_UID",
status: BookingStatus.ACCEPTED,
eventTypeId: baseInputs.eventTypeId,
userId: baseOrganizerUser.id,
userUuid: baseOrganizerUser.uuid,
title: baseInputs.eventName,
startTime: new Date(baseInputs.startTime),
endTime: new Date(baseInputs.endTime),
createdAt: expect.any(Date),
updatedAt: expect.any(Date),
attendees: [],
oneTimePassword: null,
smsReminderNumber: null,
metadata: {},
idempotencyKey: null,
userPrimaryEmail: null,
description: null,
customInputs: null,
responses: null,
location: null,
paid: false,
cancellationReason: null,
rejectionReason: null,
dynamicEventSlugRef: null,
dynamicGroupSlugRef: null,
fromReschedule: null,
recurringEventId: null,
scheduledJobs: [],
rescheduledBy: null,
destinationCalendarId: null,
reassignReason: null,
reassignById: null,
rescheduled: false,
isRecorded: false,
iCalSequence: 0,
rating: null,
ratingFeedback: null,
noShowHost: null,
cancelledBy: null,
creationSource: CreationSource.WEBAPP,
references: [],
payment: [],
});
expect(troubleshooterData).toEqual({
organizerUserId: baseOrganizerUser.id,
eventTypeId: baseInputs.eventTypeId,
askedContactOwnerEmail: baseInputs.contactOwnerFromReq,
usedContactOwnerEmail: baseInputs.contactOwnerEmail,
allHostUsers: [1, 2],
isManagedEventType: baseInputs.isManagedEventType,
});
});
});