-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add unit tests to improve coverage
- Loading branch information
1 parent
4a28019
commit 6fae198
Showing
12 changed files
with
447 additions
and
50 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
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,69 @@ | ||
import QueryString from 'query-string'; | ||
|
||
import { getTpaHint, getTpaProvider } from './utils'; | ||
|
||
// Mocking the query-string library | ||
jest.mock('query-string'); | ||
|
||
describe('Utility Functions', () => { | ||
describe('getTpaProvider', () => { | ||
it('should return the provider from primaryProviders', () => { | ||
const tpaHintProvider = 'google-oauth2'; | ||
const primaryProviders = [{ id: 'google-oauth2' }, { id: 'facebook' }]; | ||
const secondaryProviders = [{ id: 'twitter' }]; | ||
|
||
const result = getTpaProvider(tpaHintProvider, primaryProviders, secondaryProviders); | ||
expect(result.provider).toEqual({ id: 'google-oauth2' }); | ||
}); | ||
|
||
it('should return the provider from secondaryProviders', () => { | ||
const tpaHintProvider = 'twitter'; | ||
const primaryProviders = [{ id: 'google-oauth2' }, { id: 'facebook' }]; | ||
const secondaryProviders = [{ id: 'twitter' }]; | ||
|
||
const result = getTpaProvider(tpaHintProvider, primaryProviders, secondaryProviders); | ||
expect(result.provider).toEqual({ id: 'twitter' }); | ||
}); | ||
|
||
it('should return null if provider is not found', () => { | ||
const tpaHintProvider = 'linkedin'; | ||
const primaryProviders = [{ id: 'google-oauth2' }, { id: 'facebook' }]; | ||
const secondaryProviders = [{ id: 'twitter' }]; | ||
|
||
const result = getTpaProvider(tpaHintProvider, primaryProviders, secondaryProviders); | ||
expect(result.provider).toBeNull(); | ||
}); | ||
|
||
it('should return null if tpaHintProvider is not provided', () => { | ||
const tpaHintProvider = null; | ||
const primaryProviders = [{ id: 'google-oauth2' }, { id: 'facebook' }]; | ||
const secondaryProviders = [{ id: 'twitter' }]; | ||
|
||
const result = getTpaProvider(tpaHintProvider, primaryProviders, secondaryProviders); | ||
expect(result.provider).toBeNull(); | ||
}); | ||
}); | ||
|
||
describe('getTpaHint', () => { | ||
it('should return tpa_hint from the query string', () => { | ||
QueryString.parse.mockReturnValue({ tpa_hint: 'google-oauth2' }); | ||
|
||
const result = getTpaHint(); | ||
expect(result).toBe('google-oauth2'); | ||
}); | ||
|
||
it('should return tpa_hint from the "next" parameter in the query string', () => { | ||
QueryString.parse.mockReturnValue({ next: 'some-path?tpa_hint=facebook' }); | ||
|
||
const result = getTpaHint(); | ||
expect(result).toBe('facebook'); | ||
}); | ||
|
||
it('should return undefined if tpa_hint is not found', () => { | ||
QueryString.parse.mockReturnValue({ next: 'some-path' }); | ||
|
||
const result = getTpaHint(); | ||
expect(result).toBeUndefined(); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,8 +1,18 @@ | ||
import { | ||
COMPLETE_STATE, FAILURE_STATE, PENDING_STATE, | ||
COMPLETE_STATE, | ||
DEFAULT_STATE, | ||
FAILURE_STATE, | ||
PENDING_STATE, | ||
} from '../../../../data/constants'; | ||
import loginReducer, { | ||
loginInitialState, loginUser, loginUserFailed, loginUserSuccess, | ||
backupLoginForm, | ||
loginErrorClear, | ||
loginInitialState, | ||
loginUser, | ||
loginUserFailed, | ||
loginUserSuccess, | ||
setLoginSSOIntent, | ||
setShowPasswordResetBanner, | ||
} from '../reducers'; | ||
|
||
describe('loginSlice reducer', () => { | ||
|
@@ -47,4 +57,46 @@ describe('loginSlice reducer', () => { | |
}); | ||
expect(nextState.loginResult).toEqual({}); | ||
}); | ||
|
||
it('should handle setShowPasswordResetBanner action', () => { | ||
const nextState = loginReducer(loginInitialState, setShowPasswordResetBanner()); | ||
|
||
expect(nextState.showResetPasswordSuccessBanner).toEqual(true); | ||
}); | ||
|
||
it('should handle loginErrorClear action', () => { | ||
const stateWithErrors = { | ||
...loginInitialState, | ||
loginError: { errorCode: 'SOME_ERROR_CODE', errorContext: {} }, | ||
submitState: FAILURE_STATE, | ||
}; | ||
|
||
const nextState = loginReducer(stateWithErrors, loginErrorClear()); | ||
|
||
expect(nextState.loginError).toEqual({}); | ||
expect(nextState.submitState).toEqual(DEFAULT_STATE); | ||
}); | ||
|
||
it('should handle setLoginSSOIntent action', () => { | ||
const nextState = loginReducer(loginInitialState, setLoginSSOIntent()); | ||
|
||
expect(nextState.isLoginSSOIntent).toEqual(true); | ||
}); | ||
|
||
it('should handle backupLoginForm action', () => { | ||
const mockPayload = { | ||
formFields: { | ||
emailOrUsername: '[email protected]', | ||
password: 'password123', | ||
}, | ||
errors: { | ||
emailOrUsername: '', | ||
password: '', | ||
}, | ||
}; | ||
|
||
const nextState = loginReducer(loginInitialState, backupLoginForm(mockPayload)); | ||
|
||
expect(nextState.loginFormData).toEqual(mockPayload); | ||
}); | ||
}); |
Oops, something went wrong.