Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Removed IDV Status details call #418

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
125 changes: 61 additions & 64 deletions src/users/VerifiedName.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,68 @@ import {
import PageLoading from '../components/common/PageLoading';
import Table from '../components/Table';
import { formatDate } from '../utils';
import { getVerifiedNameHistory, getVerificationAttemptDetailsById } from './data/api';
import { getVerifiedNameHistory } from './data/api';

const verifiedNameColumns = [
{
Header: 'Verified Name',
accessor: 'verifiedName',
},
{
Header: 'Status',
accessor: 'status',
},
{
Header: 'Verification Type',
accessor: 'verificationType',
},
{
Header: 'History',
accessor: 'history',
},
];

const verifiedNameHistoryColumns = [
{
Header: 'Verified Name',
accessor: 'verifiedName',
},
{
Header: 'Profile Name',
accessor: 'profileName',
},
{
Header: 'Status',
accessor: 'status',
},
{
Header: 'IDV Attempt ID',
accessor: 'idvAttemptId',
},
{
Header: 'Proctoring Attempt ID',
accessor: 'proctoringAttemptId',
},
{
Header: 'Created At',
accessor: 'createdAt',
},
];

// Human readable formatter for the status. Possible status list on:
// https://github.com/edx/edx-solutions-edx-platform/blob/0ebc69f86548a44b7947decfe308032028721907/lms/djangoapps/verify_student/models.py#L104
rijuma marked this conversation as resolved.
Show resolved Hide resolved
const idvStatusFormat = status => {
rijuma marked this conversation as resolved.
Show resolved Hide resolved
// Capitalize first letter
const properStatus = `${status.at(0).toUpperCase()}${status?.slice(1)}`;

// Replace underscores with spaces
return properStatus.replace('_', ' ');
};

export default function VerifiedName({ username }) {
const [verifiedNameData, setVerifiedNameData] = useState(null);
const [verifiedNameHistoryData, setVerifiedNameHistoryData] = useState([]);
const [isModalOpen, setIsModalOpen] = useState(false);
const [verificationAttemptDetails, setVerificationAttemptDetails] = useState({});

useEffect(() => {
let isMounted = true;
Expand Down Expand Up @@ -45,10 +100,9 @@ export default function VerifiedName({ username }) {
trigger="hover"
overlay={(
<Popover id={`${result.verificationAttemptId}-details-tooltip`} aria-hidden="true">
<Popover.Title as="h5">{verificationAttemptDetails[result.verificationAttemptId].status}</Popover.Title>
<Popover.Content data-testid="verificationAttemptTooltip">
{verificationAttemptDetails[result.verificationAttemptId].message}
</Popover.Content>
<Popover.Title data-testid="verificationAttemptTooltipTitle">
{result.verificationAttemptStatus ? idvStatusFormat(result.verificationAttemptStatus) : 'Missing data'}
</Popover.Title>
</Popover>
)}
>
Expand All @@ -60,71 +114,14 @@ export default function VerifiedName({ username }) {
proctoringAttemptId: result.proctoredExamAttemptId,
createdAt: formatDate(result.created),
}),
), [verifiedNameHistoryData, verificationAttemptDetails]);
), [verifiedNameHistoryData]);

// Modal to display verified name history
const openVerifiedNameModal = async (data) => {
for (let idx = 0; idx < data.length; idx++) {
const historyItem = data[idx];
if (historyItem.verificationAttemptId && !(historyItem.verificationAttemptId in verificationAttemptDetails)) {
// eslint-disable-next-line no-await-in-loop
await getVerificationAttemptDetailsById(historyItem.verificationAttemptId).then((response) => {
const camelCaseDetailsData = camelCaseObject(response);
verificationAttemptDetails[historyItem.verificationAttemptId] = camelCaseDetailsData;
setVerificationAttemptDetails(verificationAttemptDetails);
});
}
}
setVerifiedNameHistoryData(data);
setIsModalOpen(true);
};

const verifiedNameColumns = useMemo(() => [
{
Header: 'Verified Name',
accessor: 'verifiedName',
},
{
Header: 'Status',
accessor: 'status',
},
{
Header: 'Verification Type',
accessor: 'verificationType',
},
{
Header: 'History',
accessor: 'history',
},
], []);

const verifiedNameHistoryColumns = useMemo(() => [
{
Header: 'Verified Name',
accessor: 'verifiedName',
},
{
Header: 'Profile Name',
accessor: 'profileName',
},
{
Header: 'Status',
accessor: 'status',
},
{
Header: 'IDV Attempt ID',
accessor: 'idvAttemptId',
},
{
Header: 'Proctoring Attempt ID',
accessor: 'proctoringAttemptId',
},
{
Header: 'Created At',
accessor: 'createdAt',
},
], []);

const verifiedNameParsedData = useMemo(() => [{
verifiedName: (
verifiedNameData?.verifiedName || verifiedNameData?.error || 'Error while fetching data'
Expand Down
23 changes: 3 additions & 20 deletions src/users/VerifiedName.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,7 @@ describe('Verified Name', () => {
history: verifiedNameHistory.results,
};

const idVerificationAttemptDetails = {
status: 'denied',
message: '[{"generalReasons": ["Name mismatch"]}]',
};

jest.spyOn(api, 'getVerifiedNameHistory').mockResolvedValueOnce(verifiedNameData);
jest.spyOn(api, 'getVerificationAttemptDetailsById').mockResolvedValueOnce(idVerificationAttemptDetails);
render(<VerifiedNameWrapper {...props} />);

const historyButton = await screen.findByText('Show');
Expand All @@ -63,16 +57,7 @@ describe('Verified Name', () => {
verificationType: 'Proctoring',
history: verifiedNameHistory.results,
};
const idVerificationAttemptDetails = {
status: 'denied',
message: '[{"generalReasons": ["Name mismatch"]}]',
};
jest.spyOn(api, 'getVerifiedNameHistory').mockResolvedValueOnce(verifiedNameData);
const getVerificationAPICallSpy = jest.spyOn(
api,
'getVerificationAttemptDetailsById',
).mockResolvedValueOnce(idVerificationAttemptDetails);

await act(async () => {
render(<VerifiedNameWrapper {...props} />);
});
Expand All @@ -82,15 +67,13 @@ describe('Verified Name', () => {
fireEvent.click(historyButton);
});

expect(getVerificationAPICallSpy).toHaveBeenCalledWith(
verifiedNameHistory.results[1].verification_attempt_id,
);

const hoverLink = await screen.getByText(verifiedNameHistory.results[1].verification_attempt_id);
await act(async () => {
fireEvent.mouseOver(hoverLink);
});

await screen.getByTestId('verificationAttemptTooltip');
await screen.getByTestId('verificationAttemptTooltipTitle');

expect(screen.getByText('Must retry')).toBeTruthy();
});
});
2 changes: 2 additions & 0 deletions src/users/data/test/verifiedNameHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const verifiedNameHistory = {
verified_name: 'Jonathan Doe',
profile_name: 'Jon Doe',
verification_attempt_id: null,
verification_attempt_status: null,
proctored_exam_attempt_id: 123,
status: 'approved',
},
Expand All @@ -13,6 +14,7 @@ const verifiedNameHistory = {
verified_name: 'J Doe',
profile_name: 'Jon Doe',
verification_attempt_id: 456,
verification_attempt_status: 'must_retry',
proctored_exam_attempt_id: null,
status: 'denied',
},
Expand Down