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: reschedule with google meet #14730

Merged
merged 16 commits into from May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
85 changes: 65 additions & 20 deletions apps/web/test/utils/bookingScenario/bookingScenario.ts
Expand Up @@ -202,10 +202,10 @@
});
const allEventTypes = await prismock.eventType.findMany({
include: {
users: true,

Check warning on line 205 in apps/web/test/utils/bookingScenario/bookingScenario.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

apps/web/test/utils/bookingScenario/bookingScenario.ts#L205

[@calcom/eslint/no-prisma-include-true] Do not pass argument object with include: { AnyPropertyName: true } to prisma methods
workflows: true,

Check warning on line 206 in apps/web/test/utils/bookingScenario/bookingScenario.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

apps/web/test/utils/bookingScenario/bookingScenario.ts#L206

[@calcom/eslint/no-prisma-include-true] Do not pass argument object with include: { AnyPropertyName: true } to prisma methods
destinationCalendar: true,

Check warning on line 207 in apps/web/test/utils/bookingScenario/bookingScenario.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

apps/web/test/utils/bookingScenario/bookingScenario.ts#L207

[@calcom/eslint/no-prisma-include-true] Do not pass argument object with include: { AnyPropertyName: true } to prisma methods
schedule: true,

Check warning on line 208 in apps/web/test/utils/bookingScenario/bookingScenario.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

apps/web/test/utils/bookingScenario/bookingScenario.ts#L208

[@calcom/eslint/no-prisma-include-true] Do not pass argument object with include: { AnyPropertyName: true } to prisma methods
},
});

Expand Down Expand Up @@ -344,8 +344,8 @@
JSON.stringify({
bookings: await prismock.booking.findMany({
include: {
references: true,

Check warning on line 347 in apps/web/test/utils/bookingScenario/bookingScenario.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

apps/web/test/utils/bookingScenario/bookingScenario.ts#L347

[@calcom/eslint/no-prisma-include-true] Do not pass argument object with include: { AnyPropertyName: true } to prisma methods
attendees: true,

Check warning on line 348 in apps/web/test/utils/bookingScenario/bookingScenario.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

apps/web/test/utils/bookingScenario/bookingScenario.ts#L348

[@calcom/eslint/no-prisma-include-true] Do not pass argument object with include: { AnyPropertyName: true } to prisma methods
},
}),
})
Expand Down Expand Up @@ -476,15 +476,15 @@
safeStringify({
allUsers: await prismock.user.findMany({
include: {
credentials: true,

Check warning on line 479 in apps/web/test/utils/bookingScenario/bookingScenario.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

apps/web/test/utils/bookingScenario/bookingScenario.ts#L479

[@calcom/eslint/no-prisma-include-true] Do not pass argument object with include: { AnyPropertyName: true } to prisma methods
teams: true,

Check warning on line 480 in apps/web/test/utils/bookingScenario/bookingScenario.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

apps/web/test/utils/bookingScenario/bookingScenario.ts#L480

[@calcom/eslint/no-prisma-include-true] Do not pass argument object with include: { AnyPropertyName: true } to prisma methods
profiles: true,

Check warning on line 481 in apps/web/test/utils/bookingScenario/bookingScenario.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

apps/web/test/utils/bookingScenario/bookingScenario.ts#L481

[@calcom/eslint/no-prisma-include-true] Do not pass argument object with include: { AnyPropertyName: true } to prisma methods
schedules: {
include: {
availability: true,

Check warning on line 484 in apps/web/test/utils/bookingScenario/bookingScenario.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

apps/web/test/utils/bookingScenario/bookingScenario.ts#L484

[@calcom/eslint/no-prisma-include-true] Do not pass argument object with include: { AnyPropertyName: true } to prisma methods
},
},
destinationCalendar: true,

Check warning on line 487 in apps/web/test/utils/bookingScenario/bookingScenario.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

apps/web/test/utils/bookingScenario/bookingScenario.ts#L487

[@calcom/eslint/no-prisma-include-true] Do not pass argument object with include: { AnyPropertyName: true } to prisma methods
},
}),
})
Expand Down Expand Up @@ -763,6 +763,15 @@
});
}

