1
1
import { expect , test } from '@playwright/test' ;
2
2
3
+ import { createClerkClient } from '@clerk/backend' ;
3
4
import { appConfigs } from '../presets' ;
5
+ import { instanceKeys } from '../presets/envs' ;
4
6
import type { FakeUser } from '../testUtils' ;
5
7
import { createTestUtils , testAgainstRunningApps } from '../testUtils' ;
6
- import type { FakeOrganization } from '../testUtils/organizationsService ' ;
8
+ import { createUserService } from '../testUtils/usersService ' ;
7
9
8
10
testAgainstRunningApps ( { withEnv : [ appConfigs . envs . withSessionTasks ] } ) (
9
11
'session tasks after sign-up flow @nextjs' ,
10
12
( { app } ) => {
11
13
test . describe . configure ( { mode : 'serial' } ) ;
12
14
13
15
let fakeUser : FakeUser ;
14
- let fakeOrganization : FakeOrganization ;
15
16
16
17
test . beforeAll ( ( ) => {
17
18
const u = createTestUtils ( { app } ) ;
@@ -20,7 +21,6 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withSessionTasks] })(
20
21
withPhoneNumber : true ,
21
22
withUsername : true ,
22
23
} ) ;
23
- fakeOrganization = u . services . organizations . createFakeOrganization ( ) ;
24
24
} ) ;
25
25
26
26
test . afterAll ( async ( ) => {
@@ -45,11 +45,49 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withSessionTasks] })(
45
45
expect ( page . url ( ) ) . toContain ( 'tasks' ) ;
46
46
47
47
// Resolves task
48
+ const fakeOrganization = u . services . organizations . createFakeOrganization ( ) ;
48
49
await u . po . sessionTask . resolveForceOrganizationSelectionTask ( fakeOrganization ) ;
49
50
await u . po . expect . toHaveResolvedTask ( ) ;
50
51
51
52
// Navigates to after sign-up
52
53
await u . page . waitForAppUrl ( '/' ) ;
53
54
} ) ;
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
+ } ) ;
54
92
} ,
55
93
) ;
0 commit comments