This repository has been archived by the owner on Oct 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[okta-react] fix: show error string on LoginCallback (#700)
* [okta-react] fix: show error string on LoginCallback * [okta-react] release 2.0.1
- Loading branch information
1 parent
03bfdaf
commit 91b5a12
Showing
4 changed files
with
109 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import LoginCallback from '../../src/LoginCallback'; | ||
import Security from '../../src/Security'; | ||
import AuthSdkError from '@okta/okta-auth-js/lib/errors/AuthSdkError'; | ||
import AuthApiError from '@okta/okta-auth-js/lib/errors/AuthApiError'; | ||
import OAuthError from '@okta/okta-auth-js/lib/errors/OAuthError'; | ||
|
||
describe('<LoginCallback />', () => { | ||
let authService; | ||
let authState; | ||
let mockProps; | ||
beforeEach(() => { | ||
authState = { | ||
isPending: true | ||
}; | ||
authService = { | ||
on: jest.fn(), | ||
updateAuthState: jest.fn(), | ||
getAuthState: jest.fn().mockImplementation(() => authState), | ||
handleAuthentication: jest.fn() | ||
}; | ||
mockProps = { authService }; | ||
}); | ||
|
||
it('renders the component', () => { | ||
const wrapper = mount( | ||
<Security {...mockProps}> | ||
<LoginCallback /> | ||
</Security> | ||
); | ||
expect(wrapper.find(LoginCallback).length).toBe(1); | ||
expect(wrapper.text()).toBe(''); | ||
}); | ||
|
||
it('calls handleAuthentication', () => { | ||
mount( | ||
<Security {...mockProps}> | ||
<LoginCallback /> | ||
</Security> | ||
); | ||
expect(authService.handleAuthentication).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('renders empty by default', () => { | ||
const wrapper = mount( | ||
<Security {...mockProps}> | ||
<LoginCallback /> | ||
</Security> | ||
); | ||
expect(wrapper.text()).toBe(''); | ||
}); | ||
|
||
describe('shows errors', () => { | ||
test('generic', () => { | ||
const errorMessage = 'I am a test error message'; | ||
authState.error = new Error(errorMessage); | ||
const wrapper = mount( | ||
<Security {...mockProps}> | ||
<LoginCallback /> | ||
</Security> | ||
); | ||
expect(wrapper.text()).toBe(`Error: ${errorMessage}`); | ||
}); | ||
test('AuthSdkError', () => { | ||
const errorMessage = 'I am a test error message'; | ||
authState.error = new AuthSdkError(errorMessage); | ||
const wrapper = mount( | ||
<Security {...mockProps}> | ||
<LoginCallback /> | ||
</Security> | ||
); | ||
expect(wrapper.text()).toBe(`AuthSdkError: ${errorMessage}`); | ||
}); | ||
test('AuthApiError', () => { | ||
const errorSummary = 'I am a test error message'; | ||
authState.error = new AuthApiError({ errorSummary }); | ||
const wrapper = mount( | ||
<Security {...mockProps}> | ||
<LoginCallback /> | ||
</Security> | ||
); | ||
expect(wrapper.text()).toBe(`AuthApiError: ${errorSummary}`); | ||
}); | ||
test('OAuthError', () => { | ||
const errorCode = 400; | ||
const errorSummary = 'I am a test error message'; | ||
authState.error = new OAuthError(errorCode, errorSummary); | ||
const wrapper = mount( | ||
<Security {...mockProps}> | ||
<LoginCallback /> | ||
</Security> | ||
); | ||
expect(wrapper.text()).toBe(`OAuthError: ${errorSummary}`); | ||
}); | ||
}); | ||
|
||
|
||
|
||
|
||
}); |