Skip to content

Commit

Permalink
Merge pull request #216 from openedx/bseverino/verified-name
Browse files Browse the repository at this point in the history
[MST-1135] Remove IDV and add verified name panel
  • Loading branch information
bseverino authored Feb 2, 2022
2 parents cca1825 + cb6cada commit c741481
Show file tree
Hide file tree
Showing 11 changed files with 362 additions and 268 deletions.
49 changes: 49 additions & 0 deletions src/users/data/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,55 @@ export async function getUserVerificationStatus(username) {
}
}

export async function getVerifiedNameHistory(username) {
const response = {
verifiedName: null,
status: null,
verificationType: null,
history: [],
error: null,
};

try {
const { data } = await getAuthenticatedHttpClient().get(
AppUrls.getVerifiedNameHistoryUrl(username),
);

if (!data || !data.results || data.results.length === 0) {
return { ...response, error: 'No record found' };
}
const latestResult = data.results[0];
let verificationType = null;

if (latestResult.verification_attempt_id) {
verificationType = 'IDV';
} else if (latestResult.proctored_exam_attempt_id) {
verificationType = 'Proctoring';
}

return {
...response,
verifiedName: latestResult.verified_name,
status: latestResult.status,
verificationType,
history: data.results,
};
} catch (error) {
let errorText = 'Error while fetching data';

try {
if (error.customAttributes?.httpErrorResponseData) {
errorText = JSON.parse(error.customAttributes.httpErrorResponseData);
}
} catch (e) {
// In case there is something wrong with the response, use the default
// error message
}

return { ...response, error: errorText };
}
}

export async function getUserPasswordStatus(userIdentifier) {
const { data } = await getAuthenticatedHttpClient().get(
AppUrls.getUserPasswordStatusUrl(userIdentifier),
Expand Down
76 changes: 76 additions & 0 deletions src/users/data/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';

import { enrollmentsData } from './test/enrollments';
import { downloadableCertificate } from './test/certificates';
import verifiedNameHistoryData from './test/verifiedNameHistory';
import * as api from './api';
import * as urls from './urls';

Expand All @@ -19,6 +20,7 @@ describe('API', () => {
const entitlementsApiBaseUrl = `${getConfig().LMS_BASE_URL}/api/entitlements/v1/entitlements/?user=${testUsername}`;
const verificationDetailsApiUrl = `${getConfig().LMS_BASE_URL}/api/user/v1/accounts/${testUsername}/verifications/`;
const verificationStatusApiUrl = `${getConfig().LMS_BASE_URL}/api/user/v1/accounts/${testUsername}/verification_status/`;
const verifiedNameHistoryUrl = `${getConfig().LMS_BASE_URL}/api/edx_name_affirmation/v1/verified_name/history?username=${testUsername}`;
const licensesApiUrl = `${getConfig().LICENSE_MANAGER_URL}/api/v1/staff_lookup_licenses/`;
const certificatesUrl = urls.getCertificateUrl(testUsername, testCourseId);
const generateCertificateUrl = urls.generateCertificateUrl();
Expand Down Expand Up @@ -259,6 +261,80 @@ describe('API', () => {
});
});

describe('Verified Name History Fetch', () => {
const defaultResponse = {
verifiedName: null,
status: null,
verificationType: null,
history: [],
error: null,
};

it('returns a server error with default message', async () => {
const expectedData = {
...defaultResponse,
error: 'Error while fetching data',
};
mockAdapter.onGet(verifiedNameHistoryUrl).reply(() => throwError(500));
const response = await api.getVerifiedNameHistory(testUsername);
expect(response).toEqual(expectedData);
});

it('returns a server error with information', async () => {
const expectedData = {
...defaultResponse,
error: 'User does not exist',
};
mockAdapter.onGet(verifiedNameHistoryUrl).reply(() => throwError(500, 'User does not exist'));
const response = await api.getVerifiedNameHistory(testUsername);
expect(response).toEqual(expectedData);
});

it('returns an error with an empty data set', async () => {
const expectedData = {
...defaultResponse,
error: 'No record found',
};
mockAdapter.onGet(verifiedNameHistoryUrl).reply(200, { results: [] });
const response = await api.getVerifiedNameHistory(testUsername);
expect(response).toEqual(expectedData);
});

it('successfully fetches data', async () => {
const expectedData = {
...defaultResponse,
verifiedName: verifiedNameHistoryData.results[0].verified_name,
status: verifiedNameHistoryData.results[0].status,
verificationType: 'Proctoring',
history: verifiedNameHistoryData.results,
};
mockAdapter.onGet(verifiedNameHistoryUrl).reply(200, verifiedNameHistoryData);

const response = await api.getVerifiedNameHistory(testUsername);
expect(response).toEqual(expectedData);
});

it('changes verificationType field based on linked ID', async () => {
const apiResponseData = {
results: [
{ ...verifiedNameHistoryData.results[1] },
{ ...verifiedNameHistoryData.results[0] },
],
};
const expectedData = {
...defaultResponse,
verifiedName: apiResponseData.results[0].verified_name,
status: apiResponseData.results[0].status,
verificationType: 'IDV',
history: apiResponseData.results,
};
mockAdapter.onGet(verifiedNameHistoryUrl).reply(200, apiResponseData);

const response = await api.getVerifiedNameHistory(testUsername);
expect(response).toEqual(expectedData);
});
});

describe('User Account Details', () => {
const successDictResponse = {
username: testUsername,
Expand Down
22 changes: 22 additions & 0 deletions src/users/data/test/verifiedNameHistory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const verifiedNameHistory = {
results: [
{
created: '2021-10-08T17:36:55.781077Z',
verified_name: 'Jonathan Doe',
profile_name: 'Jon Doe',
verification_attempt_id: null,
proctored_exam_attempt_id: 123,
status: 'approved',
},
{
created: '2021-09-08T17:36:55.781077Z',
verified_name: 'J Doe',
profile_name: 'Jon Doe',
verification_attempt_id: 456,
proctored_exam_attempt_id: null,
status: 'denied',
},
],
};

export default verifiedNameHistory;
4 changes: 4 additions & 0 deletions src/users/data/urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export const getUserVerificationStatusUrl = username => `${
LMS_BASE_URL
}/api/user/v1/accounts/${username}/verification_status/`;

export const getVerifiedNameHistoryUrl = username => `${
LMS_BASE_URL
}/api/edx_name_affirmation/v1/verified_name/history?username=${username}`;

export const getUserPasswordStatusUrl = userIdentifier => `${
LMS_BASE_URL
}/support/manage_user/${userIdentifier}`;
Expand Down
159 changes: 0 additions & 159 deletions src/users/v2/IdentityVerificationStatus.jsx

This file was deleted.

Loading

0 comments on commit c741481

Please sign in to comment.