|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | + |
| 3 | +import { appConfigs } from '../presets'; |
| 4 | +import type { FakeUser } from '../testUtils'; |
| 5 | +import { createTestUtils, testAgainstRunningApps } from '../testUtils'; |
| 6 | + |
| 7 | +testAgainstRunningApps({ withEnv: [appConfigs.envs.withBilling] })('billing hooks @billing', ({ app }) => { |
| 8 | + test.describe.configure({ mode: 'parallel' }); |
| 9 | + test.skip(!app.name.includes('next'), 'Skipping: Only runs on next'); |
| 10 | + |
| 11 | + let fakeUser: FakeUser; |
| 12 | + |
| 13 | + test.beforeAll(async () => { |
| 14 | + const u = createTestUtils({ app }); |
| 15 | + fakeUser = u.services.users.createFakeUser(); |
| 16 | + await u.services.users.createBapiUser(fakeUser); |
| 17 | + }); |
| 18 | + |
| 19 | + test.afterAll(async () => { |
| 20 | + await fakeUser.deleteIfExists(); |
| 21 | + await app.teardown(); |
| 22 | + }); |
| 23 | + |
| 24 | + test.describe('when signed out', () => { |
| 25 | + test('renders billing hooks with plans, but no statements and no subscription', async ({ page, context }) => { |
| 26 | + const u = createTestUtils({ app, page, context }); |
| 27 | + await u.po.page.goToRelative('/billing/hooks'); |
| 28 | + |
| 29 | + await u.po.page.waitForClerkJsLoaded(); |
| 30 | + |
| 31 | + await expect(u.po.page.getByText('Plans found')).toBeVisible(); |
| 32 | + await expect(u.po.page.getByRole('heading', { name: 'Plan: Pro' })).toBeVisible(); |
| 33 | + await expect(u.po.page.getByText('No statements found')).toBeVisible(); |
| 34 | + await expect(u.po.page.getByText('No subscription found')).toBeVisible(); |
| 35 | + }); |
| 36 | + }); |
| 37 | + |
| 38 | + test.describe('when signed in', () => { |
| 39 | + test.describe.configure({ mode: 'serial' }); |
| 40 | + test('subscribes to a plan', async ({ page, context }) => { |
| 41 | + const u = createTestUtils({ app, page, context }); |
| 42 | + await u.po.signIn.goTo(); |
| 43 | + await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password }); |
| 44 | + await u.po.page.goToRelative('/pricing-table?newSubscriptionRedirectUrl=/pricing-table'); |
| 45 | + await u.po.pricingTable.waitForMounted(); |
| 46 | + await u.po.pricingTable.startCheckout({ planSlug: 'plus' }); |
| 47 | + await u.po.checkout.waitForMounted(); |
| 48 | + await u.po.checkout.fillTestCard(); |
| 49 | + await u.po.checkout.clickPayOrSubscribe(); |
| 50 | + await expect(u.po.checkout.root.getByText('Payment was successful!')).toBeVisible(); |
| 51 | + await u.po.checkout.confirmAndContinue(); |
| 52 | + }); |
| 53 | + |
| 54 | + test('renders billing hooks with plans, statements and subscription', async ({ page, context }) => { |
| 55 | + const u = createTestUtils({ app, page, context }); |
| 56 | + await u.po.signIn.goTo(); |
| 57 | + await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password }); |
| 58 | + await u.po.page.goToRelative('/billing/hooks'); |
| 59 | + |
| 60 | + await u.po.page.waitForClerkJsLoaded(); |
| 61 | + |
| 62 | + await expect(u.po.page.getByText('Plans found')).toBeVisible(); |
| 63 | + await expect(u.po.page.getByRole('heading', { name: 'Plan: Pro' })).toBeVisible(); |
| 64 | + |
| 65 | + await expect(u.po.page.getByText('Statements found')).toBeVisible(); |
| 66 | + await expect(u.po.page.getByText('Statement total: 99.96')).toBeVisible(); |
| 67 | + |
| 68 | + await expect(u.po.page.getByRole('heading', { name: 'Subscribed to Plus' })).toBeVisible(); |
| 69 | + |
| 70 | + await u.page.evaluate(async () => { |
| 71 | + await window.Clerk.signOut({ |
| 72 | + redirectUrl: '/billing/hooks', |
| 73 | + }); |
| 74 | + }); |
| 75 | + |
| 76 | + await expect(u.po.page.getByText('Plans found')).toBeVisible(); |
| 77 | + await expect(u.po.page.getByRole('heading', { name: 'Plan: Pro' })).toBeVisible(); |
| 78 | + await expect(u.po.page.getByText('No statements found')).toBeVisible(); |
| 79 | + await expect(u.po.page.getByText('No subscription found')).toBeVisible(); |
| 80 | + |
| 81 | + await expect(u.po.page.getByRole('heading', { name: 'Subscribed to Plus' })).toBeHidden(); |
| 82 | + await expect(u.po.page.getByText('Statements found', { exact: true })).toBeHidden(); |
| 83 | + await expect(u.po.page.getByText('Statement total: 99.96', { exact: true })).toBeHidden(); |
| 84 | + }); |
| 85 | + }); |
| 86 | +}); |
0 commit comments