Skip to content

Commit 7c28e7f

Browse files
committed
Add integration tests for protect service loader
Introduces tests to verify script creation based on protect_config.loader settings. Ensures the loader script is added when configured and absent otherwise.
1 parent f51eee9 commit 7c28e7f

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import type { ProtectConfigJSON } from '@clerk/shared/types';
2+
import type { Page } from '@playwright/test';
3+
import { expect, test } from '@playwright/test';
4+
5+
import { appConfigs } from '../presets';
6+
import { createTestUtils, testAgainstRunningApps } from '../testUtils';
7+
8+
const mockProtectSettings = async (page: Page, config: ProtectConfigJSON) => {
9+
await page.route('*/**/v1/environment*', async route => {
10+
const response = await route.fetch();
11+
const json = await response.json();
12+
const newJson = {
13+
...json,
14+
protect_config: config,
15+
};
16+
await route.fulfill({ response, json: newJson });
17+
});
18+
};
19+
20+
testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes] })('Hello World Div @xgeneric', ({ app }) => {
21+
test.describe.configure({ mode: 'parallel' });
22+
23+
test.afterAll(async () => {
24+
await app.teardown();
25+
});
26+
27+
test('should create 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+
loader: {
33+
type: 'script',
34+
target: 'body',
35+
attributes: { id: 'test-protect-loader', type: 'module', src: 'data:application/json;base64,Cgo=' },
36+
},
37+
});
38+
await u.page.goToAppHome();
39+
await u.page.waitForClerkJsLoaded();
40+
await expect(page.locator('#test-protect-loader')).toHaveAttribute('type', 'module');
41+
});
42+
43+
test('should not create Hello World div when protect_config.loader is not set', async ({ page, context }) => {
44+
const u = createTestUtils({ app, page, context });
45+
await mockProtectSettings(page, undefined);
46+
await u.page.goToAppHome();
47+
await u.page.waitForClerkJsLoaded();
48+
expect(page.locator('#test-protect-loader')).toBeUndefined();
49+
});
50+
});

0 commit comments

Comments
 (0)