2021-12-17 16:58:23 +00:00
|
|
|
import { expect, test } from "@playwright/test";
|
|
|
|
|
|
|
|
import { hasIntegrationInstalled } from "../lib/integrations/getIntegrations";
|
2022-03-17 19:36:11 +00:00
|
|
|
import * as teardown from "./lib/teardown";
|
2022-03-08 22:40:31 +00:00
|
|
|
import { selectFirstAvailableTimeSlotNextMonth, todo } from "./lib/testUtils";
|
2021-12-17 16:58:23 +00:00
|
|
|
|
|
|
|
test.describe.serial("Stripe integration", () => {
|
2022-03-17 19:36:11 +00:00
|
|
|
test.afterAll(() => {
|
|
|
|
teardown.deleteAllPaymentsByEmail("pro@example.com");
|
|
|
|
teardown.deleteAllBookingsByEmail("pro@example.com");
|
|
|
|
});
|
2021-12-17 16:58:23 +00:00
|
|
|
test.skip(!hasIntegrationInstalled("stripe_payment"), "It should only run if Stripe is installed");
|
|
|
|
|
|
|
|
test.describe.serial("Stripe integration dashboard", () => {
|
|
|
|
test.use({ storageState: "playwright/artifacts/proStorageState.json" });
|
|
|
|
|
|
|
|
test("Can add Stripe integration", async ({ page }) => {
|
|
|
|
await page.goto("/integrations");
|
|
|
|
/** We should see the "Connect" button for Stripe */
|
2022-01-17 18:15:18 +00:00
|
|
|
await expect(
|
|
|
|
page.locator(`li:has-text("Stripe") >> [data-testid="integration-connection-button"]`)
|
|
|
|
).toContainText("Connect");
|
2021-12-17 16:58:23 +00:00
|
|
|
|
|
|
|
/** We start the Stripe flow */
|
|
|
|
await Promise.all([
|
|
|
|
page.waitForNavigation({ url: "https://connect.stripe.com/oauth/v2/authorize?*" }),
|
2022-01-17 18:15:18 +00:00
|
|
|
page.click('li:has-text("Stripe") >> [data-testid="integration-connection-button"]'),
|
2021-12-17 16:58:23 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
await Promise.all([
|
|
|
|
page.waitForNavigation({ url: "/integrations" }),
|
|
|
|
/** We skip filling Stripe forms (testing mode only) */
|
2022-01-17 18:15:18 +00:00
|
|
|
page.click('[id="skip-account-app"]'),
|
2021-12-17 16:58:23 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
/** If Stripe is added correctly we should see the "Disconnect" button */
|
2022-01-17 18:15:18 +00:00
|
|
|
await expect(
|
2021-12-17 16:58:23 +00:00
|
|
|
page.locator(`li:has-text("Stripe") >> [data-testid="integration-connection-button"]`)
|
|
|
|
).toContainText("Disconnect");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Can book a paid booking", async ({ page }) => {
|
|
|
|
await page.goto("/pro/paid");
|
2022-03-08 22:40:31 +00:00
|
|
|
await selectFirstAvailableTimeSlotNextMonth(page);
|
2021-12-17 16:58:23 +00:00
|
|
|
// --- fill form
|
|
|
|
await page.fill('[name="name"]', "Stripe Stripeson");
|
|
|
|
await page.fill('[name="email"]', "test@example.com");
|
|
|
|
|
2022-01-17 18:15:18 +00:00
|
|
|
await Promise.all([page.waitForNavigation({ url: "/payment/*" }), page.press('[name="email"]', "Enter")]);
|
2021-12-17 16:58:23 +00:00
|
|
|
|
2022-02-18 22:16:53 +00:00
|
|
|
const stripeFrame = page
|
|
|
|
.frameLocator('iframe[src^="https://js.stripe.com/v3/elements-inner-card-"]')
|
|
|
|
.first();
|
2021-12-17 16:58:23 +00:00
|
|
|
|
|
|
|
// Fill [placeholder="Card number"]
|
2022-02-18 22:16:53 +00:00
|
|
|
await stripeFrame.locator('[placeholder="Card number"]').fill("4242 4242 4242 4242");
|
2021-12-17 16:58:23 +00:00
|
|
|
// Fill [placeholder="MM / YY"]
|
2022-02-18 22:16:53 +00:00
|
|
|
await stripeFrame.locator('[placeholder="MM / YY"]').fill("12 / 24");
|
2021-12-17 16:58:23 +00:00
|
|
|
// Fill [placeholder="CVC"]
|
2022-02-18 22:16:53 +00:00
|
|
|
await stripeFrame.locator('[placeholder="CVC"]').fill("111");
|
2021-12-17 16:58:23 +00:00
|
|
|
// Fill [placeholder="ZIP"]
|
2022-02-18 22:16:53 +00:00
|
|
|
await stripeFrame.locator('[placeholder="ZIP"]').fill("11111");
|
2021-12-17 16:58:23 +00:00
|
|
|
// Click button:has-text("Pay now")
|
|
|
|
await page.click('button:has-text("Pay now")');
|
|
|
|
|
|
|
|
// Make sure we're navigated to the success page
|
|
|
|
await page.waitForNavigation({
|
|
|
|
url(url) {
|
|
|
|
return url.pathname.endsWith("/success");
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
todo("Pending payment booking should not be confirmed by default");
|
|
|
|
todo("Payment should confirm pending payment booking");
|
|
|
|
todo("Payment should trigger a BOOKING_PAID webhook");
|
|
|
|
todo("Paid booking should be able to be rescheduled");
|
|
|
|
todo("Paid booking should be able to be cancelled");
|
|
|
|
todo("Cancelled paid booking should be refunded");
|
|
|
|
});
|