export function getGoogleMeetCredential() {
return getMockedCredential({
metadataLookupKey: "googlevideo",
key: {
scope: "",
},
});
}

export function getAppleCalendarCredential() {
return getMockedCredential({
metadataLookupKey: "applecalendar",
Expand Down Expand Up @@ -890,6 +899,17 @@
redirect_uris: ["http://localhost:3000/auth/callback"],
},
},
"google-meet": {
...appStoreMetadata.googlevideo,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
keys: {
expiry_date: Infinity,
client_id: "client_id",
client_secret: "client_secret",
redirect_uris: ["http://localhost:3000/auth/callback"],
},
},
"daily-video": {
...appStoreMetadata.dailyvideo,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand Down Expand Up @@ -1084,6 +1104,12 @@
});
}

export const enum BookingLocations {
CalVideo = "integrations:daily",
ZoomVideo = "integrations:zoom",
GoogleMeet = "integrations:google:meet",
}

/**
* @param metadataLookupKey
* @param calendarData Specify uids and other data to be faked to be returned by createEvent and updateEvent
Expand Down Expand Up @@ -1164,18 +1190,40 @@
log.silly("mockCalendar.updateEvent", JSON.stringify({ uid, event, externalCalendarId }));
// eslint-disable-next-line prefer-rest-params
updateEventCalls.push(rest);
return Promise.resolve({
type: app.type,
additionalInfo: {},
uid: "PROBABLY_UNUSED_UID",
iCalUID: normalizedCalendarData.update?.iCalUID,

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
id: normalizedCalendarData.update?.uid || "FALLBACK_MOCK_ID",
// Password and URL seems useless for CalendarService, plan to remove them if that's the case
password: "MOCK_PASSWORD",
url: "https://UNUSED_URL",
});
if (event.location === BookingLocations.GoogleMeet) {
return Promise.resolve({
type: app.type,
additionalInfo: {},
uid: "PROBABLY_UNUSED_UID",
iCalUID: normalizedCalendarData.update?.iCalUID,

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
id: normalizedCalendarData.update?.uid || "FALLBACK_MOCK_ID",
// Password and URL seems useless for CalendarService, plan to remove them if that's the case
password: "MOCK_PASSWORD",
url: "https://UNUSED_URL",
location: "https://UNUSED_URL",
hangoutLink: "https://UNUSED_URL",
conferenceData: event.conferenceData,
Udit-takkar marked this conversation as resolved.
Show resolved Hide resolved
organizer: {
email: event.organizer.email,
self: true,
},
});
} else {
return Promise.resolve({
type: app.type,
additionalInfo: {},
uid: "PROBABLY_UNUSED_UID",
iCalUID: normalizedCalendarData.update?.iCalUID,

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
id: normalizedCalendarData.update?.uid || "FALLBACK_MOCK_ID",
// Password and URL seems useless for CalendarService, plan to remove them if that's the case
password: "MOCK_PASSWORD",
url: "https://UNUSED_URL",
});
}
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
deleteEvent: async (...rest: any[]) => {
Expand Down Expand Up @@ -1487,19 +1535,16 @@
};
}

export const enum BookingLocations {
CalVideo = "integrations:daily",
ZoomVideo = "integrations:zoom",
}

const getMockAppStatus = ({
slug,
failures,
success,
overrideName,
}: {
slug: string;
failures: number;
success: number;
overrideName?: string;
}) => {
const foundEntry = Object.entries(appStoreMetadata).find(([, app]) => {
return app.slug === slug;
Expand All @@ -1509,7 +1554,7 @@
}
const foundApp = foundEntry[1];
return {
appName: foundApp.slug,
appName: overrideName ?? foundApp.slug,
type: foundApp.type,
failures,
success,
Expand All @@ -1520,6 +1565,6 @@
return getMockAppStatus({ slug, failures: 1, success: 0 });
};

export const getMockPassingAppStatus = ({ slug }: { slug: string }) => {
return getMockAppStatus({ slug, failures: 0, success: 1 });
export const getMockPassingAppStatus = ({ slug, overrideName }: { slug: string; overrideName?: string }) => {
return getMockAppStatus({ slug, overrideName, failures: 0, success: 1 });
};
26 changes: 17 additions & 9 deletions packages/features/bookings/lib/handleNewBooking.ts
Expand Up @@ -1868,7 +1868,13 @@ async function handler(
});
}

if (googleCalResult?.createdEvent?.hangoutLink) {
const googleHangoutLink =
googleCalResult?.createdEvent?.hangoutLink ??
(Array.isArray(googleCalResult?.updatedEvent)
? googleCalResult.updatedEvent[0]?.hangoutLink
: googleCalResult?.updatedEvent?.hangoutLink);
Copy link
Member

Choose a reason for hiding this comment

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

AFAIU, the issue occurred because the originalEvent didn't have videoCallData(because the booking was confirmed later and then the videoCallData isn't updated in bookingReference I guess(which I think we should do as a follow up - but it is a separate problem).

The thing is that we should have used the latest link returned by the updateMeeting/updateEvent call(which is available in updatedEvent). We can fallback to createdEvent just in case. It ensure that the link expiry is up-to-date(and maybe other details).

Though I tested, and it makes sense that, during reschedule createdEvent won't be there. So, technically we should just use updatedEvent.

const googleHangoutLink=(Array.isArray(googleCalResult?.updatedEvent) ? googleCalResult.updatedEvent[0]?.hangoutLink : googleCalResult?.updatedEvent?.hangoutLink)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Though I tested, and it makes sense that, during reschedule createdEvent won't be there. So, technically we should just use updatedEvent.

I also thought about only using updatedEvent but when you reschedule and add a new guest in booking form then you would get createdEvent.

Screenshot 2024-05-04 at 7 20 55 PM

Copy link
Member

Choose a reason for hiding this comment

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

Ah cool that's something i missed. But we should still prioritize updatedEvent over createdEvent. Not sure if that change is done already.


if (googleHangoutLink) {
results.push({
...googleMeetResult,
success: true,
Expand All @@ -1877,31 +1883,33 @@ async function handler(
// Add google_meet to referencesToCreate in the same index as google_calendar
updateManager.referencesToCreate[googleCalIndex] = {
...updateManager.referencesToCreate[googleCalIndex],
meetingUrl: googleCalResult.createdEvent.hangoutLink,
meetingUrl: googleHangoutLink,
};

// Also create a new referenceToCreate with type video for google_meet
updateManager.referencesToCreate.push({
type: "google_meet_video",
meetingUrl: googleCalResult.createdEvent.hangoutLink,
meetingUrl: googleHangoutLink,
uid: googleCalResult.uid,
credentialId: updateManager.referencesToCreate[googleCalIndex].credentialId,
});
} else if (googleCalResult && !googleCalResult.createdEvent?.hangoutLink) {
} else if (googleCalResult && !googleHangoutLink) {
results.push({
...googleMeetResult,
success: false,
});
}
}

metadata.hangoutLink = results[0].createdEvent?.hangoutLink;
metadata.conferenceData = results[0].createdEvent?.conferenceData;
metadata.entryPoints = results[0].createdEvent?.entryPoints;
const createdOrUpdatedEvent =
results[0]?.createdEvent ??
(Array.isArray(results[0]?.updatedEvent) ? results[0]?.updatedEvent[0] : results[0]?.updatedEvent);
Udit-takkar marked this conversation as resolved.
Show resolved Hide resolved
metadata.hangoutLink = createdOrUpdatedEvent?.hangoutLink;
metadata.conferenceData = createdOrUpdatedEvent?.conferenceData;
metadata.entryPoints = createdOrUpdatedEvent?.entryPoints;
evt.appsStatus = handleAppsStatus(results, booking, reqAppsStatus);
videoCallUrl =
metadata.hangoutLink ||
results[0].createdEvent?.url ||
createdOrUpdatedEvent?.url ||
organizerOrFirstDynamicGroupMemberDefaultLocationUrl ||
getVideoCallUrlFromCalEvent(evt) ||
videoCallUrl;
Expand Down