From 0093b6faa538f42e8d5b84513fcae47da7ed6a09 Mon Sep 17 00:00:00 2001 From: Jaideep Guntupalli <63718527+JaideepGuntupalli@users.noreply.github.com> Date: Thu, 13 Jul 2023 06:17:06 +0530 Subject: [PATCH] feat: Added e2e test paid booking should be able to be rescheduled (#10069) * feat: Added e2e test paid booking should be able to be rescheduled * refactor: abstracted and simplied the logic * fix: stripe iframe isnt the first frame * fix: import expect --- apps/web/playwright/fixtures/users.ts | 8 ++++++- .../web/playwright/integrations-stripe.e2e.ts | 24 ++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/apps/web/playwright/fixtures/users.ts b/apps/web/playwright/fixtures/users.ts index 8047305f42..a7a8262e3c 100644 --- a/apps/web/playwright/fixtures/users.ts +++ b/apps/web/playwright/fixtures/users.ts @@ -284,6 +284,7 @@ const createUserFixture = (user: UserWithIncludes, page: Page) => { setupEventWithPrice(eventType, store.page), bookAndPaidEvent: async (eventType: Pick) => bookAndPaidEvent(user, eventType, store.page), + makePaymentUsingStripe: async () => makePaymentUsingStripe(store.page), // ths is for developemnt only aimed to inject debugging messages in the metadata field of the user debug: async (message: string | Record) => { await prisma.user.update({ @@ -398,7 +399,12 @@ export async function bookAndPaidEvent( await Promise.all([page.waitForURL("/payment/*"), page.press('[name="email"]', "Enter")]); - const stripeFrame = page.frameLocator("iframe").first(); + await makePaymentUsingStripe(page); +} + +export async function makePaymentUsingStripe(page: Page) { + const stripeElement = await page.locator(".StripeElement").first(); + const stripeFrame = stripeElement.frameLocator("iframe").first(); await stripeFrame.locator('[name="number"]').fill("4242 4242 4242 4242"); const now = new Date(); await stripeFrame.locator('[name="expiry"]').fill(`${now.getMonth()} / ${now.getFullYear() + 1}`); diff --git a/apps/web/playwright/integrations-stripe.e2e.ts b/apps/web/playwright/integrations-stripe.e2e.ts index e1ebbac30b..52a4e9e81e 100644 --- a/apps/web/playwright/integrations-stripe.e2e.ts +++ b/apps/web/playwright/integrations-stripe.e2e.ts @@ -69,9 +69,31 @@ test.describe("Stripe integration", () => { await expect(page.getByText("Unconfirmed")).toBeVisible(); await expect(page.getByText("Pending payment").last()).toBeVisible(); }); + + 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); + await user.bookAndPaidEvent(eventType); + + // 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(); + }); 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"); });