Skip to content

Commit ebecedf

Browse files
authored
test(nextjs): Add basic testing structure for Dev Browser JWT (clerk#1535)
1 parent 876777c commit ebecedf

1 file changed

Lines changed: 89 additions & 0 deletions

File tree

integration/tests/db-jwt.test.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { test } from '@playwright/test';
2+
3+
import type { Application } from '../adapters/application';
4+
import { appConfigs } from '../presets';
5+
import type { FakeUser } from '../testUtils';
6+
import { createTestUtils } from '../testUtils';
7+
8+
test.describe('Dev Browser JWT test', () => {
9+
const configs = [appConfigs.longRunning.next.appRouterAllEnabled];
10+
11+
configs.forEach(config => {
12+
test.describe(`${config.name}`, () => {
13+
test.describe.configure({ mode: 'serial' });
14+
15+
let app: Application;
16+
let fakeUser: FakeUser;
17+
18+
test.beforeAll(async () => {
19+
app = await config.commit();
20+
await app.setup();
21+
await app.withEnv(appConfigs.instances.allEnabled);
22+
await app.dev();
23+
fakeUser = createTestUtils({ app }).services.users.createFakeUser();
24+
});
25+
26+
test.afterAll(async () => {
27+
await fakeUser.deleteIfExists();
28+
await app.teardown();
29+
});
30+
31+
test('sign up through accounts portal', async ({ page, context }) => {
32+
const u = createTestUtils({ app, page, context });
33+
await u.page.pause();
34+
await u.page.goToRelative('/protected');
35+
await u.page.waitForURL(/accounts/);
36+
await u.po.signIn.getGoToSignUp().click();
37+
await u.po.signUp.signUpWithEmailAndPassword({ email: fakeUser.email, password: fakeUser.password });
38+
await u.po.signUp.enterOtpCode(await u.services.email.getCodeForEmailAddress(fakeUser.email));
39+
await u.page.waitForURL(/protected/);
40+
await u.po.expect.toBeSignedIn();
41+
});
42+
43+
test('sign in through accounts portal', async ({ page, context }) => {
44+
const u = createTestUtils({ app, page, context });
45+
await u.page.pause();
46+
await u.page.goToRelative('/protected');
47+
await u.page.waitForURL(/accounts/);
48+
await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password });
49+
await u.page.waitForURL(/protected/);
50+
await u.po.expect.toBeSignedIn();
51+
});
52+
53+
test('Dev Browser JWT that gets appended to the URL when redirecting to Accounts Portal, overrides any existing Dev Browser JWT in AP', async ({
54+
page,
55+
context,
56+
}) => {});
57+
58+
/*
59+
- Try to access a protected page in localhost
60+
- You get redirected to Accounts Portal
61+
- Sign in with email and password
62+
- You get redirected back to localhost and are signed in
63+
- Delete cookies and storage on the browser on localhost
64+
- Try to access a protected page in localhost
65+
- Should be redirected to Accounts Portal and prompt to sign in
66+
- Sign in with email and password
67+
- Should be redirected back to localhost and are signed in
68+
*/
69+
test('Deleting localhost Dev Browser JWT should clear the signed in state in Accounts Portal when redirected', async ({
70+
page,
71+
context,
72+
}) => {});
73+
74+
/*
75+
- Access Accounts Portal directly
76+
- Sign in with email and password
77+
- You get redirected to accounts/default-redirect and are signed in
78+
- Access a protected page in localhost
79+
- Should be redirected to Accounts Portal and prompt to sign in
80+
- Sign in with email and password
81+
- Should be redirected back to localhost and are signed in
82+
*/
83+
test('Signing in to Accounts Portal directly and then trying to access localhost will redirect to Accounts Portal with a new Dev Browser', async ({
84+
page,
85+
context,
86+
}) => {});
87+
});
88+
});
89+
});

0 commit comments

Comments
 (0)