Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(e2e): Compare tokens on client recovery #5387

Merged
merged 1 commit into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/serious-tools-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
25 changes: 15 additions & 10 deletions integration/tests/resiliency.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test } from '@playwright/test';
import { expect, test } from '@playwright/test';

import { appConfigs } from '../presets';
import type { FakeUser } from '../testUtils';
Expand All @@ -24,17 +24,13 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes] })('resilienc
const u = createTestUtils({ app, page, context });

await u.po.signIn.goTo();

let waitForClientImmediately = page.waitForResponse(response => response.url().includes('/sign_ins'), {
timeout: 3_000,
});
await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password });

const clientReponse = await waitForClientImmediately;
const d = await clientReponse.json();

await u.po.expect.toBeSignedIn();

const tokenAfterSignIn = await page.evaluate(() => {
return window.Clerk?.session?.getToken();
});

// Simulate developer coming back and client fails to load.
await page.route('**/v1/client?**', route => {
return route.fulfill({
Expand All @@ -52,9 +48,11 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes] })('resilienc
}),
});
});

await page.waitForTimeout(1_000);
await page.reload();

waitForClientImmediately = page.waitForResponse(
const waitForClientImmediately = page.waitForResponse(
response => response.url().includes('/client?') && response.status() === 500,
{ timeout: 3_000 },
);
Expand All @@ -73,6 +71,13 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes] })('resilienc
// Wait for the client to be loaded. and the internal `getToken({skipCache: true})` to have been completed.
await u.po.clerk.toBeLoaded();

// Read the newly refreshed token.
const tokenOnClientOutage = await page.evaluate(() => {
return window.Clerk?.session?.getToken();
});

expect(tokenOnClientOutage).not.toEqual(tokenAfterSignIn);

await u.po.expect.toBeSignedIn();
});
});