@coorpacademy/app-review 0.1.19 → 0.1.21-alpha.12
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.
- package/es/actions/api/post-answer.js +9 -8
- package/es/actions/api/test/post-answer.test.js +6 -6
- package/es/index.js +1 -4
- package/es/reducers/data/test/progression.test.js +4 -3
- package/es/services/fetch-correction.d.ts +2 -0
- package/es/services/fetch-correction.js +14 -0
- package/es/services/fetch-slide.js +1 -2
- package/es/services/index.js +5 -3
- package/es/services/post-answer.d.ts +1 -1
- package/es/services/post-answer.js +3 -1
- package/es/services/test/fetch-correction.test.d.ts +1 -0
- package/es/services/test/fetch-correction.test.js +39 -0
- package/es/services/test/post-answer.test.js +27 -4
- package/es/test/util/services.mock.d.ts +2 -1
- package/es/test/util/services.mock.js +332 -23
- package/es/types/common.d.ts +20 -9
- package/es/views/slides/index.d.ts +1 -0
- package/es/views/slides/index.js +24 -8
- package/es/views/slides/test/index.test.js +518 -203
- package/lib/actions/api/post-answer.js +10 -9
- package/lib/actions/api/test/post-answer.test.js +6 -6
- package/lib/index.js +1 -4
- package/lib/reducers/data/test/progression.test.js +4 -3
- package/lib/services/fetch-correction.d.ts +2 -0
- package/lib/services/fetch-correction.js +58 -0
- package/lib/services/fetch-slide.js +2 -5
- package/lib/services/index.js +5 -3
- package/lib/services/post-answer.d.ts +1 -1
- package/lib/services/post-answer.js +4 -2
- package/lib/services/test/fetch-correction.test.d.ts +1 -0
- package/lib/services/test/fetch-correction.test.js +95 -0
- package/lib/services/test/post-answer.test.js +27 -4
- package/lib/test/util/services.mock.d.ts +2 -1
- package/lib/test/util/services.mock.js +334 -23
- package/lib/types/common.d.ts +20 -9
- package/lib/views/slides/index.d.ts +1 -0
- package/lib/views/slides/index.js +23 -7
- package/lib/views/slides/test/index.test.js +521 -203
- package/package.json +4 -4
- package/src/actions/api/post-answer.ts +9 -9
- package/src/actions/api/test/post-answer.test.ts +6 -6
- package/src/index.tsx +1 -6
- package/src/reducers/data/test/progression.test.ts +4 -3
- package/src/services/fetch-correction.ts +26 -0
- package/src/services/fetch-slide.ts +1 -2
- package/src/services/index.ts +5 -3
- package/src/services/post-answer.ts +3 -2
- package/src/services/test/fetch-correction.test.ts +55 -0
- package/src/services/test/post-answer.test.ts +28 -4
- package/src/test/util/services.mock.ts +344 -24
- package/src/types/common.ts +29 -10
- package/src/views/slides/index.ts +35 -10
- package/src/views/slides/test/index.test.ts +559 -228
|
@@ -5,21 +5,22 @@ export const POST_ANSWER_REQUEST = '@@answer/POST_REQUEST';
|
|
|
5
5
|
export const POST_ANSWER_SUCCESS = '@@answer/POST_SUCCESS';
|
|
6
6
|
export const POST_ANSWER_FAILURE = '@@answer/POST_FAILURE';
|
|
7
7
|
export const postAnswer = async (dispatch, getState, { services }) => {
|
|
8
|
+
const state = getState();
|
|
9
|
+
const token = get('data.token', state);
|
|
10
|
+
const answer = get('ui.answers', state);
|
|
11
|
+
const progression = state.data.progression;
|
|
12
|
+
if (!progression)
|
|
13
|
+
throw new Error('cannot answer question of inexisting progression');
|
|
8
14
|
const action = buildTask({
|
|
9
15
|
types: [POST_ANSWER_REQUEST, POST_ANSWER_SUCCESS, POST_ANSWER_FAILURE],
|
|
10
16
|
task: () => {
|
|
11
|
-
|
|
12
|
-
const token = get('data.token', state);
|
|
13
|
-
const answer = get('ui.answers', state);
|
|
14
|
-
const progressionId = get('data.progression._id', state);
|
|
15
|
-
const skillRef = get('data.progression.content.ref', state);
|
|
16
|
-
return services.postAnswer(skillRef, token, progressionId, answer);
|
|
17
|
+
return services.postAnswer(progression, token, answer);
|
|
17
18
|
}
|
|
18
19
|
});
|
|
19
20
|
const response = await dispatch(action);
|
|
20
21
|
if (response.type === POST_ANSWER_SUCCESS) {
|
|
21
|
-
const
|
|
22
|
-
const slideRef =
|
|
22
|
+
const updatedProgression = response.payload;
|
|
23
|
+
const slideRef = updatedProgression.state.nextContent.ref;
|
|
23
24
|
await dispatch(fetchSlide(slideRef));
|
|
24
25
|
}
|
|
25
26
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import test from 'ava';
|
|
2
2
|
import { createTestStore } from '../../test/create-test-store';
|
|
3
|
-
import {
|
|
3
|
+
import { postAnswerResponses, services } from '../../../test/util/services.mock';
|
|
4
4
|
import { postAnswer, POST_ANSWER_FAILURE, POST_ANSWER_REQUEST, POST_ANSWER_SUCCESS } from '../post-answer';
|
|
5
5
|
import { SLIDE_FETCH_REQUEST, SLIDE_FETCH_SUCCESS } from '../fetch-slide';
|
|
6
6
|
import { qcmGraphicSlide } from '../../../views/slides/test/fixtures/qcm-graphic';
|
|
@@ -21,7 +21,7 @@ const initialState = {
|
|
|
21
21
|
allAnswers: [],
|
|
22
22
|
isCorrect: true,
|
|
23
23
|
nextContent: {
|
|
24
|
-
ref:
|
|
24
|
+
ref: freeTextSlide.id,
|
|
25
25
|
type: 'slide'
|
|
26
26
|
},
|
|
27
27
|
pendingSlides: [],
|
|
@@ -39,7 +39,7 @@ const initialState = {
|
|
|
39
39
|
token: '1234'
|
|
40
40
|
},
|
|
41
41
|
ui: {
|
|
42
|
-
currentSlideRef:
|
|
42
|
+
currentSlideRef: freeTextSlide.id,
|
|
43
43
|
navigation: ['skills', 'slides'],
|
|
44
44
|
answers: answer,
|
|
45
45
|
slide: {
|
|
@@ -52,12 +52,12 @@ test('should dispatch POST_ANSWER_REQUEST, then POST_ANSWER_SUCCESS when the upd
|
|
|
52
52
|
{ type: POST_ANSWER_REQUEST },
|
|
53
53
|
{
|
|
54
54
|
type: POST_ANSWER_SUCCESS,
|
|
55
|
-
payload:
|
|
55
|
+
payload: postAnswerResponses[freeTextSlide.id]
|
|
56
56
|
},
|
|
57
|
-
{ type: SLIDE_FETCH_REQUEST, meta: { slideRef:
|
|
57
|
+
{ type: SLIDE_FETCH_REQUEST, meta: { slideRef: qcmGraphicSlide.id } },
|
|
58
58
|
{
|
|
59
59
|
type: SLIDE_FETCH_SUCCESS,
|
|
60
|
-
meta: { slideRef:
|
|
60
|
+
meta: { slideRef: qcmGraphicSlide.id },
|
|
61
61
|
payload: qcmGraphicSlide
|
|
62
62
|
},
|
|
63
63
|
{ type: SET_CURRENT_SLIDE, payload: qcmGraphicSlide }
|
package/es/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React, { useEffect, useState } from 'react';
|
|
2
2
|
import { useSelector, useDispatch, Provider } from 'react-redux';
|
|
3
3
|
import AppReviewTemplate from '@coorpacademy/components/es/template/app-review';
|
|
4
|
-
import { TemplateContext } from '@coorpacademy/components/es/template/app-review/template-context';
|
|
5
4
|
import isEmpty from 'lodash/fp/isEmpty';
|
|
6
5
|
import get from 'lodash/fp/get';
|
|
7
6
|
import configureStore from './configure-store';
|
|
@@ -66,9 +65,7 @@ const AppReview = ({ options }) => {
|
|
|
66
65
|
}, [isProgressionCreated, options, store]);
|
|
67
66
|
if (!store)
|
|
68
67
|
return null;
|
|
69
|
-
const { templateContext: values } = options;
|
|
70
68
|
return (React.createElement(Provider, { store: store },
|
|
71
|
-
React.createElement(
|
|
72
|
-
React.createElement(ConnectedApp, null))));
|
|
69
|
+
React.createElement(ConnectedApp, null)));
|
|
73
70
|
};
|
|
74
71
|
export default AppReview;
|
|
@@ -2,7 +2,8 @@ import test from 'ava';
|
|
|
2
2
|
import reducer from '../progression';
|
|
3
3
|
import { POST_PROGRESSION_SUCCESS } from '../../../actions/api/post-progression';
|
|
4
4
|
import { POST_ANSWER_SUCCESS } from '../../../actions/api/post-answer';
|
|
5
|
-
import {
|
|
5
|
+
import { postAnswerResponses, postProgressionResponse } from '../../../test/util/services.mock';
|
|
6
|
+
import { freeTextSlide } from '../../../views/slides/test/fixtures/free-text';
|
|
6
7
|
test('should have initial value', t => {
|
|
7
8
|
const state = reducer(undefined, {});
|
|
8
9
|
t.is(state, null);
|
|
@@ -17,7 +18,7 @@ test('should set the value of POST_PROGRESSION_SUCCESS action', t => {
|
|
|
17
18
|
test('should set the value of POST_ANSWER_SUCCESS action', t => {
|
|
18
19
|
const state = reducer(null, {
|
|
19
20
|
type: POST_ANSWER_SUCCESS,
|
|
20
|
-
payload:
|
|
21
|
+
payload: postAnswerResponses[freeTextSlide.universalRef]
|
|
21
22
|
});
|
|
22
|
-
t.deepEqual(state,
|
|
23
|
+
t.deepEqual(state, postAnswerResponses[freeTextSlide.universalRef]);
|
|
23
24
|
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import crossFetch from 'cross-fetch';
|
|
2
|
+
import decode from 'jwt-decode';
|
|
3
|
+
import { toJSON } from './tools/fetch-responses';
|
|
4
|
+
export const fetchCorrection = async (slideRef, token, progressionId, answer) => {
|
|
5
|
+
const { host } = decode(token);
|
|
6
|
+
const response = await crossFetch(`${host}/api/v2/progressions/${progressionId}/answers/${slideRef}`, {
|
|
7
|
+
method: 'post',
|
|
8
|
+
headers: { authorization: token },
|
|
9
|
+
body: JSON.stringify({
|
|
10
|
+
answer
|
|
11
|
+
})
|
|
12
|
+
});
|
|
13
|
+
return toJSON(response);
|
|
14
|
+
};
|
|
@@ -6,6 +6,5 @@ export const fetchSlide = async (slideRef, token) => {
|
|
|
6
6
|
const response = await crossFetch(`${host}/api/v2/slide/${slideRef}/parentContentTitle`, {
|
|
7
7
|
headers: { authorization: token }
|
|
8
8
|
});
|
|
9
|
-
|
|
10
|
-
return slide;
|
|
9
|
+
return toJSON(response);
|
|
11
10
|
};
|
package/es/services/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { fetchCorrection } from './fetch-correction';
|
|
1
2
|
import { fetchSkills } from './fetch-skills';
|
|
2
|
-
import { postProgression } from './post-progression';
|
|
3
3
|
import { fetchSlide } from './fetch-slide';
|
|
4
4
|
import { postAnswer } from './post-answer';
|
|
5
|
+
import { postProgression } from './post-progression';
|
|
5
6
|
export const getServices = () => ({
|
|
7
|
+
fetchCorrection,
|
|
6
8
|
fetchSkills,
|
|
7
9
|
fetchSlide,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
postAnswer,
|
|
11
|
+
postProgression
|
|
10
12
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ProgressionFromAPI } from '../types/common';
|
|
2
|
-
export declare const postAnswer: (
|
|
2
|
+
export declare const postAnswer: (progression: ProgressionFromAPI, token: string, answer: string[]) => Promise<ProgressionFromAPI>;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import crossFetch from 'cross-fetch';
|
|
2
2
|
import decode from 'jwt-decode';
|
|
3
3
|
import { toJSON } from './tools/fetch-responses';
|
|
4
|
-
export const postAnswer = async (
|
|
4
|
+
export const postAnswer = async (progression, token, answer) => {
|
|
5
|
+
const progressionId = progression._id;
|
|
6
|
+
const skillRef = progression.content.ref;
|
|
5
7
|
const { host } = decode(token);
|
|
6
8
|
const response = await crossFetch(`${host}/api/v2/progressions/${progressionId}/answers`, {
|
|
7
9
|
method: 'post',
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import test from 'ava';
|
|
2
|
+
import nock from 'nock';
|
|
3
|
+
import { fetchCorrection } from '../fetch-correction';
|
|
4
|
+
const progressionId = '123456789123';
|
|
5
|
+
const slideRef = 'sli_123546';
|
|
6
|
+
const answer = ['Lister vos tâches pour vous libérer l’esprit', '15 jours à Bora Bora'];
|
|
7
|
+
const correction = {
|
|
8
|
+
correctAnswer: ['15 jours à Bora Bora'],
|
|
9
|
+
corrections: [
|
|
10
|
+
{
|
|
11
|
+
answer: answer[0],
|
|
12
|
+
isCorrect: false
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
answer: answer[1],
|
|
16
|
+
isCorrect: true
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
};
|
|
20
|
+
test.before(() => {
|
|
21
|
+
nock('http://localhost:3000')
|
|
22
|
+
.post(`/api/v2/progressions/${progressionId}/answers/${slideRef}`, JSON.stringify({
|
|
23
|
+
answer
|
|
24
|
+
}))
|
|
25
|
+
.reply(200, correction);
|
|
26
|
+
});
|
|
27
|
+
test.after(() => {
|
|
28
|
+
nock.cleanAll();
|
|
29
|
+
});
|
|
30
|
+
test('should fetch the correction of the slide for the specified progression successfully', async (t) => {
|
|
31
|
+
const token = process.env.API_TEST_TOKEN || '';
|
|
32
|
+
const response = await fetchCorrection(slideRef, token, progressionId, answer);
|
|
33
|
+
t.deepEqual(correction, response);
|
|
34
|
+
});
|
|
35
|
+
test('should reject if a bad token is passed', async (t) => {
|
|
36
|
+
const badToken = 'token is not a jwt';
|
|
37
|
+
const error = await t.throwsAsync(() => fetchCorrection(slideRef, badToken, progressionId, answer));
|
|
38
|
+
t.is(error?.message, "Invalid token specified: Cannot read properties of undefined (reading 'replace')");
|
|
39
|
+
});
|
|
@@ -1,9 +1,32 @@
|
|
|
1
1
|
import test from 'ava';
|
|
2
2
|
import nock from 'nock';
|
|
3
3
|
import { postAnswer } from '../post-answer';
|
|
4
|
-
const progressionId = '123456789123';
|
|
5
4
|
const skillRef = '_skill-ref';
|
|
6
5
|
const answer = ['Lister vos tâches pour vous libérer l’esprit', 'Vous isoler dans un lieu calme'];
|
|
6
|
+
const initProgression = {
|
|
7
|
+
content: {
|
|
8
|
+
type: 'skill',
|
|
9
|
+
ref: skillRef
|
|
10
|
+
},
|
|
11
|
+
engine: {
|
|
12
|
+
ref: 'review'
|
|
13
|
+
},
|
|
14
|
+
_id: '123456123456',
|
|
15
|
+
state: {
|
|
16
|
+
allAnswers: [],
|
|
17
|
+
isCorrect: true,
|
|
18
|
+
nextContent: {
|
|
19
|
+
type: 'slide',
|
|
20
|
+
ref: 'sli_NkvrWPFF2'
|
|
21
|
+
},
|
|
22
|
+
pendingSlides: [],
|
|
23
|
+
slides: [],
|
|
24
|
+
step: {
|
|
25
|
+
current: 1
|
|
26
|
+
},
|
|
27
|
+
stars: 0
|
|
28
|
+
}
|
|
29
|
+
};
|
|
7
30
|
const result = {
|
|
8
31
|
content: {
|
|
9
32
|
type: 'skill',
|
|
@@ -40,18 +63,18 @@ const result = {
|
|
|
40
63
|
};
|
|
41
64
|
test.before(() => {
|
|
42
65
|
const moocApi = nock('http://localhost:3000');
|
|
43
|
-
moocApi.post(
|
|
66
|
+
moocApi.post('/api/v2/progressions/123456123456/answers').reply(200, result);
|
|
44
67
|
});
|
|
45
68
|
test.after(() => {
|
|
46
69
|
nock.cleanAll();
|
|
47
70
|
});
|
|
48
71
|
test('should post the answers successfully', async (t) => {
|
|
49
72
|
const token = process.env.API_TEST_TOKEN || '';
|
|
50
|
-
const progression = await postAnswer(
|
|
73
|
+
const progression = await postAnswer(initProgression, token, answer);
|
|
51
74
|
t.deepEqual(result, progression);
|
|
52
75
|
});
|
|
53
76
|
test('should reject bad token', async (t) => {
|
|
54
77
|
const badToken = 'token is not a jwt';
|
|
55
|
-
const error = await t.throwsAsync(() => postAnswer(
|
|
78
|
+
const error = await t.throwsAsync(() => postAnswer(initProgression, badToken, answer));
|
|
56
79
|
t.is(error?.message, "Invalid token specified: Cannot read properties of undefined (reading 'replace')");
|
|
57
80
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ProgressionFromAPI, Services } from '../../types/common';
|
|
2
2
|
export declare const postProgressionResponse: ProgressionFromAPI;
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const postAnswerResponses: Record<string, ProgressionFromAPI>;
|
|
4
|
+
export declare const progressionSlideWithPendingSlide: ProgressionFromAPI;
|
|
4
5
|
export declare const services: Services;
|