-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fxa-settings): Implement using recovery phone to sign in
Because: * New feature: recovery phone as recovery method for 2FA during sign in This commit: * Hook up new pages to choose recovery method and use recovery phone during sign in Closes #FXA-10374
- Loading branch information
1 parent
2615da7
commit 3837486
Showing
38 changed files
with
798 additions
and
215 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
File renamed without changes.
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
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
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
148 changes: 148 additions & 0 deletions
148
packages/fxa-settings/src/pages/Signin/SigninRecoveryChoice/container.test.tsx
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,148 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import * as ModelsModule from '../../../models'; | ||
import * as ReachRouterModule from '@reach/router'; | ||
import * as ReactUtils from 'fxa-react/lib/utils'; | ||
import * as CacheModule from '../../../lib/cache'; | ||
import * as SigninRecoveryChoiceModule from './index'; | ||
|
||
import { LocationProvider } from '@reach/router'; | ||
import { renderWithLocalizationProvider } from 'fxa-react/lib/test-utils/localizationProvider'; | ||
import { MOCK_STORED_ACCOUNT, mockLoadingSpinnerModule } from '../../mocks'; | ||
import { mockSigninLocationState } from '../mocks'; | ||
import { SigninRecoveryChoiceProps } from '.'; | ||
import SigninRecoveryChoiceContainer from './container'; | ||
import AuthClient from 'fxa-auth-client/lib/client'; | ||
|
||
// mock custom glean events if needed | ||
|
||
jest.mock('../../../models', () => { | ||
return { | ||
...jest.requireActual('../../../models'), | ||
useAuthClient: jest.fn(), | ||
}; | ||
}); | ||
|
||
const mockAuthClient = new AuthClient('http://localhost:9000', { | ||
keyStretchVersion: 1, | ||
}); | ||
|
||
function mockModelsModule() { | ||
mockAuthClient.recoveryKeyExists = jest.fn().mockResolvedValue({ | ||
hasBackupCodes: true, | ||
count: 3, | ||
}); | ||
mockAuthClient.recoveryPhoneGet = jest | ||
.fn() | ||
.mockResolvedValue({ exists: true, number: '7890' }); | ||
(ModelsModule.useAuthClient as jest.Mock).mockImplementation( | ||
() => mockAuthClient | ||
); | ||
} | ||
|
||
let currentSigninRecoveryChoiceProps: SigninRecoveryChoiceProps | undefined; | ||
function mockSigninRecoveryChoiceModule() { | ||
jest | ||
.spyOn(SigninRecoveryChoiceModule, 'default') | ||
.mockImplementation((props: SigninRecoveryChoiceProps) => { | ||
currentSigninRecoveryChoiceProps = props; | ||
return <div>signin recovery choice mock</div>; | ||
}); | ||
} | ||
|
||
function mockCache(opts: any = {}, isEmpty = false) { | ||
jest.spyOn(CacheModule, 'currentAccount').mockReturnValue( | ||
isEmpty | ||
? undefined | ||
: { | ||
sessionToken: '123', | ||
...(opts || {}), | ||
} | ||
); | ||
} | ||
|
||
function mockReactUtilsModule() { | ||
jest.spyOn(ReactUtils, 'hardNavigate').mockImplementation(() => {}); | ||
} | ||
|
||
const mockLocation = (pathname: string, mockLocationState: Object) => { | ||
return { | ||
...global.window.location, | ||
pathname, | ||
state: mockLocationState, | ||
}; | ||
}; | ||
|
||
function mockReachRouter( | ||
mockNavigate = jest.fn(), | ||
pathname = '', | ||
mockLocationState = {} | ||
) { | ||
mockNavigate.mockReset(); | ||
jest.spyOn(ReachRouterModule, 'useNavigate').mockReturnValue(mockNavigate); | ||
jest | ||
.spyOn(ReachRouterModule, 'useLocation') | ||
.mockImplementation(() => mockLocation(pathname, mockLocationState)); | ||
} | ||
|
||
function applyDefaultMocks() { | ||
jest.resetAllMocks(); | ||
jest.restoreAllMocks(); | ||
mockModelsModule(); | ||
mockSigninRecoveryChoiceModule(); | ||
mockLoadingSpinnerModule(); | ||
mockReactUtilsModule(); | ||
mockCache(); | ||
mockReachRouter(undefined, 'signin_recovery_choice', mockSigninLocationState); | ||
} | ||
|
||
function render() { | ||
renderWithLocalizationProvider( | ||
<LocationProvider> | ||
<SigninRecoveryChoiceContainer /> | ||
</LocationProvider> | ||
); | ||
} | ||
|
||
describe('SigninRecoveryChoice container', () => { | ||
beforeEach(() => { | ||
applyDefaultMocks(); | ||
}); | ||
|
||
describe('initial state', () => { | ||
it('redirects if page is reached without location state', async () => { | ||
mockReachRouter(undefined, 'signin_recovery_choice'); | ||
mockCache({}, true); | ||
await render(); | ||
// expect navigation to signin | ||
}); | ||
|
||
it('redirects if there is no sessionToken', async () => { | ||
mockReachRouter(undefined, 'signin_recovery_choice'); | ||
mockCache({ sessionToken: '' }); | ||
await render(); | ||
// expect navigation to signin | ||
}); | ||
|
||
it('retrieves the session token from local storage if no location state', async () => { | ||
mockReachRouter(undefined, 'signin_recovery_choice', {}); | ||
mockCache(MOCK_STORED_ACCOUNT); | ||
await render(); | ||
// expect navigation to signin | ||
}); | ||
}); | ||
|
||
describe('fetches recovery method data', () => { | ||
it('successful', async () => { | ||
// fill in test | ||
}); | ||
|
||
it('handles errors', async () => { | ||
// fill in test | ||
}); | ||
}); | ||
|
||
// redirects if no recovery phone | ||
}); |
Oops, something went wrong.