Skip to content

Commit

Permalink
feat: Removed IDV Status details call (#418)
Browse files Browse the repository at this point in the history
* feat: Removed IDV Status details call

* fix: Removed parsing on database value for status. Added label
  • Loading branch information
rijuma authored Sep 16, 2024
1 parent 9d06fe6 commit 8dba940
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 83 deletions.
116 changes: 53 additions & 63 deletions src/users/VerifiedName.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,58 @@ 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',
},
];

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,9 +90,11 @@ 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.Title as="h3">
Status
</Popover.Title>
<Popover.Content data-testid="verificationAttemptTooltipTitle">
{result.verificationAttemptStatus ? result.verificationAttemptStatus : 'Error: Missing data'}
</Popover.Content>
</Popover>
)}
Expand All @@ -60,71 +107,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

0 comments on commit 8dba940

Please sign in to comment.