Merge pull request #500 from edx/ashultz0/idv_redo_ok

feat: if verified name is on, we can redo ID verification
This commit is contained in:
Andrew Shultz
2021-09-15 11:03:56 -04:00
committed by GitHub
3 changed files with 45 additions and 5 deletions

View File

@@ -176,6 +176,19 @@ export async function shouldDisplayDemographicsQuestions() {
return false;
}
export async function getVerifiedNameEnabled() {
let data;
const client = getAuthenticatedHttpClient();
try {
const requestUrl = `${getConfig().LMS_BASE_URL}/api/edx_name_affirmation/v1/verified_name_enabled`;
({ data } = await client.get(requestUrl));
} catch (error) {
return {};
}
return data;
}
export async function getVerifiedName() {
let data;
const client = getAuthenticatedHttpClient();

View File

@@ -2,7 +2,7 @@ import React, { useState, useContext, useEffect } from 'react';
import PropTypes from 'prop-types';
import { AppContext } from '@edx/frontend-platform/react';
import { getProfileDataManager, getVerifiedName } from '../account-settings/data/service';
import { getProfileDataManager, getVerifiedName, getVerifiedNameEnabled } from '../account-settings/data/service';
import PageLoading from '../account-settings/PageLoading';
import { getExistingIdVerification, getEnrollments } from './data/service';
@@ -30,11 +30,25 @@ export default function IdVerificationContextProvider({ children }) {
hasGetUserMediaSupport ? MEDIA_ACCESS.PENDING : MEDIA_ACCESS.UNSUPPORTED,
);
const [verifiedNameEnabled, setVerifiedNameEnabled] = useState(false);
useEffect(() => {
// Make the API call to retrieve VerifiedNameEnabled
(async () => {
const response = await getVerifiedNameEnabled();
if (response) {
setVerifiedNameEnabled(response.verified_name_enabled);
} else {
setVerifiedNameEnabled(false);
}
})();
}, []);
const [canVerify, setCanVerify] = useState(true);
const [error, setError] = useState('');
useEffect(() => {
// Check for an existing verification attempt
if (existingIdVerification && !existingIdVerification.canVerify) {
// With verified name we can redo verification multiple times
// if not a successful request prevents re-verification
if (!verifiedNameEnabled && existingIdVerification && !existingIdVerification.canVerify) {
const { status } = existingIdVerification;
setCanVerify(false);
if (status === 'pending' || status === 'approved') {
@@ -43,7 +57,7 @@ export default function IdVerificationContextProvider({ children }) {
setError(ERROR_REASONS.CANNOT_VERIFY);
}
}
}, [existingIdVerification]);
}, [existingIdVerification, verifiedNameEnabled]);
useEffect(() => {
// Check whether the learner is enrolled in a verified course mode.
(async () => {

View File

@@ -5,7 +5,7 @@ import '@testing-library/jest-dom/extend-expect';
import { IntlProvider } from '@edx/frontend-platform/i18n';
import { AppContext } from '@edx/frontend-platform/react';
import { getProfileDataManager, getVerifiedName } from '../../account-settings/data/service';
import { getProfileDataManager, getVerifiedName, getVerifiedNameEnabled } from '../../account-settings/data/service';
import { getExistingIdVerification, getEnrollments } from '../data/service';
import IdVerificationContextProvider from '../IdVerificationContextProvider';
@@ -13,6 +13,7 @@ import IdVerificationContextProvider from '../IdVerificationContextProvider';
jest.mock('../../account-settings/data/service', () => ({
getProfileDataManager: jest.fn(),
getVerifiedName: jest.fn(),
getVerifiedNameEnabled: jest.fn(),
}));
jest.mock('../data/service', () => ({
@@ -75,4 +76,16 @@ describe('IdVerificationContextProvider', () => {
)));
expect(getVerifiedName).toHaveBeenCalled();
});
it('calls getVerifiedNameEnabled', async () => {
const context = { authenticatedUser: { userId: 3, roles: [] } };
await act(async () => render((
<AppContext.Provider value={context}>
<IntlProvider locale="en">
<IdVerificationContextProvider {...defaultProps} />
</IntlProvider>
</AppContext.Provider>
)));
expect(getVerifiedNameEnabled).toHaveBeenCalled();
});
});