2022-05-14 03:02:10 +00:00
|
|
|
import { expect } from "@playwright/test";
|
2023-07-01 17:18:27 +00:00
|
|
|
import type Prisma from "@prisma/client";
|
2021-12-17 16:58:23 +00:00
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
import { test } from "./lib/fixtures";
|
2023-09-27 21:30:22 +00:00
|
|
|
import type { Fixtures } from "./lib/fixtures";
|
2023-07-01 17:18:27 +00:00
|
|
|
import { todo, selectFirstAvailableTimeSlotNextMonth } from "./lib/testUtils";
|
2021-12-17 16:58:23 +00:00
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
test.describe.configure({ mode: "parallel" });
|
2023-03-01 20:18:51 +00:00
|
|
|
test.afterEach(({ users }) => users.deleteAll());
|
2022-05-14 03:02:10 +00:00
|
|
|
|
2022-03-23 22:00:30 +00:00
|
|
|
const IS_STRIPE_ENABLED = !!(
|
|
|
|
process.env.NEXT_PUBLIC_STRIPE_PUBLIC_KEY &&
|
2023-07-01 17:18:27 +00:00
|
|
|
process.env.STRIPE_CLIENT_ID &&
|
|
|
|
process.env.STRIPE_PRIVATE_KEY &&
|
|
|
|
process.env.PAYMENT_FEE_FIXED &&
|
|
|
|
process.env.PAYMENT_FEE_PERCENTAGE
|
2022-03-23 22:00:30 +00:00
|
|
|
);
|
|
|
|
|
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();
|
2023-06-06 18:02:32 +00:00
|
|
|
await user.apiLogin();
|
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
|
|
|
|
2023-07-01 17:18:27 +00:00
|
|
|
await expect(page.locator(`h3:has-text("Stripe")`)).toBeVisible();
|
|
|
|
await page.getByRole("list").getByRole("button").click();
|
|
|
|
await expect(page.getByRole("button", { name: "Remove App" })).toBeVisible();
|
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();
|
2023-07-01 17:18:27 +00:00
|
|
|
const eventType = user.eventTypes.find((e) => e.slug === "paid") as Prisma.EventType;
|
|
|
|
await user.apiLogin();
|
|
|
|
await page.goto("/apps/installed");
|
|
|
|
|
|
|
|
await user.getPaymentCredential();
|
|
|
|
await user.setupEventWithPrice(eventType);
|
2023-08-21 09:12:39 +00:00
|
|
|
await user.bookAndPayEvent(eventType);
|
2023-07-01 17:18:27 +00:00
|
|
|
// success
|
|
|
|
await expect(page.locator("[data-testid=success-page]")).toBeVisible();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Pending payment booking should not be confirmed by default", async ({ page, users }) => {
|
|
|
|
const user = await users.create();
|
|
|
|
const eventType = user.eventTypes.find((e) => e.slug === "paid") as Prisma.EventType;
|
2023-06-06 18:02:32 +00:00
|
|
|
await user.apiLogin();
|
2022-05-14 03:02:10 +00:00
|
|
|
await page.goto("/apps/installed");
|
2023-07-01 17:18:27 +00:00
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
await user.getPaymentCredential();
|
2023-07-01 17:18:27 +00:00
|
|
|
await user.setupEventWithPrice(eventType);
|
2022-05-14 03:02:10 +00:00
|
|
|
|
2023-07-01 17:18:27 +00:00
|
|
|
// booking process without payment
|
2023-06-06 11:59:57 +00:00
|
|
|
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");
|
|
|
|
|
2023-05-02 16:58:39 +00:00
|
|
|
await Promise.all([page.waitForURL("/payment/*"), page.press('[name="email"]', "Enter")]);
|
2021-12-17 16:58:23 +00:00
|
|
|
|
2023-07-01 17:18:27 +00:00
|
|
|
await page.goto(`/bookings/upcoming`);
|
2021-12-17 16:58:23 +00:00
|
|
|
|
2023-07-01 17:18:27 +00:00
|
|
|
await expect(page.getByText("Unconfirmed")).toBeVisible();
|
|
|
|
await expect(page.getByText("Pending payment").last()).toBeVisible();
|
2021-12-17 16:58:23 +00:00
|
|
|
});
|
2023-07-13 00:47:06 +00:00
|
|
|
|
|
|
|
test("Paid booking should be able to be rescheduled", async ({ page, users }) => {
|
|
|
|
const user = await users.create();
|
|
|
|
const eventType = user.eventTypes.find((e) => e.slug === "paid") as Prisma.EventType;
|
|
|
|
await user.apiLogin();
|
|
|
|
await page.goto("/apps/installed");
|
|
|
|
|
|
|
|
await user.getPaymentCredential();
|
|
|
|
await user.setupEventWithPrice(eventType);
|
2023-08-21 09:12:39 +00:00
|
|
|
await user.bookAndPayEvent(eventType);
|
2023-07-13 00:47:06 +00:00
|
|
|
|
|
|
|
// Rescheduling the event
|
|
|
|
await Promise.all([page.waitForURL("/booking/*"), page.click('[data-testid="reschedule-link"]')]);
|
|
|
|
|
|
|
|
await selectFirstAvailableTimeSlotNextMonth(page);
|
|
|
|
|
|
|
|
await Promise.all([
|
|
|
|
page.waitForURL("/payment/*"),
|
|
|
|
page.click('[data-testid="confirm-reschedule-button"]'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
await user.makePaymentUsingStripe();
|
|
|
|
});
|
2023-08-21 09:12:39 +00:00
|
|
|
|
|
|
|
test("Paid booking should be able to be cancelled", async ({ page, users }) => {
|
|
|
|
const user = await users.create();
|
|
|
|
const eventType = user.eventTypes.find((e) => e.slug === "paid") as Prisma.EventType;
|
|
|
|
await user.apiLogin();
|
|
|
|
await page.goto("/apps/installed");
|
|
|
|
|
|
|
|
await user.getPaymentCredential();
|
|
|
|
await user.setupEventWithPrice(eventType);
|
|
|
|
await user.bookAndPayEvent(eventType);
|
|
|
|
|
|
|
|
await page.click('[data-testid="cancel"]');
|
|
|
|
await page.click('[data-testid="confirm_cancel"]');
|
|
|
|
|
|
|
|
await expect(await page.locator('[data-testid="cancelled-headline"]').first()).toBeVisible();
|
|
|
|
});
|
|
|
|
|
|
|
|
test.describe("When event is paid and confirmed", () => {
|
|
|
|
let user: Awaited<ReturnType<Fixtures["users"]["create"]>>;
|
|
|
|
let eventType: Prisma.EventType;
|
|
|
|
|
|
|
|
test.beforeEach(async ({ page, users }) => {
|
|
|
|
user = await users.create();
|
|
|
|
eventType = user.eventTypes.find((e) => e.slug === "paid") as Prisma.EventType;
|
|
|
|
await user.apiLogin();
|
|
|
|
await page.goto("/apps/installed");
|
|
|
|
|
|
|
|
await user.getPaymentCredential();
|
|
|
|
await user.setupEventWithPrice(eventType);
|
|
|
|
await user.bookAndPayEvent(eventType);
|
|
|
|
await user.confirmPendingPayment();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Cancelled paid booking should be refunded", async ({ page, users, request }) => {
|
|
|
|
await page.click('[data-testid="cancel"]');
|
|
|
|
await page.click('[data-testid="confirm_cancel"]');
|
|
|
|
|
|
|
|
await expect(await page.locator('[data-testid="cancelled-headline"]').first()).toBeVisible();
|
|
|
|
await expect(page.getByText("This booking payment has been refunded")).toBeVisible();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Payment should confirm pending payment booking", async ({ page, users }) => {
|
|
|
|
await page.goto("/bookings/upcoming");
|
|
|
|
|
|
|
|
const paidBadge = page.locator('[data-testid="paid_badge"]').first();
|
|
|
|
|
|
|
|
await expect(paidBadge).toBeVisible();
|
|
|
|
expect(await paidBadge.innerText()).toBe("Paid");
|
|
|
|
});
|
|
|
|
|
2023-09-27 13:49:13 +00:00
|
|
|
test("Paid and confirmed booking should be able to be rescheduled", async ({ page, users }) => {
|
|
|
|
await Promise.all([page.waitForURL("/booking/*"), page.click('[data-testid="reschedule-link"]')]);
|
|
|
|
|
|
|
|
await selectFirstAvailableTimeSlotNextMonth(page);
|
|
|
|
|
|
|
|
await page.click('[data-testid="confirm-reschedule-button"]');
|
|
|
|
|
|
|
|
await expect(page.getByText("This meeting is scheduled")).toBeVisible();
|
|
|
|
});
|
|
|
|
|
2023-08-21 09:12:39 +00:00
|
|
|
todo("Payment should trigger a BOOKING_PAID webhook");
|
|
|
|
});
|
2023-09-27 21:30:22 +00:00
|
|
|
|
|
|
|
test.describe("Change stripe presented currency", () => {
|
|
|
|
test("Should be able to change currency", async ({ page, users }) => {
|
|
|
|
const user = await users.create();
|
|
|
|
const eventType = user.eventTypes.find((e) => e.slug === "paid") as Prisma.EventType;
|
|
|
|
await user.apiLogin();
|
|
|
|
|
|
|
|
await user.getPaymentCredential();
|
|
|
|
|
|
|
|
// Edit currency inside event type page
|
|
|
|
await page.goto(`/event-types/${eventType?.id}?tabName=apps`);
|
|
|
|
|
|
|
|
// Enable Stripe
|
|
|
|
await page.locator("#event-type-form").getByRole("switch").click();
|
|
|
|
|
|
|
|
// Set price
|
|
|
|
await page.getByTestId("price-input-stripe").fill("200");
|
|
|
|
|
|
|
|
// Select currency in dropdown
|
2023-09-28 12:03:01 +00:00
|
|
|
await page.locator(".text-black > .bg-default > div > div:nth-child(2)").first().click();
|
2023-09-27 21:30:22 +00:00
|
|
|
await page.locator("#react-select-2-input").fill("mexi");
|
|
|
|
await page.locator("#react-select-2-option-81").click();
|
|
|
|
|
|
|
|
await page.getByTestId("update-eventtype").click();
|
|
|
|
|
|
|
|
// Book event
|
|
|
|
await page.goto(`${user.username}/${eventType?.slug}`);
|
|
|
|
|
|
|
|
// Confirm MXN currency it's displayed use expect
|
|
|
|
await expect(await page.getByText("MX$200.00")).toBeVisible();
|
|
|
|
|
|
|
|
await selectFirstAvailableTimeSlotNextMonth(page);
|
|
|
|
|
|
|
|
// Confirm again in book form page
|
|
|
|
await expect(await page.getByText("MX$200.00")).toBeVisible();
|
|
|
|
|
|
|
|
// --- fill form
|
|
|
|
await page.fill('[name="name"]', "Stripe Stripeson");
|
|
|
|
await page.fill('[name="email"]', "stripe@example.com");
|
|
|
|
|
|
|
|
// Confirm booking
|
|
|
|
await page.click('[data-testid="confirm-book-button"]');
|
|
|
|
|
|
|
|
// wait for url to be payment
|
|
|
|
await page.waitForURL("/payment/*");
|
|
|
|
|
|
|
|
// Confirm again in book form page
|
|
|
|
await expect(await page.getByText("MX$200.00")).toBeVisible();
|
|
|
|
});
|
|
|
|
});
|
2021-12-17 16:58:23 +00:00
|
|
|
});
|