Skip to content

Commit 6976aae

Browse files
authored
chore(e2e): Run existing protect tests with a JWT v2 instance (#5615)
1 parent 5ce5147 commit 6976aae

File tree

7 files changed

+22
-2
lines changed

7 files changed

+22
-2
lines changed

.changeset/purple-falcons-behave.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

.changeset/silly-spies-cut.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

integration/models/longRunningApplication.ts

+3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export const longRunningApplication = (params: LongRunningApplicationParams) =>
6262
try {
6363
const publishableKey = params.env.publicVariables.get('CLERK_PUBLISHABLE_KEY');
6464
const secretKey = params.env.privateVariables.get('CLERK_SECRET_KEY');
65+
const apiUrl = params.env.privateVariables.get('CLERK_API_URL');
6566
const { instanceType, frontendApi: frontendApiUrl } = parsePublishableKey(publishableKey);
6667

6768
if (instanceType !== 'development') {
@@ -71,6 +72,8 @@ export const longRunningApplication = (params: LongRunningApplicationParams) =>
7172
publishableKey,
7273
frontendApiUrl,
7374
secretKey,
75+
// @ts-expect-error apiUrl is not a typed option for clerkSetup, but it is accepted at runtime.
76+
apiUrl,
7477
dotenv: false,
7578
});
7679
}

integration/presets/envs.ts

+8
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ const withSessionTasks = base
144144
.setEnvVariable('public', 'CLERK_PUBLISHABLE_KEY', instanceKeys.get('with-session-tasks').pk)
145145
.setEnvVariable('private', 'CLERK_ENCRYPTION_KEY', constants.E2E_CLERK_ENCRYPTION_KEY || 'a-key');
146146

147+
const withBillingStaging = base
148+
.clone()
149+
.setId('withBillingStaging')
150+
.setEnvVariable('private', 'CLERK_API_URL', 'https://api.clerkstage.dev')
151+
.setEnvVariable('private', 'CLERK_SECRET_KEY', instanceKeys.get('with-billing-staging').sk)
152+
.setEnvVariable('public', 'CLERK_PUBLISHABLE_KEY', instanceKeys.get('with-billing-staging').pk);
153+
147154
export const envs = {
148155
base,
149156
withKeyless,
@@ -165,4 +172,5 @@ export const envs = {
165172
withSignInOrUpEmailLinksFlow,
166173
withSignInOrUpwithRestrictedModeFlow,
167174
withSessionTasks,
175+
withBillingStaging,
168176
} as const;

integration/presets/longRunningApps.ts

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export const createLongRunningApps = () => {
4242
config: next.appRouter,
4343
env: envs.withSessionTasks,
4444
},
45+
{ id: 'next.appRouter.withBillingStaging', config: next.appRouter, env: envs.withBillingStaging },
4546
{
4647
id: 'next.appRouter.withLegalConsent',
4748
config: next.appRouter,

integration/tests/protect.test.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import { appConfigs } from '../presets';
55
import type { FakeOrganization, FakeUser } from '../testUtils';
66
import { createTestUtils, testAgainstRunningApps } from '../testUtils';
77

8-
testAgainstRunningApps({ withEnv: [appConfigs.envs.withCustomRoles] })('authorization @nextjs', ({ app }) => {
8+
testAgainstRunningApps({
9+
withEnv: [appConfigs.envs.withCustomRoles, appConfigs.envs.withBillingStaging],
10+
})('authorization @nextjs', ({ app }) => {
911
test.describe.configure({ mode: 'serial' });
1012

1113
let fakeAdmin: FakeUser;
@@ -40,6 +42,8 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withCustomRoles] })('authoriz
4042
await u.po.signIn.waitForMounted();
4143
await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeAdmin.email, password: fakeAdmin.password });
4244
await u.po.expect.toBeSignedIn();
45+
const jwtVersion = await page.evaluate(() => window.Clerk.session?.lastActiveToken?.jwt?.claims?.v);
46+
expect(jwtVersion).toBe(app.env.id === 'withBillingStaging' ? 2 : undefined);
4347

4448
await u.po.organizationSwitcher.goTo();
4549
await u.po.organizationSwitcher.waitForMounted();

packages/testing/src/common/setup.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const fetchEnvVars = async (options?: ClerkSetupOptions): Promise<ClerkSe
4848
log('Fetching testing token from Clerk Backend API...');
4949

5050
try {
51-
const apiUrl = process.env.CLERK_API_URL;
51+
const apiUrl = (rest as any)?.apiUrl || process.env.CLERK_API_URL;
5252
const clerkClient = createClerkClient({ secretKey, apiUrl });
5353
const tokenData = await clerkClient.testingTokens.createTestingToken();
5454
testingToken = tokenData.token;

0 commit comments

Comments
 (0)