Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: require confirmation cal video bug #16376

Merged
merged 7 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions packages/core/EventManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,12 @@ export default class EventManager {
result.type = result.createdEvent.type;
//responses data is later sent to webhook
if (evt.location && evt.responses) {
evt.responses["location"].value = {
optionValue: "",
value: evt.location,
evt.responses["location"] = {
...(evt.responses["location"] ?? {}),
value: {
optionValue: "",
value: evt.location,
},
Comment on lines +189 to +194
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When an event type doesn't have any location set and user submits booking form there is no location field in responses causing Type error "Cannot set properties of undefined"

};
}
}
Expand Down Expand Up @@ -256,9 +259,12 @@ export default class EventManager {
result.type = result.createdEvent.type;
//responses data is later sent to webhook
if (evt.location && evt.responses) {
evt.responses["location"].value = {
optionValue: "",
value: evt.location,
evt.responses["location"] = {
...(evt.responses["location"] ?? {}),
value: {
optionValue: "",
value: evt.location,
},
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/emails/lib/generateIcsFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function generateIcsFile({
if (
role !== GenerateIcsRole.ATTENDEE &&
calEvent.destinationCalendar &&
calEvent.destinationCalendar[0].integration === "office365_calendar"
calEvent.destinationCalendar[0]?.integration === "office365_calendar"
)
return null;

Expand Down
110 changes: 110 additions & 0 deletions packages/trpc/server/routers/viewer/bookings/confirm.handler.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import {
createBookingScenario,
TestData,
getOrganizer,
getScenarioData,
mockSuccessfulVideoMeetingCreation,
getDate,
} from "@calcom/web/test/utils/bookingScenario/bookingScenario";
import { setupAndTeardown } from "@calcom/web/test/utils/bookingScenario/setupAndTeardown";

import { describe, it, beforeEach, vi, expect } from "vitest";

import { BookingStatus } from "@calcom/prisma/enums";

import type { TrpcSessionUser } from "../../../trpc";
import { confirmHandler } from "./confirm.handler";

describe("confirmHandler", () => {
setupAndTeardown();
beforeEach(() => {
// Reset all mocks before each test
vi.clearAllMocks();
});

it("should successfully confirm booking when event type doesn't have any default location", async () => {
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 = "n5Wv3eHgconAED2j4gcVhP";
const iCalUID = `${uidOfBooking}@Cal.com`;

const { dateString: plus1DateString } = getDate({ dateIncrement: 1 });

await createBookingScenario(
getScenarioData({
webhooks: [
{
userId: organizer.id,
eventTriggers: ["BOOKING_CREATED"],
subscriberUrl: "http://my-webhook.example.com",
active: true,
eventTypeId: 1,
appId: null,
},
],
eventTypes: [
{
id: 1,
slotInterval: 15,
length: 15,
locations: [],
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, guests: [] },
},
],
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>,
};

const res = await confirmHandler({
ctx,
input: { bookingId: 101, confirmed: true, reason: "" },
});

expect(res?.status).toBe(BookingStatus.ACCEPTED);
});
});
Loading