1
+ import { createClerkClient } from '@clerk/backend' ;
1
2
import { expect , test } from '@playwright/test' ;
2
3
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' ;
8
+ import { createUserService } from '../testUtils/usersService' ;
6
9
7
10
testAgainstRunningApps ( { withEnv : [ appConfigs . envs . withSessionTasks ] } ) (
8
11
'session tasks after sign-up flow @nextjs' ,
9
12
( { app } ) => {
10
13
test . describe . configure ( { mode : 'serial' } ) ;
11
14
12
- let fakeUser : FakeUser ;
15
+ let regularFakeUser : FakeUser ;
16
+ let fakeUserForOAuth : FakeUser ;
13
17
14
18
test . beforeEach ( ( ) => {
15
19
const u = createTestUtils ( { app } ) ;
16
- fakeUser = u . services . users . createFakeUser ( {
20
+ regularFakeUser = u . services . users . createFakeUser ( {
21
+ fictionalEmail : true ,
22
+ withPhoneNumber : true ,
23
+ withUsername : true ,
24
+ } ) ;
25
+ fakeUserForOAuth = u . services . users . createFakeUser ( {
17
26
fictionalEmail : true ,
18
27
withPhoneNumber : true ,
19
28
withUsername : true ,
@@ -23,10 +32,18 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withSessionTasks] })(
23
32
test . afterAll ( async ( ) => {
24
33
const u = createTestUtils ( { app } ) ;
25
34
await u . services . organizations . deleteAll ( ) ;
26
- // Delete the user on the OAuth provider instance.
27
- await fakeUser . deleteIfExists ( ) ;
28
- // Delete the user on the app instance.
29
- await u . services . users . deleteIfExists ( { email : fakeUser . email } ) ;
35
+ await regularFakeUser . deleteIfExists ( ) ;
36
+
37
+ // Delete user from OAuth provider instance
38
+ const client = createClerkClient ( {
39
+ secretKey : instanceKeys . get ( 'oauth-provider' ) . sk ,
40
+ publishableKey : instanceKeys . get ( 'oauth-provider' ) . pk ,
41
+ } ) ;
42
+ const users = createUserService ( client ) ;
43
+ await users . deleteIfExists ( { email : fakeUserForOAuth . email } ) ;
44
+ // Delete OAuth user from `with-session-tasks` instance
45
+ await u . services . users . deleteIfExists ( { email : fakeUserForOAuth . email } ) ;
46
+
30
47
await app . teardown ( ) ;
31
48
} ) ;
32
49
@@ -41,8 +58,8 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withSessionTasks] })(
41
58
const u = createTestUtils ( { app, page, context } ) ;
42
59
await u . po . signUp . goTo ( ) ;
43
60
await u . po . signUp . signUpWithEmailAndPassword ( {
44
- email : fakeUser . email ,
45
- password : fakeUser . password ,
61
+ email : regularFakeUser . email ,
62
+ password : regularFakeUser . password ,
46
63
} ) ;
47
64
await u . po . expect . toBeSignedIn ( ) ;
48
65
@@ -71,7 +88,7 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withSessionTasks] })(
71
88
await u . po . signIn . getGoToSignUp ( ) . click ( ) ;
72
89
73
90
await u . po . signUp . waitForMounted ( ) ;
74
- await u . po . signUp . setEmailAddress ( fakeUser . email ) ;
91
+ await u . po . signUp . setEmailAddress ( fakeUserForOAuth . email ) ;
75
92
await u . po . signUp . continue ( ) ;
76
93
await u . po . signUp . enterTestOtpCode ( ) ;
77
94
0 commit comments