1
1
import { createClerkClient } from '@clerk/backend' ;
2
- import { expect , test } from '@playwright/test' ;
2
+ import { test } from '@playwright/test' ;
3
3
4
4
import { appConfigs } from '../presets' ;
5
5
import { instanceKeys } from '../presets/envs' ;
@@ -12,46 +12,54 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withSessionTasks] })(
12
12
( { app } ) => {
13
13
test . describe . configure ( { mode : 'serial' } ) ;
14
14
15
- let fakeUser : FakeUser ;
15
+ let user : FakeUser ;
16
16
17
17
test . beforeAll ( async ( ) => {
18
18
const u = createTestUtils ( { app } ) ;
19
- fakeUser = u . services . users . createFakeUser ( ) ;
20
- await u . services . users . createBapiUser ( fakeUser ) ;
19
+ user = u . services . users . createFakeUser ( ) ;
20
+ await u . services . users . createBapiUser ( user ) ;
21
21
} ) ;
22
22
23
23
test . afterAll ( async ( ) => {
24
24
const u = createTestUtils ( { app } ) ;
25
- await fakeUser . deleteIfExists ( ) ;
25
+ await user . deleteIfExists ( ) ;
26
26
await u . services . organizations . deleteAll ( ) ;
27
27
await app . teardown ( ) ;
28
28
} ) ;
29
29
30
- test . skip ( 'with email and password, navigate to task on after sign-in' , async ( { page, context } ) => {
30
+ test . afterEach ( async ( { page, context } ) => {
31
+ const u = createTestUtils ( { app, page, context } ) ;
32
+ await u . page . signOut ( ) ;
33
+ await u . page . context ( ) . clearCookies ( ) ;
34
+ } ) ;
35
+
36
+ test ( 'with email and password, navigate to task on after sign-in' , async ( { page, context } ) => {
31
37
const u = createTestUtils ( { app, page, context } ) ;
32
38
33
39
// Performs sign-in
34
40
await u . po . signIn . goTo ( ) ;
35
- await u . po . signIn . setIdentifier ( fakeUser . email ) ;
41
+ await u . po . signIn . setIdentifier ( user . email ) ;
36
42
await u . po . signIn . continue ( ) ;
37
- await u . po . signIn . setPassword ( fakeUser . password ) ;
43
+ await u . po . signIn . setPassword ( user . password ) ;
38
44
await u . po . signIn . continue ( ) ;
39
45
await u . po . expect . toBeSignedIn ( ) ;
40
46
41
47
// Redirects back to tasks when accessing protected route by `auth.protect`
42
48
await u . page . goToRelative ( '/page-protected' ) ;
43
- expect ( page . url ( ) ) . toContain ( 'tasks' ) ;
44
49
45
50
// Resolves task
46
- const fakeOrganization = u . services . organizations . createFakeOrganization ( ) ;
51
+ const fakeOrganization = Object . assign ( u . services . organizations . createFakeOrganization ( ) , {
52
+ slug : u . services . organizations . createFakeOrganization ( ) . slug + '-with-sign-in-password' ,
53
+ } ) ;
54
+ await u . po . signIn . waitForMounted ( ) ;
47
55
await u . po . sessionTask . resolveForceOrganizationSelectionTask ( fakeOrganization ) ;
48
56
await u . po . expect . toHaveResolvedTask ( ) ;
49
57
50
58
// Navigates to after sign-in
51
59
await u . page . waitForAppUrl ( '/' ) ;
52
60
} ) ;
53
61
54
- test . skip ( 'with sso, navigate to task on after sign-in' , async ( { page, context } ) => {
62
+ test ( 'with sso, navigate to task on after sign-in' , async ( { page, context } ) => {
55
63
const u = createTestUtils ( { app, page, context } ) ;
56
64
57
65
// Create a clerkClient for the OAuth provider instance
@@ -60,32 +68,35 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withSessionTasks] })(
60
68
publishableKey : instanceKeys . get ( 'oauth-provider' ) . pk ,
61
69
} ) ;
62
70
const users = createUserService ( client ) ;
63
- fakeUser = users . createFakeUser ( {
71
+ const userFromOAuth = users . createFakeUser ( {
64
72
withUsername : true ,
65
73
} ) ;
66
74
// Create the user on the OAuth provider instance so we do not need to sign up twice
67
- await users . createBapiUser ( fakeUser ) ;
75
+ await users . createBapiUser ( userFromOAuth ) ;
68
76
69
77
// Performs sign-in with SSO
70
78
await u . po . signIn . goTo ( ) ;
71
79
await u . page . getByRole ( 'button' , { name : 'E2E OAuth Provider' } ) . click ( ) ;
72
80
await u . page . getByText ( 'Sign in to oauth-provider' ) . waitFor ( ) ;
73
- await u . po . signIn . setIdentifier ( fakeUser . email ) ;
81
+ await u . po . signIn . setIdentifier ( userFromOAuth . email ) ;
74
82
await u . po . signIn . continue ( ) ;
75
83
await u . po . signIn . enterTestOtpCode ( ) ;
76
84
77
85
// Resolves task
78
- const fakeOrganization = u . services . organizations . createFakeOrganization ( ) ;
86
+ await u . po . signIn . waitForMounted ( ) ;
87
+ const fakeOrganization = Object . assign ( u . services . organizations . createFakeOrganization ( ) , {
88
+ slug : u . services . organizations . createFakeOrganization ( ) . slug + '-with-sign-in-sso' ,
89
+ } ) ;
79
90
await u . po . sessionTask . resolveForceOrganizationSelectionTask ( fakeOrganization ) ;
80
91
await u . po . expect . toHaveResolvedTask ( ) ;
81
92
82
93
// Navigates to after sign-in
83
94
await u . page . waitForAppUrl ( '/' ) ;
84
95
85
96
// Delete the user on the OAuth provider instance
86
- await fakeUser . deleteIfExists ( ) ;
97
+ await userFromOAuth . deleteIfExists ( ) ;
87
98
// Delete the user on the app instance.
88
- await u . services . users . deleteIfExists ( { email : fakeUser . email } ) ;
99
+ await u . services . users . deleteIfExists ( { email : userFromOAuth . email } ) ;
89
100
} ) ;
90
101
} ,
91
102
) ;
0 commit comments