From a3fc15320714008a0dffc52a64f8e8558806b165 Mon Sep 17 00:00:00 2001 From: giancarlo Date: Mon, 15 Apr 2024 12:40:27 +0800 Subject: [PATCH] Update billing navigation and increase test timeout Changes include updating the user and team billing specs to increase visibility timeout and alter navigation route post-billing. Minor adjustments have been made to the page aesthetics and redirection logic. Also, refactored import statements for code organization purposes. Changes in the build script are also reflected in the commit. --- .github/workflows/workflow.yml | 14 +++++++++----- apps/e2e/tests/team-accounts/team-accounts.po.ts | 4 +--- apps/e2e/tests/team-billing/team-billing.spec.ts | 7 ++++--- apps/e2e/tests/user-billing/user-billing.spec.ts | 9 +++------ apps/e2e/tests/utils/billing.po.ts | 4 ++-- .../home/(user)/billing/return/page.tsx | 2 +- .../home/[account]/billing/return/page.tsx | 8 ++++++-- apps/web/package.json | 2 +- .../src/components/billing-session-status.tsx | 14 ++++++++------ 9 files changed, 35 insertions(+), 29 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index ceb14ebe6..aa41fe0d6 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -45,9 +45,6 @@ jobs: - name: Lint run: pnpm run lint - - name: Production Build (test env) - run: pnpm --filter web build:test - test: name: ⚫️ Test timeout-minutes: 8 @@ -105,12 +102,19 @@ jobs: - name: Supabase Server run: pnpm run supabase:web:start -- -x studio,migra,deno-relay,pgadmin-schema-diff,imgproxy,logflare - - name: Run App + - name: Stripe CLI run: | - pnpm run dev & + pnpm run stripe:listen & + + - name: Production Build (test env) + run: pnpm --filter web build:test + + - name: Run App + run: pnpm --filter web start:test - name: Run Playwright tests run: pnpm run test + - uses: actions/upload-artifact@v4 if: always() with: diff --git a/apps/e2e/tests/team-accounts/team-accounts.po.ts b/apps/e2e/tests/team-accounts/team-accounts.po.ts index 605f8332f..9fee03d0c 100644 --- a/apps/e2e/tests/team-accounts/team-accounts.po.ts +++ b/apps/e2e/tests/team-accounts/team-accounts.po.ts @@ -38,9 +38,7 @@ export class TeamAccountsPageObject { } goToBilling() { - return this.page.locator('a', { - hasText: 'Billing', - }).click(); + return this.page.getByRole('button', { name: 'Billing' }).click(); } async openAccountsSelector() { diff --git a/apps/e2e/tests/team-billing/team-billing.spec.ts b/apps/e2e/tests/team-billing/team-billing.spec.ts index b1651eaff..e55bf6b65 100644 --- a/apps/e2e/tests/team-billing/team-billing.spec.ts +++ b/apps/e2e/tests/team-billing/team-billing.spec.ts @@ -20,10 +20,11 @@ test.describe('Team Billing', () => { await po.billing.stripe.fillForm(); await po.billing.stripe.submitForm(); - await expect(po.billing.successStatus()).toBeVisible(); - await po.billing.returnToHome(); + await expect(po.billing.successStatus()).toBeVisible({ + timeout: 30000, + }); - await po.teamAccounts.goToBilling(); + await po.billing.returnToBilling(); await expect(await po.billing.getStatus()).toContainText('Trial'); await expect(po.billing.manageBillingButton()).toBeVisible(); diff --git a/apps/e2e/tests/user-billing/user-billing.spec.ts b/apps/e2e/tests/user-billing/user-billing.spec.ts index 5a3526f5e..b891fb224 100644 --- a/apps/e2e/tests/user-billing/user-billing.spec.ts +++ b/apps/e2e/tests/user-billing/user-billing.spec.ts @@ -19,14 +19,11 @@ test.describe('User Billing', () => { await po.billing.stripe.fillForm(); await po.billing.stripe.submitForm(); - await expect(po.billing.successStatus()).toBeVisible(); - await po.billing.returnToHome(); - - const link = page.locator('button', { - hasText: 'Billing' + await expect(po.billing.successStatus()).toBeVisible({ + timeout: 30000, }); - await link.click(); + await po.billing.returnToBilling(); await expect(await po.billing.getStatus()).toContainText('Trial'); await expect(po.billing.manageBillingButton()).toBeVisible(); diff --git a/apps/e2e/tests/utils/billing.po.ts b/apps/e2e/tests/utils/billing.po.ts index ff2f137f8..8cdd6bf28 100644 --- a/apps/e2e/tests/utils/billing.po.ts +++ b/apps/e2e/tests/utils/billing.po.ts @@ -28,11 +28,11 @@ export class BillingPageObject { return this.page.locator('[data-test="payment-return-success"]'); } - async returnToHome() { + async returnToBilling() { // wait a bit for the webhook to be processed await this.page.waitForTimeout(1000); - return this.page.locator('[data-test="checkout-success-back-link"] button').click(); + await this.page.locator('[data-test="checkout-success-back-link"]').click(); } proceedToCheckout() { diff --git a/apps/web/app/(dashboard)/home/(user)/billing/return/page.tsx b/apps/web/app/(dashboard)/home/(user)/billing/return/page.tsx index af543ef5f..221e880fa 100644 --- a/apps/web/app/(dashboard)/home/(user)/billing/return/page.tsx +++ b/apps/web/app/(dashboard)/home/(user)/billing/return/page.tsx @@ -1,5 +1,5 @@ // We reuse the page from the billing module // as there is no need to create a new one. -import ReturnCheckoutSessionPage from '../../../[account]/billing/return/page'; +import ReturnCheckoutSessionPage from '~/(dashboard)/home/[account]/billing/return/page'; export default ReturnCheckoutSessionPage; diff --git a/apps/web/app/(dashboard)/home/[account]/billing/return/page.tsx b/apps/web/app/(dashboard)/home/[account]/billing/return/page.tsx index 70f04ab34..905532a83 100644 --- a/apps/web/app/(dashboard)/home/[account]/billing/return/page.tsx +++ b/apps/web/app/(dashboard)/home/[account]/billing/return/page.tsx @@ -95,6 +95,10 @@ async function loadCheckoutSession(sessionId: string) { }; } +/** + * Revalidates the layout to update cached pages + * and redirects back to the home page. + */ // eslint-disable-next-line @typescript-eslint/require-await async function onRedirect() { 'use server'; @@ -103,6 +107,6 @@ async function onRedirect() { // which may have changed due to the billing session revalidatePath('/home', 'layout'); - // redirect back - redirect('../'); + // redirect back to billing page + redirect('../billing'); } diff --git a/apps/web/package.json b/apps/web/package.json index 6c9f7012b..b0f455e96 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -7,7 +7,7 @@ "scripts": { "analyze": "ANALYZE=true pnpm run build", "build": "pnpm with-env next build", - "build:test": "pnpm with-env:test next build", + "build:test": "NODE_ENV=test pnpm with-env:test next build", "clean": "git clean -xdf .next .turbo node_modules", "dev": "pnpm with-env next dev --turbo", "next:lint": "next lint", diff --git a/packages/billing/gateway/src/components/billing-session-status.tsx b/packages/billing/gateway/src/components/billing-session-status.tsx index 9ffd239bc..91a1bdc6e 100644 --- a/packages/billing/gateway/src/components/billing-session-status.tsx +++ b/packages/billing/gateway/src/components/billing-session-status.tsx @@ -20,15 +20,14 @@ export function BillingSessionStatus({
-
-