2022-05-14 03:02:10 +00:00
|
|
|
import { expect } from "@playwright/test";
|
2021-12-17 16:58:23 +00:00
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
import { test } from "./lib/fixtures";
|
2022-03-08 22:40:31 +00:00
|
|
|
import { selectFirstAvailableTimeSlotNextMonth, todo } from "./lib/testUtils";
|
2021-12-17 16:58:23 +00:00
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
test.describe.configure({ mode: "parallel" });
|
|
|
|
|
2022-03-23 22:00:30 +00:00
|
|
|
const IS_STRIPE_ENABLED = !!(
|
|
|
|
process.env.STRIPE_CLIENT_ID &&
|
|
|
|
process.env.NEXT_PUBLIC_STRIPE_PUBLIC_KEY &&
|
|
|
|
process.env.STRIPE_PRIVATE_KEY
|
|
|
|
);
|
|
|
|
|
2022-09-15 19:53:09 +00:00
|
|
|
// TODO: No longer up to date, rewrite needed.
|
|
|
|
|
|
|
|
// eslint-disable-next-line playwright/no-skipped-test
|
|
|
|
test.skip();
|
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
test.describe("Stripe integration", () => {
|
2022-05-17 19:31:49 +00:00
|
|
|
// eslint-disable-next-line playwright/no-skipped-test
|
2022-03-23 22:00:30 +00:00
|
|
|
test.skip(!IS_STRIPE_ENABLED, "It should only run if Stripe is installed");
|
2021-12-17 16:58:23 +00:00
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
test.describe("Stripe integration dashboard", () => {
|
|
|
|
test("Can add Stripe integration", async ({ page, users }) => {
|
|
|
|
const user = await users.create();
|
|
|
|
await user.login();
|
2022-03-23 22:00:30 +00:00
|
|
|
await page.goto("/apps/installed");
|
2021-12-17 16:58:23 +00:00
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
await user.getPaymentCredential();
|
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(
|
2022-08-26 18:44:02 +00:00
|
|
|
page.locator(`li:has-text("Stripe") >> [data-testid="stripe_payment-integration-disconnect-button"]`)
|
2022-09-15 19:53:09 +00:00
|
|
|
).toContainText("");
|
2022-05-14 03:02:10 +00:00
|
|
|
|
|
|
|
// Cleanup
|
2022-07-06 19:31:07 +00:00
|
|
|
await users.deleteAll();
|
2021-12-17 16:58:23 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
test("Can book a paid booking", async ({ page, users }) => {
|
|
|
|
const user = await users.create();
|
|
|
|
const eventType = user.eventTypes.find((e) => e.slug === "paid")!;
|
|
|
|
await user.login();
|
|
|
|
await page.goto("/apps/installed");
|
|
|
|
await user.getPaymentCredential();
|
|
|
|
|
|
|
|
await page.goto(`${user.username}/${eventType.slug}`);
|
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
|
2022-05-11 16:46:52 +00:00
|
|
|
await expect(page.locator("[data-testid=success-page]")).toBeVisible();
|
2022-05-14 03:02:10 +00:00
|
|
|
|
|
|
|
// Cleanup
|
2022-07-06 19:31:07 +00:00
|
|
|
await users.deleteAll();
|
2021-12-17 16:58:23 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
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");
|
|
|
|
});
|