11import { expect , test } from '@playwright/test' ;
22
3+ import { createClerkClient } from '@clerk/backend' ;
34import { appConfigs } from '../presets' ;
5+ import { instanceKeys } from '../presets/envs' ;
46import type { FakeUser } from '../testUtils' ;
57import { createTestUtils , testAgainstRunningApps } from '../testUtils' ;
6- import type { FakeOrganization } from '../testUtils/organizationsService ' ;
8+ import { createUserService } from '../testUtils/usersService ' ;
79
810testAgainstRunningApps ( { withEnv : [ appConfigs . envs . withSessionTasks ] } ) (
911 'session tasks after sign-up flow @nextjs' ,
1012 ( { app } ) => {
1113 test . describe . configure ( { mode : 'serial' } ) ;
1214
1315 let fakeUser : FakeUser ;
14- let fakeOrganization : FakeOrganization ;
1516
1617 test . beforeAll ( ( ) => {
1718 const u = createTestUtils ( { app } ) ;
@@ -20,7 +21,6 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withSessionTasks] })(
2021 withPhoneNumber : true ,
2122 withUsername : true ,
2223 } ) ;
23- fakeOrganization = u . services . organizations . createFakeOrganization ( ) ;
2424 } ) ;
2525
2626 test . afterAll ( async ( ) => {
@@ -45,11 +45,49 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withSessionTasks] })(
4545 expect ( page . url ( ) ) . toContain ( 'tasks' ) ;
4646
4747 // Resolves task
48+ const fakeOrganization = u . services . organizations . createFakeOrganization ( ) ;
4849 await u . po . sessionTask . resolveForceOrganizationSelectionTask ( fakeOrganization ) ;
4950 await u . po . expect . toHaveResolvedTask ( ) ;
5051
5152 // Navigates to after sign-up
5253 await u . page . waitForAppUrl ( '/' ) ;
5354 } ) ;
55+
56+ test ( 'with sso, navigate to task on after sign-up' , async ( { page, context } ) => {
57+ const u = createTestUtils ( { app, page, context } ) ;
58+
59+ // Create a clerkClient for the OAuth provider instance
60+ const client = createClerkClient ( {
61+ secretKey : instanceKeys . get ( 'oauth-provider' ) . sk ,
62+ publishableKey : instanceKeys . get ( 'oauth-provider' ) . pk ,
63+ } ) ;
64+ const users = createUserService ( client ) ;
65+ fakeUser = users . createFakeUser ( {
66+ withUsername : true ,
67+ } ) ;
68+ // Create the user on the OAuth provider instance so we do not need to sign up twice
69+ await users . createBapiUser ( fakeUser ) ;
70+
71+ // Performs sign-up (transfer flow with sign-in) with SSO
72+ await u . po . signIn . goTo ( ) ;
73+ await u . page . getByRole ( 'button' , { name : 'E2E OAuth Provider' } ) . click ( ) ;
74+ await u . page . getByText ( 'Sign in to oauth-provider' ) . waitFor ( ) ;
75+ await u . po . signIn . setIdentifier ( fakeUser . email ) ;
76+ await u . po . signIn . continue ( ) ;
77+ await u . po . signIn . enterTestOtpCode ( ) ;
78+
79+ // Resolves task
80+ const fakeOrganization = u . services . organizations . createFakeOrganization ( ) ;
81+ await u . po . sessionTask . resolveForceOrganizationSelectionTask ( fakeOrganization ) ;
82+ await u . po . expect . toHaveResolvedTask ( ) ;
83+
84+ // Navigates to after sign-up
85+ await u . page . waitForAppUrl ( '/' ) ;
86+
87+ // Delete the user on the OAuth provider instance
88+ await fakeUser . deleteIfExists ( ) ;
89+ // Delete the user on the app instance.
90+ await u . services . users . deleteIfExists ( { email : fakeUser . email } ) ;
91+ } ) ;
5492 } ,
5593) ;
0 commit comments