Skip to content
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
1 change: 1 addition & 0 deletions __tests__/auth-reducer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('reducer', () => {
it('should initialise when not authenticated', async () => {
const payload = {
isAuthenticated: false,
user: undefined,
};
expect(
reducer(initialAuthState, { type: 'INITIALISED', ...payload })
Expand Down
99 changes: 98 additions & 1 deletion __tests__/utils.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
import { hasAuthParams, loginError, tokenError } from '../src/utils';
import { hasAuthParams, loginError, tokenError, deprecateRedirectUri } from '../src/utils';
import { OAuthError } from '../src/errors';

// Define interfaces for testing deprecateRedirectUri function
interface TestOptionsWithRedirectUri {
redirectUri?: string;
authorizationParams?: {
redirect_uri?: string;
scope?: string;
};
}

interface TestOptionsWithAuthorizationParams {
authorizationParams: {
redirectUri?: string;
redirect_uri?: string;
scope?: string;
};
}

interface TestOptionsWithBothRedirectUri {
redirectUri?: string;
authorizationParams: {
scope: string;
redirect_uri?: string;
};
}

describe('utils hasAuthParams', () => {
it('should not recognise only the code param', async () => {
['?code=1', '?foo=1&code=2', '?code=1&foo=2'].forEach((search) =>
Expand Down Expand Up @@ -62,3 +87,75 @@ describe('utils error', () => {
}).toThrowError('Login failed');
});
});

describe('utils deprecateRedirectUri', () => {
let consoleSpy: jest.SpyInstance;

beforeEach(() => {
consoleSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
});

afterEach(() => {
consoleSpy.mockRestore();
});

it('should handle options with redirectUri', () => {
const options: TestOptionsWithRedirectUri = {
redirectUri: 'https://example.com/callback',
};

deprecateRedirectUri(options);

expect(consoleSpy).toHaveBeenCalledWith(
'Using `redirectUri` has been deprecated, please use `authorizationParams.redirect_uri` instead as `redirectUri` will be no longer supported in a future version'
);
expect(options.authorizationParams?.redirect_uri).toBe('https://example.com/callback');
expect(options.redirectUri).toBeUndefined();
});

it('should handle options with authorizationParams.redirectUri', () => {
const options: TestOptionsWithAuthorizationParams = {
authorizationParams: {
redirectUri: 'https://example.com/callback',
},
};

deprecateRedirectUri(options);

expect(consoleSpy).toHaveBeenCalledWith(
'Using `authorizationParams.redirectUri` has been deprecated, please use `authorizationParams.redirect_uri` instead as `authorizationParams.redirectUri` will be removed in a future version'
);
expect(options.authorizationParams.redirect_uri).toBe('https://example.com/callback');
expect(options.authorizationParams.redirectUri).toBeUndefined();
});

it('should handle options with both redirectUri and existing authorizationParams', () => {
const options: TestOptionsWithBothRedirectUri = {
redirectUri: 'https://example.com/callback',
authorizationParams: {
scope: 'openid profile',
},
};

deprecateRedirectUri(options);

expect(options.authorizationParams.redirect_uri).toBe('https://example.com/callback');
expect(options.authorizationParams.scope).toBe('openid profile');
expect(options.redirectUri).toBeUndefined();
});

it('should handle undefined options', () => {
deprecateRedirectUri(undefined);
expect(consoleSpy).not.toHaveBeenCalled();
});

it('should handle options without redirectUri properties', () => {
const options = {
domain: 'example.auth0.com',
clientId: 'client-id',
};

deprecateRedirectUri(options);
expect(consoleSpy).not.toHaveBeenCalled();
});
});
1 change: 1 addition & 0 deletions docs/assets/hierarchy.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 17 additions & 14 deletions docs/assets/icons.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/assets/icons.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 5 additions & 4 deletions docs/assets/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/assets/navigation.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/assets/search.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading