Skip to content

Commit

Permalink
[SDK-2047] Move and refactor handleRedirectCallback tests (#640)
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikprijck authored Nov 13, 2020
1 parent f7060ac commit 72d8d82
Show file tree
Hide file tree
Showing 3 changed files with 399 additions and 379 deletions.
38 changes: 32 additions & 6 deletions __tests__/Auth0Client.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ const processDefaultLoginWithRedirectOptions = config => {

return {
token,
authorize
authorize,
useHash: config.useHash,
customCallbackUrl: config.customCallbackUrl
};
};

Expand All @@ -90,23 +92,46 @@ export const loginWithRedirectFn = (mockWindow, mockFetch, fetchResponse) => {
code?: string;
state?: string;
error?: string;
errorDescription?: string;
};
useHash?: boolean;
customCallbackUrl?: string;
} = {
token: {},
authorize: {}
}
) => {
const {
token,
authorize: { code, state, error }
authorize: { code, state, error, errorDescription },
useHash,
customCallbackUrl
} = processDefaultLoginWithRedirectOptions(testConfig);
await auth0.loginWithRedirect(options);
expect(mockWindow.location.assign).toHaveBeenCalled();

if (error) {
window.history.pushState({}, '', `/?error=${error}&state=${state}`);
if (error && errorDescription) {
window.history.pushState(
{},
'',
`/${
useHash ? '#' : ''
}?error=${error}&error_description=${errorDescription}&state=${state}`
);
} else if (error) {
window.history.pushState(
{},
'',
`/${useHash ? '#' : ''}?error=${error}&state=${state}`
);
} else if (code) {
window.history.pushState(
{},
'',
`/${useHash ? '#' : ''}?code=${code}&state=${state}`
);
} else {
window.history.pushState({}, '', `/?code=${code}&state=${state}`);
window.history.pushState({}, '', `/`);
}

mockFetch.mockResolvedValueOnce(
Expand All @@ -123,7 +148,8 @@ export const loginWithRedirectFn = (mockWindow, mockFetch, fetchResponse) => {
)
)
);
await auth0.handleRedirectCallback();

return await auth0.handleRedirectCallback(customCallbackUrl);
};
};

Expand Down
Loading

0 comments on commit 72d8d82

Please sign in to comment.