Skip to content

Commit c5e26de

Browse files
committed
Remove duplicated test block between sign-in
1 parent 2a7ecba commit c5e26de

File tree

3 files changed

+20
-84
lines changed

3 files changed

+20
-84
lines changed

integration/tests/session-tasks-sign-in.test.ts

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { createClerkClient } from '@clerk/backend';
21
import { expect, test } from '@playwright/test';
32

3+
import { createClerkClient } from '@clerk/backend';
44
import { appConfigs } from '../presets';
55
import { instanceKeys } from '../presets/envs';
66
import type { FakeUser } from '../testUtils';
@@ -82,34 +82,5 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withSessionTasks] })(
8282
// Delete the user on the app instance.
8383
await u.services.users.deleteIfExists({ email: fakeUser.email });
8484
});
85-
86-
test('when switching sessions, navigate to task', async ({ page, context }) => {
87-
const u = createTestUtils({ app, page, context });
88-
fakeUser = u.services.users.createFakeUser();
89-
await u.services.users.createBapiUser(fakeUser);
90-
91-
// Create user for second session
92-
const fakeUser2 = u.services.users.createFakeUser();
93-
await u.services.users.createBapiUser(fakeUser2);
94-
95-
// Performs sign-in
96-
await u.po.signIn.goTo();
97-
await u.po.signIn.setIdentifier(fakeUser.email);
98-
await u.po.signIn.continue();
99-
await u.po.signIn.setPassword(fakeUser.password);
100-
await u.po.signIn.continue();
101-
await u.po.expect.toBeSignedIn();
102-
103-
// Resolves task
104-
const fakeOrganization = u.services.organizations.createFakeOrganization();
105-
await u.po.sessionTask.resolveForceOrganizationSelectionTask(fakeOrganization);
106-
await u.po.expect.toHaveResolvedTask();
107-
108-
// Navigates to after sign-in
109-
await u.page.waitForAppUrl('/');
110-
111-
await u.po.userButton.toggleTrigger();
112-
await u.po.userButton.waitForPopover();
113-
});
11485
},
11586
);
Lines changed: 10 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
import { expect, test } from '@playwright/test';
22

3-
import { createClerkClient } from '@clerk/backend';
43
import { appConfigs } from '../presets';
5-
import { instanceKeys } from '../presets/envs';
64
import type { FakeUser } from '../testUtils';
75
import { createTestUtils, testAgainstRunningApps } from '../testUtils';
8-
import { createUserService } from '../testUtils/usersService';
96

107
testAgainstRunningApps({ withEnv: [appConfigs.envs.withSessionTasks] })(
118
'session tasks after sign-up flow @nextjs',
129
({ app }) => {
1310
test.describe.configure({ mode: 'serial' });
1411

1512
let fakeUser: FakeUser;
13+
14+
test.beforeAll(() => {
15+
const u = createTestUtils({ app });
16+
fakeUser = u.services.users.createFakeUser({
17+
fictionalEmail: true,
18+
withPhoneNumber: true,
19+
withUsername: true,
20+
});
21+
});
22+
1623
test.afterAll(async () => {
1724
const u = createTestUtils({ app });
1825
await u.services.organizations.deleteAll();
@@ -23,11 +30,6 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withSessionTasks] })(
2330
test('navigate to task on after sign-up', async ({ page, context }) => {
2431
// Performs sign-up
2532
const u = createTestUtils({ app, page, context });
26-
fakeUser = u.services.users.createFakeUser({
27-
fictionalEmail: true,
28-
withPhoneNumber: true,
29-
withUsername: true,
30-
});
3133

3234
await u.po.signUp.goTo();
3335
await u.po.signUp.signUpWithEmailAndPassword({
@@ -48,42 +50,5 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withSessionTasks] })(
4850
// Navigates to after sign-up
4951
await u.page.waitForAppUrl('/');
5052
});
51-
52-
test('with sso, navigate to task on after sign-up', async ({ page, context }) => {
53-
const u = createTestUtils({ app, page, context });
54-
55-
// Create a clerkClient for the OAuth provider instance
56-
const client = createClerkClient({
57-
secretKey: instanceKeys.get('oauth-provider').sk,
58-
publishableKey: instanceKeys.get('oauth-provider').pk,
59-
});
60-
const users = createUserService(client);
61-
fakeUser = users.createFakeUser({
62-
withUsername: true,
63-
});
64-
// Create the user on the OAuth provider instance so we do not need to sign up twice
65-
await users.createBapiUser(fakeUser);
66-
67-
// Performs sign-up (transfer flow with sign-in) with SSO
68-
await u.po.signIn.goTo();
69-
await u.page.getByRole('button', { name: 'E2E OAuth Provider' }).click();
70-
await u.page.getByText('Sign in to oauth-provider').waitFor();
71-
await u.po.signIn.setIdentifier(fakeUser.email);
72-
await u.po.signIn.continue();
73-
await u.po.signIn.enterTestOtpCode();
74-
75-
// Resolves task
76-
const fakeOrganization = u.services.organizations.createFakeOrganization();
77-
await u.po.sessionTask.resolveForceOrganizationSelectionTask(fakeOrganization);
78-
await u.po.expect.toHaveResolvedTask();
79-
80-
// Navigates to after sign-up
81-
await u.page.waitForAppUrl('/');
82-
83-
// Delete the user on the OAuth provider instance
84-
await fakeUser.deleteIfExists();
85-
// Delete the user on the app instance.
86-
await u.services.users.deleteIfExists({ email: fakeUser.email });
87-
});
8853
},
8954
);

packages/clerk-js/src/core/clerk.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,15 @@ export class Clerk implements ClerkInterface {
12741274
return;
12751275
}
12761276

1277+
/**
1278+
* Invalidate previously cache pages with auth state before navigating
1279+
*/
1280+
const onBeforeSetActive: SetActiveHook =
1281+
typeof window !== 'undefined' && typeof window.__unstable__onBeforeSetActive === 'function'
1282+
? window.__unstable__onBeforeSetActive
1283+
: noop;
1284+
await onBeforeSetActive();
1285+
12771286
let newSession: SignedInSessionResource | null = session;
12781287

12791288
// Handles multi-session scenario when switching between `pending` sessions
@@ -1290,15 +1299,6 @@ export class Clerk implements ClerkInterface {
12901299
eventBus.emit(events.TokenUpdate, { token: null });
12911300
}
12921301

1293-
/**
1294-
* Invalidate previously cache pages with auth state before navigating
1295-
*/
1296-
const onBeforeSetActive: SetActiveHook =
1297-
typeof window !== 'undefined' && typeof window.__unstable__onBeforeSetActive === 'function'
1298-
? window.__unstable__onBeforeSetActive
1299-
: noop;
1300-
await onBeforeSetActive();
1301-
13021302
// Only triggers navigation for internal AIO components routing or multi-session switch
13031303
const isSwitchingSessions = this.session?.id != session.id;
13041304
const shouldNavigateOnSetActive = this.#componentNavigationContext || isSwitchingSessions;

0 commit comments

Comments
 (0)