Skip to content

Commit

Permalink
test(clerk-js): Update Clerk redirect tests
Browse files Browse the repository at this point in the history
  • Loading branch information
octoper committed Nov 14, 2023
1 parent 8146947 commit 5c30f34
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions packages/clerk-js/src/core/clerk.redirects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,30 @@ describe('Clerk singleton - Redirects', () => {

it('redirects to signInUrl', async () => {
await clerkForProductionInstance.redirectToSignIn({ redirectUrl: 'https://www.example.com/' });
expect(mockNavigate).toHaveBeenNthCalledWith(1, '/sign-in#/?redirect_url=https%3A%2F%2Fwww.example.com%2F');
expect(mockNavigate).toHaveBeenNthCalledWith(
1,
'/sign-in#/?after_sign_in_url=%2F&after_sign_up_url=%2F&redirect_url=https%3A%2F%2Fwww.example.com%2F',
);

await clerkForDevelopmentInstance.redirectToSignIn({ redirectUrl: 'https://www.example.com/' });
expect(mockNavigate).toHaveBeenNthCalledWith(2, '/sign-in#/?redirect_url=https%3A%2F%2Fwww.example.com%2F');
expect(mockNavigate).toHaveBeenNthCalledWith(
2,
'/sign-in#/?after_sign_in_url=%2F&after_sign_up_url=%2F&redirect_url=https%3A%2F%2Fwww.example.com%2F',
);
});

it('redirects to signUpUrl', async () => {
await clerkForProductionInstance.redirectToSignUp({ redirectUrl: 'https://www.example.com/' });
expect(mockNavigate).toHaveBeenNthCalledWith(1, '/sign-up#/?redirect_url=https%3A%2F%2Fwww.example.com%2F');
expect(mockNavigate).toHaveBeenNthCalledWith(
1,
'/sign-up#/?after_sign_in_url=%2F&after_sign_up_url=%2F&redirect_url=https%3A%2F%2Fwww.example.com%2F',
);

await clerkForDevelopmentInstance.redirectToSignUp({ redirectUrl: 'https://www.example.com/' });
expect(mockNavigate).toHaveBeenNthCalledWith(2, '/sign-up#/?redirect_url=https%3A%2F%2Fwww.example.com%2F');
expect(mockNavigate).toHaveBeenNthCalledWith(
2,
'/sign-up#/?after_sign_in_url=%2F&after_sign_up_url=%2F&redirect_url=https%3A%2F%2Fwww.example.com%2F',
);
});

it('redirects to userProfileUrl', async () => {
Expand Down Expand Up @@ -208,27 +220,27 @@ describe('Clerk singleton - Redirects', () => {
await clerkForProductionInstance.redirectToSignIn({ redirectUrl: 'https://www.example.com/' });
expect(mockHref).toHaveBeenNthCalledWith(
1,
'http://another-test.host/sign-in#/?redirect_url=https%3A%2F%2Fwww.example.com%2F',
'http://another-test.host/sign-in#/?after_sign_in_url=http%3A%2F%2Ftest.host%2F&after_sign_up_url=http%3A%2F%2Ftest.host%2F&redirect_url=https%3A%2F%2Fwww.example.com%2F',
);

await clerkForDevelopmentInstance.redirectToSignIn({ redirectUrl: 'https://www.example.com/' });
expect(mockHref).toHaveBeenNthCalledWith(
2,
'http://another-test.host/sign-in#/?redirect_url=https%3A%2F%2Fwww.example.com%2F__clerk_db_jwt[deadbeef]',
'http://another-test.host/sign-in#/?after_sign_in_url=http%3A%2F%2Ftest.host%2F&after_sign_up_url=http%3A%2F%2Ftest.host%2F&redirect_url=https%3A%2F%2Fwww.example.com%2F__clerk_db_jwt[deadbeef]',
);
});

it('redirects to signUpUrl', async () => {
await clerkForProductionInstance.redirectToSignUp({ redirectUrl: 'https://www.example.com/' });
expect(mockHref).toHaveBeenNthCalledWith(
1,
'http://another-test.host/sign-up#/?redirect_url=https%3A%2F%2Fwww.example.com%2F',
'http://another-test.host/sign-up#/?after_sign_in_url=http%3A%2F%2Ftest.host%2F&after_sign_up_url=http%3A%2F%2Ftest.host%2F&redirect_url=https%3A%2F%2Fwww.example.com%2F',
);

await clerkForDevelopmentInstance.redirectToSignUp({ redirectUrl: 'https://www.example.com/' });
expect(mockHref).toHaveBeenNthCalledWith(
2,
'http://another-test.host/sign-up#/?redirect_url=https%3A%2F%2Fwww.example.com%2F__clerk_db_jwt[deadbeef]',
'http://another-test.host/sign-up#/?after_sign_in_url=http%3A%2F%2Ftest.host%2F&after_sign_up_url=http%3A%2F%2Ftest.host%2F&redirect_url=https%3A%2F%2Fwww.example.com%2F__clerk_db_jwt[deadbeef]',
);
});

Expand Down

0 comments on commit 5c30f34

Please sign in to comment.