richie-education 3.3.2-dev4 → 3.3.2-dev6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -170,7 +170,7 @@ describe('OpenEdX Hawthorn API', () => {
|
|
|
170
170
|
);
|
|
171
171
|
});
|
|
172
172
|
|
|
173
|
-
it('throws HttpError.localizedMessage on enrollment failure', async () => {
|
|
173
|
+
it('throws HttpError.localizedMessage on enrollment failure for bad requests', async () => {
|
|
174
174
|
fetchMock.post(`${EDX_ENDPOINT}/api/enrollment/v1/enrollment`, {
|
|
175
175
|
status: HttpStatusCode.BAD_REQUEST,
|
|
176
176
|
body: { localizedMessage: 'You are not authorized to enroll in this course' },
|
|
@@ -189,7 +189,7 @@ describe('OpenEdX Hawthorn API', () => {
|
|
|
189
189
|
);
|
|
190
190
|
});
|
|
191
191
|
|
|
192
|
-
it('throws HttpError on enrollment failure when localizedMessage property is not present in the payload', async () => {
|
|
192
|
+
it('throws HttpError on enrollment failure when localizedMessage property is not present in the payload for bad requests', async () => {
|
|
193
193
|
fetchMock.post(`${EDX_ENDPOINT}/api/enrollment/v1/enrollment`, {
|
|
194
194
|
status: HttpStatusCode.BAD_REQUEST,
|
|
195
195
|
body: { message: 'Bad Request' },
|
|
@@ -202,6 +202,38 @@ describe('OpenEdX Hawthorn API', () => {
|
|
|
202
202
|
).rejects.toThrow(new HttpError(HttpStatusCode.BAD_REQUEST, 'Bad Request'));
|
|
203
203
|
});
|
|
204
204
|
|
|
205
|
+
it('throws HttpError.localizedMessage on enrollment failure for forbidden requests', async () => {
|
|
206
|
+
fetchMock.post(`${EDX_ENDPOINT}/api/enrollment/v1/enrollment`, {
|
|
207
|
+
status: HttpStatusCode.FORBIDDEN,
|
|
208
|
+
body: { localizedMessage: 'You are not authorized to enroll in this course' },
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
await expect(
|
|
212
|
+
HawthornApi.enrollment.set(`https://demo.endpoint/courses?course_id=${courseId}`, {
|
|
213
|
+
username,
|
|
214
|
+
}),
|
|
215
|
+
).rejects.toThrow(
|
|
216
|
+
new HttpError(
|
|
217
|
+
HttpStatusCode.FORBIDDEN,
|
|
218
|
+
'Forbidden',
|
|
219
|
+
'You are not authorized to enroll in this course',
|
|
220
|
+
),
|
|
221
|
+
);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('throws HttpError on enrollment failure when localizedMessage property is not present in the payload for forbidden requests', async () => {
|
|
225
|
+
fetchMock.post(`${EDX_ENDPOINT}/api/enrollment/v1/enrollment`, {
|
|
226
|
+
status: HttpStatusCode.FORBIDDEN,
|
|
227
|
+
body: { message: 'Forbidden' },
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
await expect(
|
|
231
|
+
HawthornApi.enrollment.set(`https://demo.endpoint/courses?course_id=${courseId}`, {
|
|
232
|
+
username,
|
|
233
|
+
}),
|
|
234
|
+
).rejects.toThrow(new HttpError(HttpStatusCode.FORBIDDEN, 'Forbidden'));
|
|
235
|
+
});
|
|
236
|
+
|
|
205
237
|
it('throws HttpError when response has no json payload', async () => {
|
|
206
238
|
fetchMock.post(`${EDX_ENDPOINT}/api/enrollment/v1/enrollment`, HttpStatusCode.BAD_REQUEST);
|
|
207
239
|
|
|
@@ -115,7 +115,10 @@ const API = (APIConf: AuthenticationBackend | LMSBackend, options?: APIOptions):
|
|
|
115
115
|
})
|
|
116
116
|
.then(async (response) => {
|
|
117
117
|
if (response.ok) return response.json();
|
|
118
|
-
if (
|
|
118
|
+
if (
|
|
119
|
+
response.status === HttpStatusCode.BAD_REQUEST ||
|
|
120
|
+
response.status === HttpStatusCode.FORBIDDEN
|
|
121
|
+
) {
|
|
119
122
|
if (response.headers.get('Content-Type') === 'application/json') {
|
|
120
123
|
const { localizedMessage } = await response.json();
|
|
121
124
|
throw new HttpError(response.status, response.statusText, localizedMessage);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "richie-education",
|
|
3
|
-
"version": "3.3.2-
|
|
3
|
+
"version": "3.3.2-dev6",
|
|
4
4
|
"description": "A CMS to build learning portals for Open Education",
|
|
5
5
|
"main": "sandbox/manage.py",
|
|
6
6
|
"scripts": {
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"extract-translations": "formatjs extract './**/*.ts*' --ignore ./node_modules --ignore './**/*.d.ts' --out-file './i18n/frontend.json' --id-interpolation-pattern '[sha512:contenthash:base64:6]' --format crowdin",
|
|
10
10
|
"compile-translations": "./i18n/compile-translations.js",
|
|
11
11
|
"lint": "eslint . 'js/**/*.ts?(x)'",
|
|
12
|
+
"prettier-check": "prettier --check 'js/**/*.+(ts|tsx|json|js|jsx)' '*.+(ts|tsx|json|js|jsx)' '**/*.+(css|scss)'",
|
|
12
13
|
"prettier-write": "prettier --write 'js/**/*.+(ts|tsx|json|js|jsx)' '*.+(ts|tsx|json|js|jsx)' '**/*.+(css|scss)'",
|
|
13
14
|
"build-sass": "sass scss/_main.scss ../richie/static/richie/css/main.css --load-path=node_modules",
|
|
14
15
|
"build-sass-production": "sass scss/_main.scss ../richie/static/richie/css/main.css --style=compressed --load-path=node_modules",
|