Skip to content

Commit a57c28d

Browse files
committed
test(integration): fix session_exists tests to use separate tabs
- Use runInNewTab to properly test session_exists scenario - First tab signs in, second tab attempts to sign in with same user - This triggers the session_exists error that the code handles - Without separate tabs, SignIn component would auto-redirect on mount
1 parent 15e0643 commit a57c28d

File tree

2 files changed

+48
-29
lines changed

2 files changed

+48
-29
lines changed

integration/tests/oauth-flows.test.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,14 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withLegalConsent] })(
257257
await u.page.waitForAppUrl('/protected');
258258
});
259259

260-
test('redirects when attempting OAuth sign in with existing session', async ({ page, context }) => {
261-
const u = createTestUtils({ app, page, context });
262-
263-
// First, sign in the user via OAuth
260+
test('redirects when attempting OAuth sign in with existing session in another tab', async ({
261+
page,
262+
context,
263+
browser,
264+
}) => {
265+
const u = createTestUtils({ app, page, context, browser });
266+
267+
// Sign in on the first tab via OAuth
264268
await u.po.signIn.goTo();
265269
await u.page.getByRole('button', { name: 'E2E OAuth Provider' }).click();
266270
await u.page.getByText('Sign in to oauth-provider').waitFor();
@@ -270,12 +274,18 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withLegalConsent] })(
270274
await u.page.getByText('SignedIn').waitFor();
271275
await u.po.expect.toBeSignedIn();
272276

273-
// Now attempt to sign in again via OAuth while already signed in
274-
await u.po.signIn.goTo();
275-
await u.page.getByRole('button', { name: 'E2E OAuth Provider' }).click();
276-
277-
// Should redirect and remain signed in instead of showing an error
278-
await u.po.expect.toBeSignedIn();
277+
// Open a new tab and attempt to sign in again via OAuth with the same user
278+
await u.tabs.runInNewTab(async u2 => {
279+
await u2.po.signIn.goTo();
280+
await u2.page.getByRole('button', { name: 'E2E OAuth Provider' }).click();
281+
await u2.page.getByText('Sign in to oauth-provider').waitFor();
282+
await u2.po.signIn.setIdentifier(fakeUser.email);
283+
await u2.po.signIn.continue();
284+
await u2.po.signIn.enterTestOtpCode();
285+
286+
// Should redirect and remain signed in instead of showing an error
287+
await u2.po.expect.toBeSignedIn();
288+
});
279289
});
280290
},
281291
);

integration/tests/sign-in-flow.test.ts

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -151,44 +151,53 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes] })('sign in f
151151
await u.po.expect.toBeSignedIn();
152152
});
153153

154-
test('redirects when attempting to sign in with existing session', async ({ page, context }) => {
155-
const u = createTestUtils({ app, page, context });
154+
test('redirects when attempting to sign in with existing session in another tab', async ({
155+
page,
156+
context,
157+
browser,
158+
}) => {
159+
const u = createTestUtils({ app, page, context, browser });
156160

157-
// First, sign in the user
161+
// Sign in on the first tab
158162
await u.po.signIn.goTo();
159163
await u.po.signIn.setIdentifier(fakeUser.email);
160164
await u.po.signIn.continue();
161165
await u.po.signIn.setPassword(fakeUser.password);
162166
await u.po.signIn.continue();
163167
await u.po.expect.toBeSignedIn();
164168

165-
// Now attempt to go to sign-in page again while already signed in
166-
await u.po.signIn.goTo();
169+
// Open a new tab and attempt to sign in again with the same user
170+
await u.tabs.runInNewTab(async u2 => {
171+
await u2.po.signIn.goTo();
172+
await u2.po.signIn.setIdentifier(fakeUser.email);
173+
await u2.po.signIn.continue();
174+
await u2.po.signIn.setPassword(fakeUser.password);
175+
await u2.po.signIn.continue();
167176

168-
// User should be redirected and remain signed in instead of seeing an error
169-
await u.po.expect.toBeSignedIn();
177+
// Should redirect and be signed in without error
178+
await u2.po.expect.toBeSignedIn();
179+
});
170180
});
171181

172-
test('redirects when attempting to sign in again with instant password and existing session', async ({
182+
test('redirects when attempting to sign in again with instant password in another tab', async ({
173183
page,
174184
context,
185+
browser,
175186
}) => {
176-
const u = createTestUtils({ app, page, context });
187+
const u = createTestUtils({ app, page, context, browser });
177188

178-
// First, sign in the user
189+
// Sign in on the first tab
179190
await u.po.signIn.goTo();
180191
await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password });
181192
await u.po.expect.toBeSignedIn();
182193

183-
// Clear the page to go back to sign-in
184-
await u.page.goToRelative('/');
185-
await u.po.expect.toBeSignedIn();
194+
// Open a new tab and attempt to sign in again with instant password
195+
await u.tabs.runInNewTab(async u2 => {
196+
await u2.po.signIn.goTo();
197+
await u2.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password });
186198

187-
// Attempt to sign in again with instant password
188-
await u.po.signIn.goTo();
189-
await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password });
190-
191-
// Should redirect and remain signed in without error
192-
await u.po.expect.toBeSignedIn();
199+
// Should redirect and remain signed in without error
200+
await u2.po.expect.toBeSignedIn();
201+
});
193202
});
194203
});

0 commit comments

Comments
 (0)