2021-12-15 16:25:49 +00:00
|
|
|
import { expect, test } from "@playwright/test";
|
|
|
|
|
2022-03-17 19:36:11 +00:00
|
|
|
import * as teardown from "./lib/teardown";
|
2022-03-08 22:40:31 +00:00
|
|
|
import { createHttpServer, selectFirstAvailableTimeSlotNextMonth, todo, waitFor } from "./lib/testUtils";
|
2021-12-15 16:25:49 +00:00
|
|
|
|
|
|
|
test.describe("integrations", () => {
|
2022-03-17 19:36:11 +00:00
|
|
|
//teardown
|
|
|
|
test.afterAll(async () => {
|
|
|
|
await teardown.deleteAllWebhooksByEmail("pro@example.com");
|
|
|
|
await teardown.deleteAllBookingsByEmail("pro@example.com");
|
|
|
|
});
|
2021-12-15 16:25:49 +00:00
|
|
|
test.use({ storageState: "playwright/artifacts/proStorageState.json" });
|
|
|
|
|
|
|
|
test.beforeEach(async ({ page }) => {
|
|
|
|
await page.goto("/integrations");
|
|
|
|
});
|
|
|
|
|
|
|
|
todo("Can add Zoom integration");
|
|
|
|
|
|
|
|
todo("Can add Google Calendar");
|
|
|
|
|
|
|
|
todo("Can add Office 365 Calendar");
|
|
|
|
|
|
|
|
todo("Can add CalDav Calendar");
|
|
|
|
|
|
|
|
todo("Can add Apple Calendar");
|
|
|
|
|
|
|
|
test("add webhook & test that creating an event triggers a webhook call", async ({ page }, testInfo) => {
|
2021-10-18 21:07:06 +00:00
|
|
|
const webhookReceiver = createHttpServer();
|
|
|
|
|
|
|
|
// --- add webhook
|
|
|
|
await page.click('[data-testid="new_webhook"]');
|
2022-01-17 18:15:18 +00:00
|
|
|
|
|
|
|
await expect(page.locator(`[data-testid='WebhookDialogForm']`)).toBeVisible();
|
2021-10-18 21:07:06 +00:00
|
|
|
|
|
|
|
await page.fill('[name="subscriberUrl"]', webhookReceiver.url);
|
|
|
|
|
|
|
|
await page.click("[type=submit]");
|
|
|
|
|
|
|
|
// dialog is closed
|
2022-01-17 18:15:18 +00:00
|
|
|
await expect(page.locator(`[data-testid='WebhookDialogForm']`)).not.toBeVisible();
|
2021-10-18 21:07:06 +00:00
|
|
|
// page contains the url
|
2021-12-15 16:25:49 +00:00
|
|
|
expect(page.locator(`text='${webhookReceiver.url}'`)).toBeDefined();
|
2021-10-18 21:07:06 +00:00
|
|
|
|
2021-12-07 15:48:08 +00:00
|
|
|
// --- Book the first available day next month in the pro user's "30min"-event
|
2021-12-15 16:25:49 +00:00
|
|
|
await page.goto(`/pro/30min`);
|
2022-03-08 22:40:31 +00:00
|
|
|
await selectFirstAvailableTimeSlotNextMonth(page);
|
2021-10-18 21:07:06 +00:00
|
|
|
|
|
|
|
// --- fill form
|
|
|
|
await page.fill('[name="name"]', "Test Testson");
|
|
|
|
await page.fill('[name="email"]', "test@example.com");
|
|
|
|
await page.press('[name="email"]', "Enter");
|
|
|
|
|
|
|
|
// --- check that webhook was called
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(webhookReceiver.requestList.length).toBe(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
const [request] = webhookReceiver.requestList;
|
|
|
|
const body = request.body as any;
|
|
|
|
|
|
|
|
// remove dynamic properties that differs depending on where you run the tests
|
|
|
|
const dynamic = "[redacted/dynamic]";
|
|
|
|
body.createdAt = dynamic;
|
|
|
|
body.payload.startTime = dynamic;
|
|
|
|
body.payload.endTime = dynamic;
|
2021-12-21 00:59:06 +00:00
|
|
|
body.payload.location = dynamic;
|
2021-10-18 21:07:06 +00:00
|
|
|
for (const attendee of body.payload.attendees) {
|
|
|
|
attendee.timeZone = dynamic;
|
2022-01-27 20:32:53 +00:00
|
|
|
attendee.language = dynamic;
|
2021-10-18 21:07:06 +00:00
|
|
|
}
|
|
|
|
body.payload.organizer.timeZone = dynamic;
|
2022-01-27 20:32:53 +00:00
|
|
|
body.payload.organizer.language = dynamic;
|
2021-10-25 13:05:21 +00:00
|
|
|
body.payload.uid = dynamic;
|
2021-11-09 16:27:33 +00:00
|
|
|
body.payload.additionInformation = dynamic;
|
2021-10-18 21:07:06 +00:00
|
|
|
|
|
|
|
// if we change the shape of our webhooks, we can simply update this by clicking `u`
|
2021-11-02 14:19:40 +00:00
|
|
|
// console.log("BODY", body);
|
2021-12-15 16:25:49 +00:00
|
|
|
// Text files shouldn't have platform specific suffixes
|
|
|
|
testInfo.snapshotSuffix = "";
|
|
|
|
expect(JSON.stringify(body)).toMatchSnapshot(`webhookResponse.txt`);
|
2021-10-18 21:07:06 +00:00
|
|
|
|
|
|
|
webhookReceiver.close();
|
|
|
|
});
|
|
|
|
});
|