mirror of
https://github.com/hanzoai/calendar.git
synced 2026-10-30 14:46:43 +00:00
* Add endpoints for testing the flow * Add MVP * new route * Fixes * Fixes * Remove enable toggle support from domainWideDelegation * Fixes * Revert "Remove enable toggle support from domainWideDelegation" This reverts commit c29e729206cd1fa063f9c9ce0cf148ef1577d60b. * Revert yarn.lock * More fixes * Fix new workspace platform add * refactor: improvements * refactor: bug fixes and improvements * fix: type errors * fix: conflicts * chore: update test * fix: logic * chore: improvements * fix: toglle * fix: bugs * fix: type err * chore: check number type * fix: after conflicts * chore: fix type err * fix: type errors and tests * fix: tets * test * chore: remove unused * fix: google meet url on booking page and secondary calendar * fix: add property * fix: type err * fix: re assingment bug * fix: use getAllCredentials * chore: fix import * fix: installed count * fix: pass event type * fix: import * fix: [Stacked PR] Review fixes (#17958) * Review fixes * fix: destination calendar bug --------- Co-authored-by: Udit Takkar <[email protected]> * refactor: use repository * chore: remove duplicate * fix: More review fixes for domain wide delegation (#17969) * Reuse buildCredentialPayloadForCalendar * fixes --------- Co-authored-by: Udit Takkar <[email protected]> * fix ts error * Fix getSchedule not using dwd credentials (#17995) * fix: Remove direct DWD table access from google-calendar and remove delegatedToId column from Credential (#18015) * Remove fn rename to reduce number of files changed * chore: check feature globally * test: add unit tests * chore: move function * test: add booking test * wip * Remove domain-wide-delegation team feature flag * Make sure duplicate calendars are not shown due to DWD. Show DWD when there is conflict * Fix tests and their ts errors * Fix more tests * Move findUsersForAvailabilityCheck to separate file as it has AppStore dependency causing problem with Routing Forms. Build crashes * fix: Multiple calendar connections from Google not showing up in apps/installed * DestinationCalendar must have either credentialId or domainWideDeelgationId. Also handle the case when DWD is disabled and there was a non-dwd credential that could be used * Disable deletetion of DWD as it is destructive and prefer disabling instead * Show DWD credential calendars at the top * Fixed tests * Calendar Cache DWD support * Self-Review: Verify email required and add more selectedCalendar tests * Self Review: shorten names * Self ReviewL Dead code removal * Revert "Calendar Cache DWD support" This reverts commit 009f236470fa21eba5986117d4f6e4d4c5e38c34. * Some misc fixes * fixes * Performance improvememt in slots loading and booking * More cases for handling dwd credentials * simplify the logic. Ensure that EventManager and the modules below it in the flow have CredentialForCalendarService available * Fix tests * Fix installed/conferencing not showing gogole meet * Shorten name * Fix ApI v2 tests * Add some more tests * add getSchedule tests * Improve tests * Make Google Meet default when DWD for google is enabled * Enable feature flagging for DWD * chore: bump libraries * Encrypt serviceaccount private key * Fix ts errors * bump platform libraries * org add dwd * org add dwd * bump platform libraries * fix selected calendars * fix remove selected dwd calendar * remove oauthclient id aliad in authedCalendar * remove oauthclient id aliad in authedCalendar * refactor: OrganizationsDwdController * chore: export toggleDwdEnabled from platform-libraries * feat: v2 update (enable / disable) dwd * refactor: SelectedCalendarsController check if user belongs to dwd org & for not dwd use previous logic * wip: DestinationCalendar send domainWideDelegationCredentialId from frontend to api * try fix set destination calendar api v2 * fixup! try fix set destination calendar api v2 * setting google meet as default location working for dwd * bump platform libraries version * allow office 365 workspace slug * allow office 365 workspace slug * chore: v2 create dwd MS and Google service keys input * fix: CreateDwdInput serviceAccountKey * fix: CredentialForCalendarService type * fix: check workspace slug * feat: update serviceAccessKey of DWD * testing * fixup! testing * fix: getAuthUtl bug * fix: unit tests * fix: type err and unit test * fix: e2e test * fix: credentials bug and failing unit tests * Update CalendarService.ts * chore: refactor office365 calendar service and add testDomainWideDelegationSetup * fix: office365Calendar use correct clientId/Secret for DWD * fix: office365Calendar dwd no need refresh token * test: add unit test for outlook dwd and setup * feat: added dwd support for office365 calendar * feat: added dwd support for office365 video * test: finish test for outlook dwd * fix: create dialog bug * chore: remove console logs * fix: refreshToken bug * bump version libraries * refactor: fetch dwd credentials only in findQualifiedHosts * fixup! refactor: fetch dwd credentials only in findQualifiedHosts * fix: type err * fix: type err * fix: getUserDisplayName * fix: unit test * chore: bump platform lib --------- Co-authored-by: Syed Ali Shahbaz <[email protected]> Co-authored-by: Udit Takkar <[email protected]> Co-authored-by: Udit Takkar <[email protected]> Co-authored-by: Morgan Vernay <[email protected]> Co-authored-by: supalarry <[email protected]> Co-authored-by: Somay Chauhan <[email protected]> Co-authored-by: Morgan <[email protected]>
235 lines
8.5 KiB
TypeScript
235 lines
8.5 KiB
TypeScript
import { expect } from "@playwright/test";
|
|
import type { Page } from "@playwright/test";
|
|
|
|
import dayjs from "@calcom/dayjs";
|
|
import { APP_CREDENTIAL_SHARING_ENABLED } from "@calcom/lib/constants";
|
|
import prisma from "@calcom/prisma";
|
|
import type { CredentialForCalendarServiceWithEmail } from "@calcom/types/Credential";
|
|
import { test } from "@calcom/web/playwright/lib/fixtures";
|
|
import { selectSecondAvailableTimeSlotNextMonth } from "@calcom/web/playwright/lib/testUtils";
|
|
|
|
import metadata from "../_metadata";
|
|
import GoogleCalendarService from "../lib/CalendarService";
|
|
import { createBookingAndFetchGCalEvent, deleteBookingAndEvent, assertValueExists } from "./testUtils";
|
|
|
|
test.describe("Google Calendar", async () => {
|
|
// Skip till the tests are flaky
|
|
// eslint-disable-next-line playwright/no-skipped-test
|
|
test.describe.skip("Test using the primary calendar", async () => {
|
|
let qaUsername: string;
|
|
let qaGCalCredential: CredentialForCalendarServiceWithEmail;
|
|
test.beforeAll(async () => {
|
|
let runIntegrationTest = false;
|
|
const errorMessage = "Could not run test";
|
|
|
|
test.skip(!!APP_CREDENTIAL_SHARING_ENABLED, "Credential sharing enabled");
|
|
|
|
if (process.env.E2E_TEST_CALCOM_GCAL_KEYS) {
|
|
const gCalKeys = JSON.parse(process.env.E2E_TEST_CALCOM_GCAL_KEYS);
|
|
await prisma.app.update({
|
|
where: {
|
|
slug: "google-calendar",
|
|
},
|
|
data: {
|
|
keys: gCalKeys,
|
|
},
|
|
});
|
|
} else {
|
|
test.skip(!process.env.E2E_TEST_CALCOM_GCAL_KEYS, "GCal keys not found");
|
|
}
|
|
|
|
test.skip(!process.env.E2E_TEST_CALCOM_QA_EMAIL, "QA email not found");
|
|
test.skip(!process.env.E2E_TEST_CALCOM_QA_PASSWORD, "QA password not found");
|
|
|
|
if (process.env.E2E_TEST_CALCOM_QA_EMAIL && process.env.E2E_TEST_CALCOM_QA_PASSWORD) {
|
|
qaGCalCredential = {
|
|
...(await prisma.credential.findFirstOrThrow({
|
|
where: {
|
|
user: {
|
|
email: process.env.E2E_TEST_CALCOM_QA_EMAIL,
|
|
},
|
|
type: metadata.type,
|
|
},
|
|
include: {
|
|
user: {
|
|
select: {
|
|
email: true,
|
|
},
|
|
},
|
|
},
|
|
})),
|
|
delegatedTo: null,
|
|
} as CredentialForCalendarServiceWithEmail;
|
|
test.skip(!qaGCalCredential?.id, "Google QA credential not found");
|
|
|
|
const qaUserQuery = await prisma.user.findFirstOrThrow({
|
|
where: {
|
|
email: process.env.E2E_TEST_CALCOM_QA_EMAIL,
|
|
},
|
|
select: {
|
|
id: true,
|
|
username: true,
|
|
},
|
|
});
|
|
|
|
test.skip(!qaUserQuery, "QA user not found");
|
|
|
|
assertValueExists(qaUserQuery.username, "qaUsername");
|
|
qaUsername = qaUserQuery.username;
|
|
|
|
test.skip(!qaUsername, "QA username not found");
|
|
|
|
const googleCalendarService = new GoogleCalendarService(qaGCalCredential);
|
|
|
|
const calendars = await googleCalendarService.listCalendars();
|
|
|
|
const primaryCalendarName = calendars.find((calendar) => calendar.primary)?.name;
|
|
assertValueExists(primaryCalendarName, "primaryCalendarName");
|
|
|
|
await prisma.destinationCalendar.upsert({
|
|
where: {
|
|
userId: qaUserQuery.id,
|
|
externalId: primaryCalendarName,
|
|
eventTypeId: undefined,
|
|
},
|
|
update: {},
|
|
create: {
|
|
integration: "google_calendar",
|
|
userId: qaUserQuery.id,
|
|
externalId: primaryCalendarName,
|
|
credentialId: qaGCalCredential.id,
|
|
},
|
|
});
|
|
|
|
if (qaGCalCredential && qaUsername) runIntegrationTest = true;
|
|
}
|
|
|
|
test.skip(!runIntegrationTest, errorMessage);
|
|
});
|
|
|
|
test("On new booking, event should be created on GCal", async ({ page }) => {
|
|
const { gCalEvent, gCalReference, booking, authedCalendar } = await createBookingAndFetchGCalEvent(
|
|
page as Page,
|
|
qaGCalCredential,
|
|
qaUsername
|
|
);
|
|
|
|
assertValueExists(gCalEvent.start?.timeZone, "gCalEvent");
|
|
assertValueExists(gCalEvent.end?.timeZone, "gCalEvent");
|
|
|
|
// Ensure that the start and end times are matching
|
|
const startTimeMatches = dayjs(booking.startTime).isSame(
|
|
dayjs(gCalEvent.start.dateTime).tz(gCalEvent.start.timeZone)
|
|
);
|
|
const endTimeMatches = dayjs(booking.endTime).isSame(
|
|
dayjs(gCalEvent.end?.dateTime).tz(gCalEvent.end.timeZone)
|
|
);
|
|
expect(startTimeMatches && endTimeMatches).toBe(true);
|
|
|
|
// Ensure that the titles are matching
|
|
expect(booking.title).toBe(gCalEvent.summary);
|
|
|
|
// Ensure that the attendee is on the event
|
|
const bookingAttendee = booking?.attendees[0].email;
|
|
const attendeeInGCalEvent = gCalEvent.attendees?.find((attendee) => attendee.email === bookingAttendee);
|
|
expect(attendeeInGCalEvent).toBeTruthy();
|
|
|
|
await deleteBookingAndEvent(authedCalendar, booking.uid, gCalReference.uid);
|
|
});
|
|
|
|
test("On reschedule, event should be updated on GCal", async ({ page }) => {
|
|
// Reschedule the booking and check the gCalEvent's time is also changed
|
|
// On reschedule gCal UID stays the same
|
|
const { gCalReference, booking, authedCalendar } = await createBookingAndFetchGCalEvent(
|
|
page,
|
|
qaGCalCredential,
|
|
qaUsername
|
|
);
|
|
|
|
await page.locator('[data-testid="reschedule-link"]').click();
|
|
|
|
await selectSecondAvailableTimeSlotNextMonth(page);
|
|
await page.locator('[data-testid="confirm-reschedule-button"]').click();
|
|
|
|
await expect(page.locator("[data-testid=success-page]")).toBeVisible();
|
|
|
|
const rescheduledBookingUrl = await page.url();
|
|
const rescheduledBookingUid = rescheduledBookingUrl.match(/booking\/([^\/?]+)/);
|
|
|
|
assertValueExists(rescheduledBookingUid, "rescheduledBookingUid");
|
|
|
|
// Get the rescheduled booking start and end times
|
|
const rescheduledBooking = await prisma.booking.findFirst({
|
|
where: {
|
|
uid: rescheduledBookingUid[1],
|
|
},
|
|
select: {
|
|
startTime: true,
|
|
endTime: true,
|
|
},
|
|
});
|
|
assertValueExists(rescheduledBooking, "rescheduledBooking");
|
|
|
|
// The GCal event UID persists after reschedule but should get the rescheduled data
|
|
const gCalRescheduledEventResponse = await authedCalendar.events.get({
|
|
calendarId: "primary",
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
//@ts-ignore
|
|
eventId: gCalReference.uid,
|
|
});
|
|
|
|
expect(gCalRescheduledEventResponse.status).toBe(200);
|
|
|
|
const rescheduledGCalEvent = gCalRescheduledEventResponse.data;
|
|
|
|
assertValueExists(rescheduledGCalEvent.start?.timeZone, "rescheduledGCalEvent");
|
|
assertValueExists(rescheduledGCalEvent.end?.timeZone, "rescheduledGCalEvent");
|
|
|
|
// Ensure that the new start and end times are matching
|
|
const rescheduledStartTimeMatches = dayjs(rescheduledBooking.startTime).isSame(
|
|
dayjs(rescheduledGCalEvent.start?.dateTime).tz(rescheduledGCalEvent.start?.timeZone)
|
|
);
|
|
const rescheduledEndTimeMatches = dayjs(rescheduledBooking.endTime).isSame(
|
|
dayjs(rescheduledGCalEvent.end?.dateTime).tz(rescheduledGCalEvent.end.timeZone)
|
|
);
|
|
expect(rescheduledStartTimeMatches && rescheduledEndTimeMatches).toBe(true);
|
|
|
|
// After test passes we can delete the bookings and GCal event
|
|
await deleteBookingAndEvent(authedCalendar, booking.uid, gCalReference.uid);
|
|
|
|
await prisma.booking.delete({
|
|
where: {
|
|
uid: rescheduledBookingUid[1],
|
|
},
|
|
});
|
|
});
|
|
|
|
test("When canceling the booking, the GCal event should also be deleted", async ({ page }) => {
|
|
const { gCalReference, booking, authedCalendar } = await createBookingAndFetchGCalEvent(
|
|
page,
|
|
qaGCalCredential,
|
|
qaUsername
|
|
);
|
|
|
|
// Cancel the booking
|
|
await page.locator('[data-testid="cancel"]').click();
|
|
await page.locator('[data-testid="confirm_cancel"]').click();
|
|
// Query for the bookingUID and ensure that it doesn't exist on GCal
|
|
|
|
await page.waitForSelector('[data-testid="cancelled-headline"]');
|
|
|
|
const canceledGCalEventResponse = await authedCalendar.events.get({
|
|
calendarId: "primary",
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
//@ts-ignore
|
|
eventId: gCalReference.uid,
|
|
});
|
|
|
|
expect(canceledGCalEventResponse.data.status).toBe("cancelled");
|
|
|
|
// GCal API sees canceled events as already deleted
|
|
await deleteBookingAndEvent(authedCalendar, booking.uid);
|
|
});
|
|
});
|
|
});
|