Skip to content

Commit

Permalink
Introduce skeleton for integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LauraBeatris committed Feb 25, 2025
1 parent 1233d3b commit e15d124
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .changeset/old-cherries-laugh.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
'@clerk/types': patch
---

Navigate to after-auth tasks
Navigate to session tasks
35 changes: 35 additions & 0 deletions integration/tests/session-tasks.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { appConfigs } from '../presets';
import { testAgainstRunningApps } from '../testUtils';

// TODO ORGS-566 - write integration tests for after-auth flow
testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes] })('after-auth flows @generic @nextjs', () => {
describe('after sign-in', () => {
// /sign-in -> /sign-in/select-organization
it.todo('navigates to tasks');

// /sign-in -> /sign-in/select-organization -> /app (after-sign-in URL)
it.todo('navigates to after-sign-in URL when tasks get resolved');

// with session status pending -> accesses /sign-in -> redirects to /sign-in/select-organization
it.todo('on single-session mode, sign-in redirects back to tasks when accessed with a pending session');
});

describe('after sign-up', () => {
// /sign-up -> /sign-up/select-organization
it.todo('navigates to tasks');

// /sign-up -> /sign-up/select-organization -> /app/welcome (after-sign-up URL)
it.todo('navigates to after-sign-up URL when tasks get resolved');

// with session status pending -> accesses /sign-up -> redirects to /sign-up/select-organization
it.todo('on single-session mode, sign-up redirects back to tasks when accessed with a pending session');
});

describe('middle app', () => {
// /my-dashboard/recipes -> /sign-in/select-organization
it.todo('on session transition to pending with tasks, redirects to tasks');

// /my-dashboard/recipes -> /sign-in/select-organization -> /my-dashboard/recipes
it.todo('navigates to middle app origin when tasks get resolved');
});
});
54 changes: 10 additions & 44 deletions packages/clerk-js/src/core/__tests__/clerk.redirects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,55 +312,21 @@ describe('Clerk singleton - Redirects', () => {
});
});

describe('on signed-in session with pending tasks', () => {
let clerkForProductionInstance: Clerk;
let clerkForDevelopmentInstance: Clerk;

beforeEach(async () => {
mockEnvironmentFetch.mockReturnValue(
Promise.resolve({
userSettings: mockUserSettings,
displayConfig: mockDisplayConfigWithDifferentOrigin,
isProduction: () => false,
isDevelopmentOrStaging: () => true,
}),
);

mockClientFetch.mockReturnValue(
Promise.resolve({
signedInSessions: [
{
id: '1',
remove: jest.fn(),
status: 'pending',
currentTask: { key: 'org' },
user: {},
touch: jest.fn(() => Promise.resolve()),
getToken: jest.fn(),
lastActiveToken: { getRawString: () => 'mocked-token' },
},
],
}),
);

clerkForProductionInstance = new Clerk(productionPublishableKey);
clerkForDevelopmentInstance = new Clerk(developmentPublishableKey);

await clerkForProductionInstance.load(mockedLoadOptions);
await clerkForDevelopmentInstance.load(mockedLoadOptions);
describe('.redirectToTasks', () => {
describe('after sign-in with pending session', () => {
it.todo('redirects to tasks URL with after sign-in URL appended as query param');
});

afterEach(() => {
mockEnvironmentFetch.mockRestore();
mockClientFetch.mockRestore();
describe('after sign-up with pending session', () => {
it.todo('redirects to tasks URL with after sign-up URL appended as query param');
});

it('when session has tasks, redirect to tasks URL', async () => {
await clerkForDevelopmentInstance.redirectToTasks();
describe('after sign-up with pending session', () => {
it.todo('redirects to tasks URL with after sign-up URL appended as query param');
});

expect(mockNavigate).toHaveBeenCalledWith('/#/select-organization', {
windowNavigate: expect.any(Function),
});
describe('user already exists and session transitions from active to pending on middle app', () => {
it.todo('redirects to tasks URL with app origin appended as query param');
});
});
});

0 comments on commit e15d124

Please sign in to comment.