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 all 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
43 changes: 35 additions & 8 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,6 +1190,7 @@
log.silly("mockCalendar.updateEvent", JSON.stringify({ uid, event, externalCalendarId }));
// eslint-disable-next-line prefer-rest-params
updateEventCalls.push(rest);
const isGoogleMeetLocation = event.location === BookingLocations.GoogleMeet;
return Promise.resolve({
type: app.type,
additionalInfo: {},
Expand All @@ -1175,6 +1202,9 @@
// Password and URL seems useless for CalendarService, plan to remove them if that's the case
password: "MOCK_PASSWORD",
url: "https://UNUSED_URL",
location: isGoogleMeetLocation ? "https://UNUSED_URL" : undefined,
hangoutLink: isGoogleMeetLocation ? "https://UNUSED_URL" : undefined,
conferenceData: isGoogleMeetLocation ? event.conferenceData : undefined,
});
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -1487,19 +1517,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 +1536,7 @@
}
const foundApp = foundEntry[1];
return {
appName: foundApp.slug,
appName: overrideName ?? foundApp.slug,
type: foundApp.type,
failures,
success,
Expand All @@ -1520,6 +1547,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 });
};
24 changes: 15 additions & 9 deletions packages/features/bookings/lib/handleNewBooking.ts
Expand Up @@ -1868,7 +1868,11 @@ async function handler(
});
}

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

if (googleHangoutLink) {
results.push({
...googleMeetResult,
success: true,
Expand All @@ -1877,31 +1881,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 = Array.isArray(results[0]?.updatedEvent)
? results[0]?.updatedEvent[0]
: results[0]?.updatedEvent ?? results[0]?.createdEvent;
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