Skip to content

Commit 15e0643

Browse files
committed
test(integration): add tests for session_exists redirect behavior
- Add tests in sign-in-flow.test.ts for regular sign-in with existing session - Add test in oauth-flows.test.ts for OAuth sign-in with existing session - Verify users are redirected and remain signed in instead of seeing errors
1 parent 2eb6101 commit 15e0643

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

integration/tests/oauth-flows.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,5 +256,26 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withLegalConsent] })(
256256

257257
await u.page.waitForAppUrl('/protected');
258258
});
259+
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
264+
await u.po.signIn.goTo();
265+
await u.page.getByRole('button', { name: 'E2E OAuth Provider' }).click();
266+
await u.page.getByText('Sign in to oauth-provider').waitFor();
267+
await u.po.signIn.setIdentifier(fakeUser.email);
268+
await u.po.signIn.continue();
269+
await u.po.signIn.enterTestOtpCode();
270+
await u.page.getByText('SignedIn').waitFor();
271+
await u.po.expect.toBeSignedIn();
272+
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();
279+
});
259280
},
260281
);

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,45 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes] })('sign in f
150150

151151
await u.po.expect.toBeSignedIn();
152152
});
153+
154+
test('redirects when attempting to sign in with existing session', async ({ page, context }) => {
155+
const u = createTestUtils({ app, page, context });
156+
157+
// First, sign in the user
158+
await u.po.signIn.goTo();
159+
await u.po.signIn.setIdentifier(fakeUser.email);
160+
await u.po.signIn.continue();
161+
await u.po.signIn.setPassword(fakeUser.password);
162+
await u.po.signIn.continue();
163+
await u.po.expect.toBeSignedIn();
164+
165+
// Now attempt to go to sign-in page again while already signed in
166+
await u.po.signIn.goTo();
167+
168+
// User should be redirected and remain signed in instead of seeing an error
169+
await u.po.expect.toBeSignedIn();
170+
});
171+
172+
test('redirects when attempting to sign in again with instant password and existing session', async ({
173+
page,
174+
context,
175+
}) => {
176+
const u = createTestUtils({ app, page, context });
177+
178+
// First, sign in the user
179+
await u.po.signIn.goTo();
180+
await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password });
181+
await u.po.expect.toBeSignedIn();
182+
183+
// Clear the page to go back to sign-in
184+
await u.page.goToRelative('/');
185+
await u.po.expect.toBeSignedIn();
186+
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();
193+
});
153194
});

0 commit comments

Comments
 (0)