|
| 1 | +import { test } from '@playwright/test'; |
| 2 | + |
| 3 | +import type { Application } from '../models/application'; |
| 4 | +import { appConfigs } from '../presets'; |
| 5 | +import type { FakeUser } from '../testUtils'; |
| 6 | +import { createTestUtils } from '../testUtils'; |
| 7 | + |
| 8 | +test.describe('session tasks eject flow @nextjs', () => { |
| 9 | + test.describe.configure({ mode: 'serial' }); |
| 10 | + let app: Application; |
| 11 | + let user: FakeUser; |
| 12 | + |
| 13 | + test.beforeAll(async () => { |
| 14 | + app = await appConfigs.next.appRouter |
| 15 | + .clone() |
| 16 | + .addFile( |
| 17 | + 'src/app/provider.tsx', |
| 18 | + () => `'use client' |
| 19 | +import { ClerkProvider } from "@clerk/nextjs"; |
| 20 | +
|
| 21 | +export function Provider({ children }: { children: any }) { |
| 22 | +return ( |
| 23 | + <ClerkProvider taskUrls={{ 'select-organization': '/onboarding/select-organization' }}> |
| 24 | + {children} |
| 25 | + </ClerkProvider> |
| 26 | +) |
| 27 | +}`, |
| 28 | + ) |
| 29 | + .addFile( |
| 30 | + 'src/app/layout.tsx', |
| 31 | + () => `import './globals.css'; |
| 32 | +import { Inter } from 'next/font/google'; |
| 33 | +import { Provider } from './provider'; |
| 34 | +
|
| 35 | +const inter = Inter({ subsets: ['latin'] }); |
| 36 | +
|
| 37 | +export const metadata = { |
| 38 | +title: 'Create Next App', |
| 39 | +description: 'Generated by create next app', |
| 40 | +}; |
| 41 | +
|
| 42 | +export default function RootLayout({ children }: { children: React.ReactNode }) { |
| 43 | +return ( |
| 44 | + <Provider> |
| 45 | + <html lang='en'> |
| 46 | + <body className={inter.className}>{children}</body> |
| 47 | + </html> |
| 48 | + </Provider> |
| 49 | +); |
| 50 | +}`, |
| 51 | + ) |
| 52 | + .addFile( |
| 53 | + 'src/app/onboarding/select-organization/page.tsx', |
| 54 | + () => ` |
| 55 | +import { TaskSelectOrganization } from '@clerk/nextjs'; |
| 56 | +
|
| 57 | +export default function Page() { |
| 58 | +return ( |
| 59 | + <TaskSelectOrganization redirectUrlComplete='/'/> |
| 60 | +); |
| 61 | +}`, |
| 62 | + ) |
| 63 | + .commit(); |
| 64 | + |
| 65 | + await app.setup(); |
| 66 | + await app.withEnv(appConfigs.envs.withSessionTasks); |
| 67 | + await app.dev(); |
| 68 | + |
| 69 | + const u = createTestUtils({ app }); |
| 70 | + user = u.services.users.createFakeUser(); |
| 71 | + await u.services.users.createBapiUser(user); |
| 72 | + }); |
| 73 | + |
| 74 | + test.afterAll(async () => { |
| 75 | + const u = createTestUtils({ app }); |
| 76 | + await user.deleteIfExists(); |
| 77 | + await u.services.organizations.deleteAll(); |
| 78 | + await app.teardown(); |
| 79 | + }); |
| 80 | + |
| 81 | + test.afterEach(async ({ page, context }) => { |
| 82 | + const u = createTestUtils({ app, page, context }); |
| 83 | + await u.page.signOut(); |
| 84 | + await u.page.context().clearCookies(); |
| 85 | + }); |
| 86 | + |
| 87 | + test('redirects to completion page after resolving task', async ({ page, context }) => { |
| 88 | + const u = createTestUtils({ app, page, context }); |
| 89 | + |
| 90 | + // Performs sign-in |
| 91 | + await u.po.signIn.goTo(); |
| 92 | + await u.po.signIn.setIdentifier(user.email); |
| 93 | + await u.po.signIn.continue(); |
| 94 | + await u.po.signIn.setPassword(user.password); |
| 95 | + await u.po.signIn.continue(); |
| 96 | + await u.po.expect.toBeSignedIn(); |
| 97 | + |
| 98 | + // Complete the organization selection task |
| 99 | + await u.page.waitForAppUrl('/onboarding/select-organization'); |
| 100 | + const fakeOrganization = Object.assign(u.services.organizations.createFakeOrganization(), { |
| 101 | + slug: u.services.organizations.createFakeOrganization().slug + '-eject-flow', |
| 102 | + }); |
| 103 | + await u.po.sessionTask.resolveForceOrganizationSelectionTask(fakeOrganization); |
| 104 | + await u.po.expect.toHaveResolvedTask(); |
| 105 | + |
| 106 | + // Verify redirect to completion page |
| 107 | + await u.page.waitForAppUrl('/'); |
| 108 | + }); |
| 109 | +}); |
0 commit comments