Skip to content

Commit 51c3c4c

Browse files
chore(repo): Add new test instance for protect service (#7242)
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 7be8f45 commit 51c3c4c

File tree

4 files changed

+67
-50
lines changed

4 files changed

+67
-50
lines changed

.changeset/beige-sloths-provide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
"@clerk/shared": minor
44
---
55

6-
Introduce ProtectConfig resource and Protect loader integration.
6+
Introduced initial Clerk Protect dynamic loader and related types to support dynamically enabling and rolling out Protect in the environment.

integration/.keys.json.sample

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,9 @@
5858
"with-api-keys": {
5959
"pk": "",
6060
"sk": ""
61+
},
62+
"with-protect-service": {
63+
"pk": "",
64+
"sk": ""
6165
}
6266
}

integration/presets/envs.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,12 @@ const withAPIKeys = base
185185
.setEnvVariable('private', 'CLERK_SECRET_KEY', instanceKeys.get('with-api-keys').sk)
186186
.setEnvVariable('public', 'CLERK_PUBLISHABLE_KEY', instanceKeys.get('with-api-keys').pk);
187187

188+
const withProtectService = base
189+
.clone()
190+
.setId('withProtectService')
191+
.setEnvVariable('private', 'CLERK_SECRET_KEY', instanceKeys.get('with-protect-service').sk)
192+
.setEnvVariable('public', 'CLERK_PUBLISHABLE_KEY', instanceKeys.get('with-protect-service').pk);
193+
188194
export const envs = {
189195
base,
190196
sessionsProd1,
@@ -212,4 +218,5 @@ export const envs = {
212218
withSignInOrUpwithRestrictedModeFlow,
213219
withWaitlistdMode,
214220
withWhatsappPhoneCode,
221+
withProtectService,
215222
} as const;

integration/tests/protect-service.test.ts

Lines changed: 55 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -17,60 +17,66 @@ const mockProtectSettings = async (page: Page, config?: ProtectConfigJSON) => {
1717
});
1818
};
1919

20-
testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes] })('Clerk Protect checks @generic', ({ app }) => {
21-
test.describe.configure({ mode: 'parallel' });
20+
testAgainstRunningApps({ withEnv: [appConfigs.envs.withProtectService] })(
21+
'Clerk Protect checks @generic',
22+
({ app }) => {
23+
test.describe.configure({ mode: 'parallel' });
2224

23-
test.afterAll(async () => {
24-
await app.teardown();
25-
});
26-
27-
test('should add loader script when protect_config.loader is set', async ({ page, context }) => {
28-
const u = createTestUtils({ app, page, context });
29-
await mockProtectSettings(page, {
30-
object: 'protect_config',
31-
id: 'n',
32-
loaders: [
33-
{
34-
rollout: 1.0,
35-
type: 'script',
36-
target: 'body',
37-
attributes: { id: 'test-protect-loader-1', type: 'module', src: 'data:application/json;base64,Cgo=' },
38-
},
39-
],
25+
test.afterAll(async () => {
26+
await app.teardown();
4027
});
41-
await u.page.goToAppHome();
42-
await u.page.waitForClerkJsLoaded();
4328

44-
await expect(page.locator('#test-protect-loader-1')).toHaveAttribute('type', 'module');
45-
});
29+
test('should add loader script when protect_config.loader is set', async ({ page, context }) => {
30+
const u = createTestUtils({ app, page, context });
31+
await mockProtectSettings(page, {
32+
object: 'protect_config',
33+
id: 'n',
34+
loaders: [
35+
{
36+
rollout: 1.0,
37+
type: 'script',
38+
target: 'body',
39+
attributes: { id: 'test-protect-loader-1', type: 'module', src: 'data:application/json;base64,Cgo=' },
40+
},
41+
],
42+
});
43+
await u.page.goToAppHome();
44+
await u.page.waitForClerkJsLoaded();
4645

47-
test('should not add loader script when protect_config.loader is set and rollout 0.00', async ({ page, context }) => {
48-
const u = createTestUtils({ app, page, context });
49-
await mockProtectSettings(page, {
50-
object: 'protect_config',
51-
id: 'n',
52-
loaders: [
53-
{
54-
rollout: 0, // force 0% rollout, should not materialize
55-
type: 'script',
56-
target: 'body',
57-
attributes: { id: 'test-protect-loader-2', type: 'module', src: 'data:application/json;base64,Cgo=' },
58-
},
59-
],
46+
await expect(page.locator('#test-protect-loader-1')).toHaveAttribute('type', 'module');
6047
});
61-
await u.page.goToAppHome();
62-
await u.page.waitForClerkJsLoaded();
6348

64-
await expect(page.locator('#test-protect-loader-2')).toHaveCount(0);
65-
});
49+
test('should not add loader script when protect_config.loader is set and rollout 0.00', async ({
50+
page,
51+
context,
52+
}) => {
53+
const u = createTestUtils({ app, page, context });
54+
await mockProtectSettings(page, {
55+
object: 'protect_config',
56+
id: 'n',
57+
loaders: [
58+
{
59+
rollout: 0, // force 0% rollout, should not materialize
60+
type: 'script',
61+
target: 'body',
62+
attributes: { id: 'test-protect-loader-2', type: 'module', src: 'data:application/json;base64,Cgo=' },
63+
},
64+
],
65+
});
66+
await u.page.goToAppHome();
67+
await u.page.waitForClerkJsLoaded();
6668

67-
test('should not create loader element when protect_config.loader is not set', async ({ page, context }) => {
68-
const u = createTestUtils({ app, page, context });
69-
await mockProtectSettings(page);
70-
await u.page.goToAppHome();
71-
await u.page.waitForClerkJsLoaded();
69+
await expect(page.locator('#test-protect-loader-2')).toHaveCount(0);
70+
});
7271

73-
// Playwright locators are always objects, never undefined
74-
await expect(page.locator('#test-protect-loader')).toHaveCount(0);
75-
});
76-
});
72+
test('should not create loader element when protect_config.loader is not set', async ({ page, context }) => {
73+
const u = createTestUtils({ app, page, context });
74+
await mockProtectSettings(page);
75+
await u.page.goToAppHome();
76+
await u.page.waitForClerkJsLoaded();
77+
78+
// Playwright locators are always objects, never undefined
79+
await expect(page.locator('#test-protect-loader')).toHaveCount(0);
80+
});
81+
},
82+
);

0 commit comments

Comments
 (0)