Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import { LocationProvider } from '@reach/router';
import { renderWithLocalizationProvider } from 'fxa-react/lib/test-utils/localizationProvider';
import SigninRecoveryCodeContainer from './container';
import { createMockWebIntegration } from '../../../lib/integrations/mocks';
import { Integration, useAuthClient, useSensitiveDataClient } from '../../../models';
import {
Integration,
useAuthClient,
useSensitiveDataClient,
} from '../../../models';
import { mockSensitiveDataClient as createMockSensitiveDataClient } from '../../../models/mocks';
import {
MOCK_STORED_ACCOUNT,
Expand All @@ -24,6 +28,16 @@ import { mockSigninLocationState } from '../mocks';
import { waitFor } from '@testing-library/react';
import { AuthUiErrors } from '../../../lib/auth-errors/auth-errors';
import { SensitiveData } from '../../../lib/sensitive-data-client';
import {
useFinishOAuthFlowHandler,
useOAuthKeysCheck,
} from '../../../lib/oauth/hooks';

jest.mock('../../../lib/oauth/hooks', () => ({
__esModule: true,
useFinishOAuthFlowHandler: jest.fn(),
useOAuthKeysCheck: jest.fn(),
}));

let integration: Integration;
function mockWebIntegration() {
Expand Down Expand Up @@ -122,6 +136,13 @@ function applyDefaultMocks() {
mockWebIntegration();
resetMockSensitiveDataClient();
resetMockAuthClient();
(useFinishOAuthFlowHandler as jest.Mock).mockImplementation(() => ({
finishOAuthFlowHandler: jest.fn(),
oAuthDataError: null,
}));
(useOAuthKeysCheck as jest.Mock).mockImplementation(() => ({
oAuthKeysCheckError: null,
}));
}

function render() {
Expand Down Expand Up @@ -170,6 +191,36 @@ describe('SigninRecoveryCode container', () => {
});
});

describe('useOAuthKeysCheck', () => {
it('passes isPasswordlessFlow to skip the keys check', () => {
mockReachRouter('signin_recovery_code', {
signinState: { ...mockSigninLocationState, isPasswordlessFlow: true },
});
render();
expect(useOAuthKeysCheck).toHaveBeenCalledWith(
integration,
MOCK_KEY_FETCH_TOKEN,
MOCK_UNWRAP_BKEY,
true
);
});

it('renders the recovery code component when keys check is skipped for passwordless flow', () => {
(useOAuthKeysCheck as jest.Mock).mockImplementationOnce(
(_integration: any, _kft: any, _ubk: any, skipKeysCheck: boolean) => ({
oAuthKeysCheckError: skipKeysCheck
? null
: { errno: 1, message: 'TRY_AGAIN' },
})
);
mockReachRouter('signin_recovery_code', {
signinState: { ...mockSigninLocationState, isPasswordlessFlow: true },
});
render();
expect(currentSigninRecoveryCodeProps).toBeDefined();
});
});

describe('submitRecoveryCode', () => {
it('successful', async () => {
mockAuthClient.consumeRecoveryCode.mockResolvedValue({ remaining: 3 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const SigninRecoveryCodeContainer = ({
integration,
keyFetchToken,
unwrapBKey,
signinState?.isSignInWithThirdPartyAuth
signinState?.isSignInWithThirdPartyAuth || signinState?.isPasswordlessFlow
);

const submitRecoveryCode: SubmitRecoveryCode = useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,32 @@ describe('SigninRecoveryPhoneContainer', () => {
);
});
});

describe('useOAuthKeysCheck', () => {
it('passes isPasswordlessFlow to skip the keys check', () => {
mockReachRouter('/signin_recovery_phone', {
signinState: { ...mockSigninLocationState, isPasswordlessFlow: true },
lastFourPhoneDigits: '1234',
});
renderSigninRecoveryPhoneContainer();
const lastArg = (useOAuthKeysCheck as jest.Mock).mock.calls[0]?.[3];
expect(lastArg).toBe(true);
});

it('renders the recovery phone component when keys check is skipped for passwordless flow', () => {
(useOAuthKeysCheck as jest.Mock).mockImplementationOnce(
(_integration: any, _kft: any, _ubk: any, skipKeysCheck: boolean) => ({
oAuthKeysCheckError: skipKeysCheck
? null
: { errno: 1, message: 'TRY_AGAIN' },
})
);
mockReachRouter('/signin_recovery_phone', {
signinState: { ...mockSigninLocationState, isPasswordlessFlow: true },
lastFourPhoneDigits: '1234',
});
renderSigninRecoveryPhoneContainer();
expect(currentPageProps).toBeDefined();
});
Comment on lines +263 to +277
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like good testing feedback.

});
});
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const SigninRecoveryPhoneContainer = ({
integration,
keyFetchToken,
unwrapBKey,
signinState?.isSignInWithThirdPartyAuth
signinState?.isSignInWithThirdPartyAuth || signinState?.isPasswordlessFlow
);

const webRedirectCheck = useWebRedirect(integration.data.redirectTo);
Expand Down
Loading