Files
cozsweet-frontend-nextjs/e2e/fixtures/helpers/payment.ts
T
Codex 2e04260ebd
Docker Image / Build and Push Docker Image (push) Successful in 2m15s
revert(payment): remove unsupported Stripe and EzPay upgrade
2026-07-29 18:15:20 +08:00

41 lines
1.9 KiB
TypeScript

import { expect, type Page } from "@playwright/test";
export async function completeVipPayment(page: Page) {
const checkoutButton = page.getByRole("button", { name: "Pay and Top Up" });
await expect(checkoutButton).toBeDisabled();
await page.getByRole("button", { name: /Monthly,/i }).click();
const renewalDialog = page.getByRole("dialog", {
name: "Automatic Renewal Confirmation",
});
await expect(renewalDialog).toBeVisible();
await renewalDialog.getByRole("button", { name: "Confirm" }).click();
await expect(checkoutButton).toBeEnabled();
const createOrderRequestPromise = page.waitForRequest("**/api/payment/create-order");
const orderStatusRequestPromise = page.waitForRequest("**/api/payment/order-status**");
await checkoutButton.click();
const createOrderRequest = await createOrderRequestPromise;
expect(createOrderRequest.postDataJSON()).toMatchObject({ planId: "vip_monthly", payChannel: "stripe" });
await orderStatusRequestPromise;
const paymentSuccessDialog = page.getByRole("alertdialog", { name: "Payment successful" });
await expect(paymentSuccessDialog).toBeVisible();
await paymentSuccessDialog.getByRole("button", { name: "OK" }).click();
}
export async function expectVipChatSubscriptionUrl(page: Page) {
await expect(page).toHaveURL(/\/subscription\?/);
const url = new URL(page.url());
expect(url.pathname).toBe("/subscription");
expect(url.searchParams.get("type")).toBe("vip");
expect(url.searchParams.get("returnTo")).toBe("chat");
}
export function expectAuthRedirectToVipChatSubscription(page: Page) {
const redirect = new URL(page.url()).searchParams.get("redirect");
expect(redirect).not.toBeNull();
const redirectUrl = new URL(redirect ?? "", "http://e2e.local");
expect(redirectUrl.pathname).toBe("/subscription");
expect(redirectUrl.searchParams.get("type")).toBe("vip");
expect(redirectUrl.searchParams.get("returnTo")).toBe("chat");
}