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: add view certificate button #121

Merged
merged 2 commits into from
Jun 28, 2021
Merged

feat: add view certificate button #121

merged 2 commits into from
Jun 28, 2021

Conversation

DawoudSheraz
Copy link
Contributor

@DawoudSheraz DawoudSheraz commented May 24, 2021

PROD-2357

Description

Add certificate tool with the following features:

  • Get certificate details
  • Generate certificate
  • Regenerate certificate

The backend APIs are the same as old support tools, located at https://github.com/edx/edx-platform/blob/master/lms/djangoapps/certificates/views/support.py. The view cert button is added to the enrollment listing, as requested in the ticket.

image
image
image
image
image

@codecov
Copy link

codecov bot commented May 28, 2021

Codecov Report

Merging #121 (95d4802) into master (dbb9cfb) will increase coverage by 2.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #121      +/-   ##
==========================================
+ Coverage   76.23%   78.26%   +2.03%     
==========================================
  Files          43       45       +2     
  Lines         930     1017      +87     
  Branches      183      199      +16     
==========================================
+ Hits          709      796      +87     
  Misses        210      210              
  Partials       11       11              
Impacted Files Coverage Δ
src/users/data/api.js 99.33% <100.00%> (+0.08%) ⬆️
src/users/data/test/certificates.js 100.00% <100.00%> (ø)
src/users/data/urls.js 100.00% <100.00%> (ø)
src/users/enrollments/Certificates.jsx 100.00% <100.00%> (ø)
src/users/enrollments/Enrollments.jsx 98.27% <100.00%> (+0.16%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dbb9cfb...95d4802. Read the comment docs.

@DawoudSheraz DawoudSheraz force-pushed the dsheraz/PROD-2357 branch 2 times, most recently from 8222190 to 35f15db Compare June 23, 2021 15:58
@DawoudSheraz DawoudSheraz changed the title [WIP]feat: add view certificate button feat: add view certificate button Jun 24, 2021
Copy link
Contributor

@Ali-D-Akbar Ali-D-Akbar left a comment

Choose a reason for hiding this comment

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

A handful of queries to be addressed:

  1. Can you please add a screenshot for regenerate button scenario? Just wanted to confirm that only one of the button is shown
  2. What does a user see as a verification that an operation was successful? Some sort of a success message or the whole page/component refresh?

Comment on lines 22 to 24
const certificatesUrl = `${getConfig().LMS_BASE_URL}/certificates/search?user=${testUsername}&course_id=${testCourseId}`;
const generateCertificateUrl = `${getConfig().LMS_BASE_URL}/certificates/generate`;
const regenerateCertificateUrl = `${getConfig().LMS_BASE_URL}/certificates/regenerate`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why're you not using getCertificateUrl, regenerateCertificateUrl and regenerateCertificateUrl from urls.js?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, I will change it

Comment on lines +21 to +25
const props = {
username: testUser,
courseId: testCourseId,
closeHandler: jest.fn(() => {}),
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Move this in src/users/data/test/certificates.js.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not the exact data. The data is already in cert.js.

await waitForComponentToPaint(wrapper);
generateButton = wrapper.find('button#generate-certificate');
expect(wrapper.find('h3').length).toEqual(0);
expect(generateButton.prop('disabled')).toBeFalsy();
Copy link
Contributor

Choose a reason for hiding this comment

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

why is the generate-certificate button still not disabled after flow has been successful?
And are we showing some success message on success of certificate generation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because it is still possible to generate/regenerate after one attempt. The backend does not restrict reattempts for generation/regeneration. Ideally, the generate button would change into the regenerate button. But the mock in this current test is returning the generatable certificate data.

@DawoudSheraz
Copy link
Contributor Author

A handful of queries to be addressed:

  1. Can you please add a screenshot for regenerate button scenario? Just wanted to confirm that only one of the button is shown
  2. What does a user see as a verification that an operation was successful? Some sort of a success message or the whole page/component refresh?
  1. Ok, although there won't be much difference. Only status text is changed.
  2. If the generate/regenerate is successful, only the cert component reloads. This behavior is the same as the old support tools, where the reloading is done via django.

const { data } = await getAuthenticatedHttpClient().get(
AppUrls.getCertificateUrl(username, courseKey),
);
return Array.isArray(data) && data.length > 0 ? data[0] : data;
Copy link
Contributor

Choose a reason for hiding this comment

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

In what cases this endpoint will return an array or single item?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If course id is mentioned, then the single item, otherwise a list of certificates. We might not need this check. I added it for cautious purposes(unexpected data on stage/prod). Once the changes are live, I will validate and remove the unnecessary check.

AppUrls.generateCertificateUrl(),
formData,
);
return data;
Copy link
Contributor

Choose a reason for hiding this comment

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

What does data contain in this case? from here it says its a http response. Are we using it anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it is just a response. We are not using it anywhere though. The return value is used only in tests to verify the api behavior.


export const getCertificateUrl = (username, courseKey) => `${
LMS_BASE_URL
}/certificates/search?user=${username}&course_id=${courseKey}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

we may need to encode courseKey.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Encoding is not needed. Encoding the courseId results in 404 on backend.

<div className="m-3">
<h2>Course ID: {certificate.courseKey}</h2>
{status && (<h3>Status: {status} </h3>)}
<table className="table">
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a specific reason for not using Table component?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the Table component is more suited for listing with headings on top and data listed vertically. In cert case, the headers are on the left and data on right i.e. one header and one piece of data are on the same row. furthermore, the Table component has many other operations not needed in this case.

@DawoudSheraz DawoudSheraz merged commit 6630c19 into master Jun 28, 2021
@DawoudSheraz DawoudSheraz deleted the dsheraz/PROD-2357 branch June 28, 2021 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants