-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add view certificate button (#121)
* feat: add view certificate button
- Loading branch information
1 parent
dbb9cfb
commit 6630c19
Showing
8 changed files
with
663 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,14 @@ import { getConfig } from '@edx/frontend-platform'; | |
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; | ||
|
||
import { enrollmentsData } from './test/enrollments'; | ||
import { downloadableCertificate } from './test/certificates'; | ||
import * as api from './api'; | ||
import * as urls from './urls'; | ||
|
||
describe('API', () => { | ||
const testUsername = 'username'; | ||
const testEmail = '[email protected]'; | ||
const testCourseId = 'course-v1:testX+test123+2030'; | ||
const userAccountApiBaseUrl = `${getConfig().LMS_BASE_URL}/api/user/v1/accounts`; | ||
const ssoRecordsApiUrl = `${getConfig().LMS_BASE_URL}/support/sso_records/${testUsername}`; | ||
const enrollmentsApiUrl = `${getConfig().LMS_BASE_URL}/support/enrollment/${testUsername}`; | ||
|
@@ -17,6 +20,9 @@ describe('API', () => { | |
const verificationStatusApiUrl = `${getConfig().LMS_BASE_URL}/api/user/v1/accounts/${testUsername}/verification_status/`; | ||
const licensesApiUrl = `${getConfig().LICENSE_MANAGER_URL}/api/v1/staff_lookup_licenses/`; | ||
const onboardingStatusApiUrl = `${getConfig().LMS_BASE_URL}/api/edx_proctoring/v1/user_onboarding/status`; | ||
const certificatesUrl = urls.getCertificateUrl(testUsername, testCourseId); | ||
const generateCertificateUrl = urls.generateCertificateUrl(); | ||
const regenerateCertificateUrl = urls.regenerateCertificateUrl(); | ||
|
||
let mockAdapter; | ||
|
||
|
@@ -30,7 +36,7 @@ describe('API', () => { | |
}; | ||
|
||
beforeEach(() => { | ||
mockAdapter = new MockAdapter(getAuthenticatedHttpClient()); | ||
mockAdapter = new MockAdapter(getAuthenticatedHttpClient(), { onNoMatch: 'throwException' }); | ||
}); | ||
|
||
afterEach(() => { | ||
|
@@ -682,4 +688,72 @@ describe('API', () => { | |
}); | ||
}); | ||
}); | ||
|
||
describe('Certificate Operations', () => { | ||
const successDictResponse = downloadableCertificate; | ||
const successListResponse = [successDictResponse]; | ||
const expectedError = { | ||
code: null, | ||
dismissible: true, | ||
text: '', | ||
type: 'danger', | ||
topic: 'certificates', | ||
}; | ||
|
||
test.each([successDictResponse, successListResponse])('Successful Certificate Fetch', async (successResponse) => { | ||
mockAdapter.onGet(certificatesUrl).reply(200, successResponse); | ||
const response = await api.getCertificate(testUsername, testCourseId); | ||
expect(response).toEqual(Array.isArray(successResponse) ? successResponse[0] : successResponse); | ||
}); | ||
|
||
it('Unsuccessful Certificates fetch', async () => { | ||
mockAdapter.onGet(certificatesUrl).reply(() => throwError(400, '')); | ||
const response = await api.getCertificate(testUsername, testCourseId); | ||
expect(...response.errors).toEqual(expectedError); | ||
}); | ||
|
||
it('Successful generate Certificate', async () => { | ||
/** | ||
* No data is added in the post request check because axios-mock-adapter fails | ||
* with formData in post request. | ||
* See: https://github.com/ctimmerm/axios-mock-adapter/issues/253 | ||
*/ | ||
mockAdapter.onPost(generateCertificateUrl).reply(200, successDictResponse); | ||
const response = await api.generateCertificate(testUsername, testCourseId); | ||
expect(response).toEqual(successDictResponse); | ||
}); | ||
|
||
it('Unsuccessful generate Certificate', async () => { | ||
/** | ||
* No data is added in the post request check because axios-mock-adapter fails | ||
* with formData in post request. | ||
* See: https://github.com/ctimmerm/axios-mock-adapter/issues/253 | ||
*/ | ||
mockAdapter.onPost(generateCertificateUrl).reply(() => throwError(400, '')); | ||
const response = await api.generateCertificate(testUsername, testCourseId); | ||
expect(...response.errors).toEqual(expectedError); | ||
}); | ||
|
||
it('Successful regenerate Certificate', async () => { | ||
/** | ||
* No data is added in the post request check because axios-mock-adapter fails | ||
* with formData in post request. | ||
* See: https://github.com/ctimmerm/axios-mock-adapter/issues/253 | ||
*/ | ||
mockAdapter.onPost(regenerateCertificateUrl).reply(200, successDictResponse); | ||
const response = await api.regenerateCertificate(testUsername, testCourseId); | ||
expect(response).toEqual(successDictResponse); | ||
}); | ||
|
||
it('Unsuccessful regenerate Certificate', async () => { | ||
/** | ||
* No data is added in the post request check because axios-mock-adapter fails | ||
* with formData in post request. | ||
* See: https://github.com/ctimmerm/axios-mock-adapter/issues/253 | ||
*/ | ||
mockAdapter.onPost(regenerateCertificateUrl).reply(() => throwError(400, '')); | ||
const response = await api.regenerateCertificate(testUsername, testCourseId); | ||
expect(...response.errors).toEqual(expectedError); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export const downloadableCertificate = { | ||
courseKey: 'course-v1:testX+test123+2030', | ||
type: 'verified', | ||
status: 'passing', | ||
grade: '60', | ||
modified: new Date('2020/01/01').toLocaleString(), | ||
downloadUrl: '/certificates/1234-abcd', | ||
regenerate: false, | ||
}; | ||
|
||
export const regeneratableCertificate = { | ||
courseKey: 'course-v1:testX+test123+2030', | ||
type: 'verified', | ||
status: 'passing', | ||
grade: '60', | ||
modified: new Date('2020/01/01').toLocaleString(), | ||
downloadUrl: null, | ||
regenerate: true, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.