@coorpacademy/app-review 0.1.15 → 0.1.16

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.
Files changed (212) hide show
  1. package/es/actions/api/fetch-skills.d.ts +4 -6
  2. package/es/actions/api/fetch-skills.js +7 -4
  3. package/es/actions/api/fetch-slide.d.ts +14 -7
  4. package/es/actions/api/fetch-slide.js +22 -19
  5. package/es/actions/api/post-progression.d.ts +4 -6
  6. package/es/actions/api/post-progression.js +13 -8
  7. package/es/actions/api/test/create-test-store.d.ts +5 -0
  8. package/es/actions/api/test/create-test-store.js +16 -0
  9. package/es/actions/api/test/fetch-skills.test.js +54 -0
  10. package/es/actions/api/test/fetch-slide.test.js +61 -0
  11. package/es/actions/api/test/post-progression.test.d.ts +1 -0
  12. package/es/actions/api/test/post-progression.test.js +102 -0
  13. package/es/actions/ui/answers.d.ts +7 -0
  14. package/es/actions/ui/answers.js +7 -0
  15. package/es/fixtures/temp-fixture.d.ts +1 -1
  16. package/es/index.js +10 -16
  17. package/es/reducers/data/index.d.ts +1 -1
  18. package/es/reducers/data/slides.d.ts +2 -2
  19. package/es/reducers/data/slides.js +5 -1
  20. package/es/reducers/data/test/progression.test.d.ts +1 -0
  21. package/es/reducers/data/test/progression.test.js +38 -0
  22. package/es/reducers/data/test/skills.test.d.ts +1 -0
  23. package/es/reducers/data/test/skills.test.js +12 -0
  24. package/es/reducers/data/test/slides.test.d.ts +1 -0
  25. package/es/reducers/data/test/slides.test.js +20 -0
  26. package/es/reducers/data/test/token.test.d.ts +1 -0
  27. package/es/reducers/data/test/token.test.js +11 -0
  28. package/es/reducers/index.d.ts +2 -2
  29. package/es/reducers/ui/answers.d.ts +4 -0
  30. package/es/reducers/ui/answers.js +13 -0
  31. package/es/reducers/ui/index.d.ts +4 -4
  32. package/es/reducers/ui/index.js +2 -2
  33. package/es/reducers/ui/test/answers.test.d.ts +1 -0
  34. package/es/reducers/ui/test/answers.test.js +11 -0
  35. package/es/reducers/ui/test/current-slide-ref.test.d.ts +1 -0
  36. package/es/reducers/ui/test/current-slide-ref.test.js +12 -0
  37. package/es/reducers/ui/test/navigation.test.d.ts +1 -0
  38. package/es/reducers/ui/test/navigation.test.js +15 -0
  39. package/es/services/fetch-slide.js +1 -1
  40. package/es/services/index.js +3 -1
  41. package/es/services/post-answer.d.ts +2 -0
  42. package/es/services/post-answer.js +18 -0
  43. package/es/services/test/fetch-slide.test.d.ts +1 -0
  44. package/es/services/test/fetch-slide.test.js +22 -0
  45. package/es/services/test/post-answer.test.d.ts +1 -0
  46. package/es/services/test/post-answer.test.js +57 -0
  47. package/es/services/test/post-progression.test.js +9 -1
  48. package/es/test/util/services.mock.js +37 -7
  49. package/es/types/common.d.ts +22 -8
  50. package/es/views/slides/index.d.ts +78 -2
  51. package/es/views/slides/index.js +70 -4
  52. package/es/views/slides/map-api-slide-to-ui.d.ts +8 -0
  53. package/es/views/slides/map-api-slide-to-ui.js +172 -0
  54. package/{lib/helpers → es/views/slides}/test/fixtures/free-text.d.ts +1 -1
  55. package/es/views/slides/test/fixtures/free-text.js +38 -0
  56. package/es/{helpers → views/slides}/test/fixtures/qcm-drag.d.ts +1 -1
  57. package/es/views/slides/test/fixtures/qcm-drag.js +108 -0
  58. package/es/{helpers → views/slides}/test/fixtures/qcm-graphic.d.ts +1 -1
  59. package/es/views/slides/test/fixtures/qcm-graphic.js +88 -0
  60. package/es/{helpers → views/slides}/test/fixtures/qcm.d.ts +1 -1
  61. package/es/{helpers → views/slides}/test/fixtures/qcm.js +5 -1
  62. package/es/{helpers → views/slides}/test/fixtures/select-template.d.ts +1 -1
  63. package/es/views/slides/test/fixtures/select-template.js +92 -0
  64. package/es/{helpers → views/slides}/test/fixtures/slider.d.ts +1 -1
  65. package/es/views/slides/test/fixtures/slider.js +36 -0
  66. package/es/{helpers → views/slides}/test/fixtures/text-template.d.ts +1 -1
  67. package/es/{helpers → views/slides}/test/fixtures/text-template.js +5 -1
  68. package/es/views/slides/test/map-api-slide-to-ui.test.d.ts +1 -0
  69. package/es/{helpers → views/slides}/test/map-api-slide-to-ui.test.js +19 -9
  70. package/lib/actions/api/fetch-skills.d.ts +4 -6
  71. package/lib/actions/api/fetch-skills.js +55 -7
  72. package/lib/actions/api/fetch-slide.d.ts +14 -7
  73. package/lib/actions/api/fetch-slide.js +70 -20
  74. package/lib/actions/api/post-progression.d.ts +4 -6
  75. package/lib/actions/api/post-progression.js +63 -9
  76. package/lib/actions/api/test/create-test-store.d.ts +5 -0
  77. package/lib/actions/api/test/create-test-store.js +18 -0
  78. package/lib/actions/api/test/fetch-skills.test.d.ts +1 -0
  79. package/lib/actions/api/test/fetch-skills.test.js +113 -0
  80. package/lib/actions/api/test/fetch-slide.test.d.ts +1 -0
  81. package/lib/actions/api/test/fetch-slide.test.js +120 -0
  82. package/lib/actions/api/test/post-progression.test.d.ts +1 -0
  83. package/lib/actions/api/test/post-progression.test.js +160 -0
  84. package/lib/actions/ui/answers.d.ts +7 -0
  85. package/lib/actions/ui/answers.js +9 -0
  86. package/lib/fixtures/temp-fixture.d.ts +1 -1
  87. package/lib/index.js +21 -18
  88. package/lib/reducers/data/index.d.ts +1 -1
  89. package/lib/reducers/data/slides.d.ts +2 -2
  90. package/lib/reducers/data/slides.js +5 -1
  91. package/lib/reducers/data/test/progression.test.d.ts +1 -0
  92. package/lib/reducers/data/test/progression.test.js +38 -0
  93. package/lib/reducers/data/test/skills.test.d.ts +1 -0
  94. package/lib/reducers/data/test/skills.test.js +12 -0
  95. package/lib/reducers/data/test/slides.test.d.ts +1 -0
  96. package/lib/reducers/data/test/slides.test.js +20 -0
  97. package/lib/reducers/data/test/token.test.d.ts +1 -0
  98. package/lib/reducers/data/test/token.test.js +11 -0
  99. package/lib/reducers/index.d.ts +2 -2
  100. package/lib/reducers/ui/answers.d.ts +4 -0
  101. package/lib/reducers/ui/answers.js +14 -0
  102. package/lib/reducers/ui/index.d.ts +4 -4
  103. package/lib/reducers/ui/index.js +2 -2
  104. package/lib/reducers/ui/test/answers.test.d.ts +1 -0
  105. package/lib/reducers/ui/test/answers.test.js +11 -0
  106. package/lib/reducers/ui/test/current-slide-ref.test.d.ts +1 -0
  107. package/lib/reducers/ui/test/current-slide-ref.test.js +12 -0
  108. package/lib/reducers/ui/test/navigation.test.d.ts +1 -0
  109. package/lib/reducers/ui/test/navigation.test.js +15 -0
  110. package/lib/services/fetch-slide.js +1 -1
  111. package/lib/services/index.js +3 -1
  112. package/lib/services/post-answer.d.ts +2 -0
  113. package/lib/services/post-answer.js +62 -0
  114. package/lib/services/test/fetch-slide.test.d.ts +1 -0
  115. package/lib/services/test/fetch-slide.test.js +76 -0
  116. package/lib/services/test/post-answer.test.d.ts +1 -0
  117. package/lib/services/test/post-answer.test.js +111 -0
  118. package/lib/services/test/post-progression.test.js +9 -1
  119. package/lib/test/util/services.mock.js +37 -7
  120. package/lib/types/common.d.ts +22 -8
  121. package/lib/views/slides/index.d.ts +78 -2
  122. package/lib/views/slides/index.js +70 -4
  123. package/lib/views/slides/map-api-slide-to-ui.d.ts +8 -0
  124. package/lib/views/slides/map-api-slide-to-ui.js +178 -0
  125. package/{es/helpers → lib/views/slides}/test/fixtures/free-text.d.ts +1 -1
  126. package/lib/views/slides/test/fixtures/free-text.js +38 -0
  127. package/lib/{helpers → views/slides}/test/fixtures/qcm-drag.d.ts +1 -1
  128. package/lib/views/slides/test/fixtures/qcm-drag.js +108 -0
  129. package/lib/{helpers → views/slides}/test/fixtures/qcm-graphic.d.ts +1 -1
  130. package/lib/views/slides/test/fixtures/qcm-graphic.js +88 -0
  131. package/lib/{helpers → views/slides}/test/fixtures/qcm.d.ts +1 -1
  132. package/lib/{helpers → views/slides}/test/fixtures/qcm.js +5 -1
  133. package/lib/{helpers → views/slides}/test/fixtures/select-template.d.ts +1 -1
  134. package/lib/views/slides/test/fixtures/select-template.js +92 -0
  135. package/lib/{helpers → views/slides}/test/fixtures/slider.d.ts +1 -1
  136. package/lib/views/slides/test/fixtures/slider.js +36 -0
  137. package/lib/{helpers → views/slides}/test/fixtures/text-template.d.ts +1 -1
  138. package/lib/{helpers → views/slides}/test/fixtures/text-template.js +5 -1
  139. package/lib/views/slides/test/map-api-slide-to-ui.test.d.ts +1 -0
  140. package/lib/{helpers → views/slides}/test/map-api-slide-to-ui.test.js +19 -9
  141. package/package.json +3 -3
  142. package/src/actions/api/fetch-skills.ts +12 -12
  143. package/src/actions/api/fetch-slide.ts +33 -29
  144. package/src/actions/api/post-progression.ts +18 -21
  145. package/src/actions/api/test/create-test-store.ts +25 -0
  146. package/src/actions/api/test/fetch-skills.test.ts +70 -0
  147. package/src/actions/api/test/fetch-slide.test.ts +77 -0
  148. package/src/actions/api/test/post-progression.test.ts +119 -0
  149. package/src/actions/ui/answers.ts +16 -0
  150. package/src/fixtures/temp-fixture.ts +1 -1
  151. package/src/index.tsx +14 -29
  152. package/src/reducers/data/index.ts +1 -1
  153. package/src/reducers/data/slides.ts +11 -2
  154. package/src/reducers/data/test/progression.test.ts +42 -0
  155. package/src/reducers/data/test/skills.test.ts +14 -0
  156. package/src/reducers/data/test/slides.test.ts +26 -0
  157. package/src/reducers/data/test/token.test.ts +13 -0
  158. package/src/reducers/ui/answers.ts +19 -0
  159. package/src/reducers/ui/index.ts +3 -3
  160. package/src/reducers/ui/test/answers.test.ts +13 -0
  161. package/src/reducers/ui/test/current-slide-ref.test.ts +14 -0
  162. package/src/reducers/ui/test/navigation.test.ts +19 -0
  163. package/src/services/fetch-slide.ts +1 -1
  164. package/src/services/index.ts +3 -1
  165. package/src/services/post-answer.ts +27 -0
  166. package/src/services/test/fetch-slide.test.ts +30 -0
  167. package/src/services/test/post-answer.test.ts +68 -0
  168. package/src/services/test/post-progression.test.ts +9 -1
  169. package/src/test/util/services.mock.ts +37 -7
  170. package/src/types/common.ts +34 -14
  171. package/src/views/slides/index.ts +164 -5
  172. package/src/views/slides/map-api-slide-to-ui.ts +251 -0
  173. package/src/views/slides/test/fixtures/free-text.ts +43 -0
  174. package/src/views/slides/test/fixtures/qcm-drag.ts +111 -0
  175. package/src/views/slides/test/fixtures/qcm-graphic.ts +94 -0
  176. package/src/{helpers → views/slides}/test/fixtures/qcm.ts +6 -2
  177. package/src/views/slides/test/fixtures/select-template.ts +98 -0
  178. package/src/views/slides/test/fixtures/slider.ts +41 -0
  179. package/src/{helpers → views/slides}/test/fixtures/text-template.ts +6 -2
  180. package/src/{helpers → views/slides}/test/map-api-slide-to-ui.test.ts +21 -10
  181. package/es/helpers/map-api-slide-to-ui.d.ts +0 -11
  182. package/es/helpers/map-api-slide-to-ui.js +0 -193
  183. package/es/helpers/test/fixtures/free-text.js +0 -30
  184. package/es/helpers/test/fixtures/qcm-drag.js +0 -112
  185. package/es/helpers/test/fixtures/qcm-graphic.js +0 -76
  186. package/es/helpers/test/fixtures/select-template.js +0 -94
  187. package/es/helpers/test/fixtures/slider.js +0 -33
  188. package/es/reducers/ui/slides.d.ts +0 -9
  189. package/es/reducers/ui/slides.js +0 -42
  190. package/es/types/views/slides.d.ts +0 -74
  191. package/es/types/views/slides.js +0 -6
  192. package/lib/helpers/map-api-slide-to-ui.d.ts +0 -11
  193. package/lib/helpers/map-api-slide-to-ui.js +0 -201
  194. package/lib/helpers/test/fixtures/free-text.js +0 -30
  195. package/lib/helpers/test/fixtures/qcm-drag.js +0 -112
  196. package/lib/helpers/test/fixtures/qcm-graphic.js +0 -76
  197. package/lib/helpers/test/fixtures/select-template.js +0 -94
  198. package/lib/helpers/test/fixtures/slider.js +0 -33
  199. package/lib/reducers/ui/slides.d.ts +0 -9
  200. package/lib/reducers/ui/slides.js +0 -43
  201. package/lib/types/views/slides.d.ts +0 -74
  202. package/lib/types/views/slides.js +0 -6
  203. package/src/helpers/map-api-slide-to-ui.ts +0 -279
  204. package/src/helpers/test/fixtures/free-text.ts +0 -33
  205. package/src/helpers/test/fixtures/qcm-drag.ts +0 -115
  206. package/src/helpers/test/fixtures/qcm-graphic.ts +0 -79
  207. package/src/helpers/test/fixtures/select-template.ts +0 -97
  208. package/src/helpers/test/fixtures/slider.ts +0 -36
  209. package/src/reducers/ui/slides.ts +0 -58
  210. package/src/types/views/slides.ts +0 -90
  211. /package/es/{helpers/test/map-api-slide-to-ui.test.d.ts → actions/api/test/fetch-skills.test.d.ts} +0 -0
  212. /package/{lib/helpers/test/map-api-slide-to-ui.test.d.ts → es/actions/api/test/fetch-slide.test.d.ts} +0 -0
@@ -1,9 +1,14 @@
1
1
  import set from 'lodash/fp/set';
2
2
  import {ValidateSlide} from '../../actions/ui/slides';
3
- import {ReceivedSlide, SLIDE_FETCH_SUCCESS} from '../../actions/api/fetch-slide';
3
+ import {
4
+ ReceivedSlide,
5
+ FetchSlide,
6
+ SLIDE_FETCH_REQUEST,
7
+ SLIDE_FETCH_SUCCESS
8
+ } from '../../actions/api/fetch-slide';
4
9
  import {SlideFromAPI} from '../../types/common';
5
10
 
6
- export type SlidesAction = ReceivedSlide | ValidateSlide;
11
+ export type SlidesAction = FetchSlide | ReceivedSlide | ValidateSlide;
7
12
 
8
13
  export type SlidesState = Record<string, SlideFromAPI>;
9
14
  export const initialState: SlidesState = {};
@@ -11,6 +16,10 @@ export const initialState: SlidesState = {};
11
16
  // eslint-disable-next-line default-param-last
12
17
  const reducer = (state: SlidesState = initialState, action: SlidesAction): SlidesState => {
13
18
  switch (action.type) {
19
+ case SLIDE_FETCH_REQUEST: {
20
+ const {meta} = action;
21
+ return set(meta.slideRef, null, state);
22
+ }
14
23
  case SLIDE_FETCH_SUCCESS: {
15
24
  const slide = action.payload;
16
25
  return set(slide.id, slide, state);
@@ -0,0 +1,42 @@
1
+ import test from 'ava';
2
+ import reducer from '../progression';
3
+ import {POST_PROGRESSION_SUCCESS, ReceiveProgression} from '../../../actions/api/post-progression';
4
+ import {ProgressionFromAPI} from '../../../types/common';
5
+
6
+ test('should have inital value', t => {
7
+ const state = reducer(undefined, {} as ReceiveProgression);
8
+ t.is(state, null);
9
+ });
10
+
11
+ test('should set the value of POST_PROGRESSION_SUCCESS action', t => {
12
+ const progression: ProgressionFromAPI = {
13
+ _id: '62b1d1087aa12f00253f40ee',
14
+ content: {
15
+ ref: '_skill-ref',
16
+ type: 'skill'
17
+ },
18
+ engine: {
19
+ ref: 'review'
20
+ },
21
+ state: {
22
+ allAnswers: [],
23
+ isCorrect: true,
24
+ nextContent: {
25
+ ref: 'sli_N1XACJobn',
26
+ type: 'slide'
27
+ },
28
+ pendingSlides: [],
29
+ slides: [],
30
+ step: {
31
+ current: 1
32
+ },
33
+ stars: 0
34
+ }
35
+ };
36
+
37
+ const state = reducer(null, {
38
+ type: POST_PROGRESSION_SUCCESS,
39
+ payload: progression
40
+ });
41
+ t.deepEqual(state, progression);
42
+ });
@@ -0,0 +1,14 @@
1
+ import test from 'ava';
2
+ import reducer from '../skills';
3
+ import {ReceivedSkills, SKILLS_FETCH_SUCCESS} from '../../../actions/api/fetch-skills';
4
+
5
+ test('should have inital value', t => {
6
+ const state = reducer(undefined, {} as ReceivedSkills);
7
+ t.deepEqual(state, []);
8
+ });
9
+
10
+ test('should set the value of SKILLS_FETCH_SUCCESS action', t => {
11
+ const skills = [{skillRef: 'skill', name: 'skill name', slidesToReview: 5, custom: false}];
12
+ const state = reducer([], {type: SKILLS_FETCH_SUCCESS, payload: skills});
13
+ t.deepEqual(state, skills);
14
+ });
@@ -0,0 +1,26 @@
1
+ import test from 'ava';
2
+ import reducer, {type SlidesAction} from '../slides';
3
+ import {SLIDE_FETCH_REQUEST, SLIDE_FETCH_SUCCESS} from '../../../actions/api/fetch-slide';
4
+ import {freeTextSlide} from '../../../views/slides/test/fixtures/free-text';
5
+
6
+ test('should have inital value', t => {
7
+ const state = reducer(undefined, {} as SlidesAction);
8
+ t.deepEqual(state, {});
9
+ });
10
+
11
+ test('should set the value of SLIDE_FETCH_REQUEST action', t => {
12
+ const state = reducer({}, {type: SLIDE_FETCH_REQUEST, meta: {slideRef: 'slideRef'}});
13
+ t.deepEqual(state, {
14
+ slideRef: null
15
+ });
16
+ });
17
+
18
+ test('should set the value of SLIDE_FETCH_SUCCESS action', t => {
19
+ const state = reducer(
20
+ {},
21
+ {type: SLIDE_FETCH_SUCCESS, payload: freeTextSlide, meta: {slideRef: 'sli_VJYjJnJhg'}}
22
+ );
23
+ t.deepEqual(state, {
24
+ sli_VJYjJnJhg: freeTextSlide
25
+ });
26
+ });
@@ -0,0 +1,13 @@
1
+ import test from 'ava';
2
+ import reducer from '../token';
3
+ import {StoreToken, STORE_TOKEN} from '../../../actions/data/token';
4
+
5
+ test('should have inital value', t => {
6
+ const state = reducer(undefined, {} as StoreToken);
7
+ t.is(state, null);
8
+ });
9
+
10
+ test('should set the value of STORE_TOKEN action', t => {
11
+ const state = reducer(null, {type: STORE_TOKEN, payload: 'token'});
12
+ t.is(state, 'token');
13
+ });
@@ -0,0 +1,19 @@
1
+ import {EditBasicAction, EDIT_BASIC} from '../../actions/ui/answers';
2
+
3
+ export type AnswerState = string[];
4
+
5
+ const reducer = (
6
+ // eslint-disable-next-line default-param-last
7
+ state: AnswerState = [],
8
+ action: EditBasicAction
9
+ ): AnswerState => {
10
+ switch (action.type) {
11
+ case EDIT_BASIC: {
12
+ return action.payload;
13
+ }
14
+ default:
15
+ return state;
16
+ }
17
+ };
18
+
19
+ export default reducer;
@@ -2,16 +2,16 @@ import {combineReducers} from 'redux';
2
2
 
3
3
  import currentSlideRef, {CurrentSlideRefState} from './current-slide-ref';
4
4
  import navigation, {NavigationState} from './navigation';
5
- import slides, {UISlidesState} from './slides';
5
+ import answers, {AnswerState} from './answers';
6
6
 
7
7
  export type UIState = {
8
8
  currentSlideRef: CurrentSlideRefState;
9
9
  navigation: NavigationState;
10
- slides: UISlidesState;
10
+ answers: AnswerState;
11
11
  };
12
12
 
13
13
  export default combineReducers({
14
14
  currentSlideRef,
15
15
  navigation,
16
- slides
16
+ answers
17
17
  });
@@ -0,0 +1,13 @@
1
+ import test from 'ava';
2
+ import reducer from '../answers';
3
+ import {EditBasicAction, EDIT_BASIC} from '../../../actions/ui/answers';
4
+
5
+ test('should have inital value', t => {
6
+ const state = reducer(undefined, {} as EditBasicAction);
7
+ t.deepEqual(state, []);
8
+ });
9
+
10
+ test('should set the value of EDIT_BASIC action', t => {
11
+ const state = reducer([], {type: EDIT_BASIC, payload: ['value']});
12
+ t.deepEqual(state, ['value']);
13
+ });
@@ -0,0 +1,14 @@
1
+ import test from 'ava';
2
+ import reducer from '../current-slide-ref';
3
+ import {SetCurrentSlide, SET_CURRENT_SLIDE} from '../../../actions/ui/slides';
4
+ import {freeTextSlide} from '../../../views/slides/test/fixtures/free-text';
5
+
6
+ test('should have inital value', t => {
7
+ const state = reducer(undefined, {} as SetCurrentSlide);
8
+ t.is(state, '');
9
+ });
10
+
11
+ test('should set the value of SET_CURRENT_SLIDE action', t => {
12
+ const state = reducer('', {type: SET_CURRENT_SLIDE, payload: freeTextSlide});
13
+ t.is(state, 'sli_VJYjJnJhg');
14
+ });
@@ -0,0 +1,19 @@
1
+ import test from 'ava';
2
+ import reducer from '../navigation';
3
+ import {NavigateTo, NAVIGATE_TO, NAVIGATE_BACK} from '../../../actions/ui/navigation';
4
+
5
+ test('should have inital value', t => {
6
+ const state = reducer(undefined, {} as NavigateTo);
7
+ t.deepEqual(state, []);
8
+ });
9
+
10
+ test('should set the value of NAVIGATE_TO and NAVIGATE_BACK action', t => {
11
+ const state = reducer([], {type: NAVIGATE_TO, payload: 'loader'});
12
+ t.deepEqual(state, ['loader']);
13
+
14
+ const updatedState = reducer(state, {type: NAVIGATE_TO, payload: 'skills'});
15
+ t.deepEqual(updatedState, ['loader', 'skills']);
16
+
17
+ const _updatedState = reducer(updatedState, {type: NAVIGATE_BACK});
18
+ t.deepEqual(_updatedState, ['loader']);
19
+ });
@@ -6,7 +6,7 @@ import {toJSON} from './tools/fetch-responses';
6
6
 
7
7
  export const fetchSlide = async (slideRef: string, token: string): Promise<SlideFromAPI | void> => {
8
8
  const {host}: JWT = decode(token);
9
- const response = await crossFetch(`${host}/api/v2/slide/${slideRef}`, {
9
+ const response = await crossFetch(`${host}/api/v2/slide/${slideRef}/parentContentTitle`, {
10
10
  headers: {authorization: token}
11
11
  });
12
12
 
@@ -2,9 +2,11 @@ import {Services} from '../types/common';
2
2
  import {fetchSkills} from './fetch-skills';
3
3
  import {postProgression} from './post-progression';
4
4
  import {fetchSlide} from './fetch-slide';
5
+ import {postAnswer} from './post-answer';
5
6
 
6
7
  export const getServices = (): Services => ({
7
8
  fetchSkills,
8
9
  fetchSlide,
9
- postProgression
10
+ postProgression,
11
+ postAnswer
10
12
  });
@@ -0,0 +1,27 @@
1
+ import crossFetch from 'cross-fetch';
2
+ import decode from 'jwt-decode';
3
+
4
+ import {JWT, ProgressionFromAPI} from '../types/common';
5
+ import {toJSON} from './tools/fetch-responses';
6
+
7
+ export const postAnswer = async (
8
+ skillRef: string,
9
+ token: string,
10
+ progressionId: string,
11
+ answer: string[]
12
+ ): Promise<ProgressionFromAPI> => {
13
+ const {host}: JWT = decode(token);
14
+ const response = await crossFetch(`${host}/api/v2/progressions/${progressionId}/answers`, {
15
+ method: 'post',
16
+ headers: {authorization: token},
17
+ body: JSON.stringify({
18
+ content: {
19
+ ref: skillRef,
20
+ type: 'slide'
21
+ },
22
+ answer
23
+ })
24
+ });
25
+
26
+ return toJSON<ProgressionFromAPI>(response);
27
+ };
@@ -0,0 +1,30 @@
1
+ import test from 'ava';
2
+ import nock from 'nock';
3
+ import {qcmDragSlide} from '../../views/slides/test/fixtures/qcm-drag';
4
+ import {fetchSlide} from '../fetch-slide';
5
+
6
+ test.before(() => {
7
+ nock('http://localhost:3000')
8
+ .get('/api/v2/slide/sli_123546/parentContentTitle')
9
+ .reply(200, qcmDragSlide);
10
+ });
11
+
12
+ test.after(() => {
13
+ nock.cleanAll();
14
+ });
15
+
16
+ test('should fetch a slide with the parentTitleContent info successfully', async t => {
17
+ const token = process.env.API_TEST_TOKEN || '';
18
+ const slide = await fetchSlide('sli_123546', token);
19
+ t.deepEqual(qcmDragSlide, slide);
20
+ });
21
+
22
+ test('should reject if a bad token is passed', async t => {
23
+ const badToken = 'token is not a jwt';
24
+ const error = await t.throwsAsync(() => fetchSlide('sli_123546', badToken));
25
+
26
+ t.is(
27
+ error?.message,
28
+ "Invalid token specified: Cannot read properties of undefined (reading 'replace')"
29
+ );
30
+ });
@@ -0,0 +1,68 @@
1
+ import test from 'ava';
2
+ import nock from 'nock';
3
+ import type {ProgressionFromAPI} from '../../types/common';
4
+ import {postAnswer} from '../post-answer';
5
+
6
+ const progressionId = '123456789123';
7
+ const skillRef = '_skill-ref';
8
+ const answer = ['Lister vos tâches pour vous libérer l’esprit', 'Vous isoler dans un lieu calme'];
9
+
10
+ const result: ProgressionFromAPI = {
11
+ content: {
12
+ type: 'skill',
13
+ ref: skillRef
14
+ },
15
+ engine: {
16
+ ref: 'review'
17
+ },
18
+ _id: '123456123456',
19
+ state: {
20
+ allAnswers: [
21
+ {
22
+ slideRef: 'sli_NkvrWPFF2',
23
+ isCorrect: true,
24
+ answer
25
+ }
26
+ ],
27
+ isCorrect: true,
28
+ nextContent: {
29
+ type: 'slide',
30
+ ref: 'sli_NJ3m5KtWh'
31
+ },
32
+ pendingSlides: [],
33
+ slides: ['sli_NkvrWPFF2'],
34
+ content: {
35
+ ref: 'sli_NkvrWPFF2',
36
+ type: 'slide'
37
+ },
38
+ step: {
39
+ current: 2
40
+ },
41
+ stars: 4
42
+ }
43
+ };
44
+
45
+ test.before(() => {
46
+ const moocApi = nock('http://localhost:3000');
47
+ moocApi.post(`/api/v2/progressions/${progressionId}/answers`).reply(200, result);
48
+ });
49
+
50
+ test.after(() => {
51
+ nock.cleanAll();
52
+ });
53
+
54
+ test('should post the answers successfully', async t => {
55
+ const token = process.env.API_TEST_TOKEN || '';
56
+ const progression = await postAnswer(skillRef, token, progressionId, answer);
57
+ t.deepEqual(result, progression);
58
+ });
59
+
60
+ test('should reject bad token', async t => {
61
+ const badToken = 'token is not a jwt';
62
+ const error = await t.throwsAsync(() => postAnswer(skillRef, badToken, progressionId, answer));
63
+
64
+ t.is(
65
+ error?.message,
66
+ "Invalid token specified: Cannot read properties of undefined (reading 'replace')"
67
+ );
68
+ });
@@ -6,6 +6,13 @@ import {postProgression} from '../post-progression';
6
6
  const skillRef = '_skill-ref';
7
7
  const result: ProgressionFromAPI = {
8
8
  _id: '123456123456',
9
+ content: {
10
+ ref: '_skill-ref',
11
+ type: 'skill'
12
+ },
13
+ engine: {
14
+ ref: 'review'
15
+ },
9
16
  state: {
10
17
  allAnswers: [],
11
18
  isCorrect: true,
@@ -17,7 +24,8 @@ const result: ProgressionFromAPI = {
17
24
  slides: [],
18
25
  step: {
19
26
  current: 1
20
- }
27
+ },
28
+ stars: 0
21
29
  }
22
30
  };
23
31
 
@@ -1,4 +1,4 @@
1
- import {qcmSlide} from '../../helpers/test/fixtures/qcm';
1
+ import {freeTextSlide} from '../../views/slides/test/fixtures/free-text';
2
2
  import {Services} from '../../types/common';
3
3
 
4
4
  export const services: Services = {
@@ -9,20 +9,17 @@ export const services: Services = {
9
9
  slidesToReview: 2,
10
10
  name: 'skill-test',
11
11
  custom: false
12
- // TODO parentContentTitle
13
12
  },
14
13
  {
15
14
  skillRef: '_skill-ref-2',
16
15
  slidesToReview: 2,
17
16
  name: 'skill-test-2',
18
- custom: true,
19
- parentContentTitle: 'parentContentTitle 2'
20
- // TODO parentContentTitle
17
+ custom: true
21
18
  }
22
19
  ]);
23
20
  },
24
21
  fetchSlide: ref => {
25
- return Promise.resolve({...qcmSlide, universalRef: ref, id: ref});
22
+ return Promise.resolve({...freeTextSlide, universalRef: ref, id: ref});
26
23
  },
27
24
  postProgression: () => {
28
25
  return Promise.resolve({
@@ -45,7 +42,40 @@ export const services: Services = {
45
42
  slides: [],
46
43
  step: {
47
44
  current: 1
48
- }
45
+ },
46
+ stars: 0
47
+ }
48
+ });
49
+ },
50
+ postAnswer: () => {
51
+ return Promise.resolve({
52
+ _id: '62b1d1087aa12f00253f40ee',
53
+ content: {
54
+ ref: '_skill-ref',
55
+ type: 'skill'
56
+ },
57
+ engine: {
58
+ ref: 'review'
59
+ },
60
+ state: {
61
+ allAnswers: [
62
+ {
63
+ slideRef: 'sli_N1XACJobn',
64
+ isCorrect: true,
65
+ answer: ['Le créateur peut fixer un pourcentage pour chaque transaction future']
66
+ }
67
+ ],
68
+ isCorrect: true,
69
+ nextContent: {
70
+ ref: 'sli_VkSQroQnx',
71
+ type: 'slide'
72
+ },
73
+ pendingSlides: [],
74
+ slides: ['sli_N1XACJobn'],
75
+ step: {
76
+ current: 2
77
+ },
78
+ stars: 4
49
79
  }
50
80
  });
51
81
  }
@@ -25,25 +25,25 @@ type BaseContent = {
25
25
  choices: ChoiceFromAPI[];
26
26
  };
27
27
 
28
- type Question = {
28
+ type BaseQuestion = {
29
29
  header?: string;
30
30
  content: BaseContent;
31
31
  explanation?: string;
32
32
  };
33
33
 
34
- export type QcmQuestion = Question & {
34
+ export type QcmQuestion = BaseQuestion & {
35
35
  type: 'qcm';
36
36
  };
37
37
 
38
- export type QcmGraphicQuestion = Question & {
38
+ export type QcmGraphicQuestion = BaseQuestion & {
39
39
  type: 'qcmGraphic';
40
40
  };
41
41
 
42
- export type QcmDragQuestion = Question & {
42
+ export type QcmDragQuestion = BaseQuestion & {
43
43
  type: 'qcmDrag';
44
44
  };
45
45
 
46
- export type BasicQuestion = Omit<Question, 'content'> & {
46
+ export type BasicQuestion = Omit<BaseQuestion, 'content'> & {
47
47
  type: 'basic';
48
48
  content: {
49
49
  media?: unknown;
@@ -53,7 +53,7 @@ export type BasicQuestion = Omit<Question, 'content'> & {
53
53
  };
54
54
  };
55
55
 
56
- export type SliderQuestion = Omit<Question, 'content'> & {
56
+ export type SliderQuestion = Omit<BaseQuestion, 'content'> & {
57
57
  content: {
58
58
  media?: unknown;
59
59
  unitLabel: string;
@@ -64,27 +64,33 @@ export type SliderQuestion = Omit<Question, 'content'> & {
64
64
  type: 'slider';
65
65
  };
66
66
 
67
- export type TemplateQuestion = Omit<Question, 'content'> & {
67
+ export type TemplateQuestion = Omit<BaseQuestion, 'content'> & {
68
68
  content: BaseContent & {
69
69
  template: string;
70
70
  };
71
71
  type: 'template';
72
72
  };
73
73
 
74
+ export type Question =
75
+ | QcmQuestion
76
+ | QcmGraphicQuestion
77
+ | QcmDragQuestion
78
+ | BasicQuestion
79
+ | SliderQuestion
80
+ | TemplateQuestion;
81
+
74
82
  export type SlideFromAPI = {
75
- question:
76
- | QcmQuestion
77
- | QcmGraphicQuestion
78
- | QcmDragQuestion
79
- | BasicQuestion
80
- | SliderQuestion
81
- | TemplateQuestion;
83
+ question: Question;
82
84
  klf: string;
83
85
  universalRef: string;
84
86
  tips?: string;
85
87
  clue?: string;
86
88
  hasClue?: boolean;
87
89
  id: string;
90
+ parentContentTitle: {
91
+ title: string;
92
+ type: 'chapter' | 'course';
93
+ };
88
94
  };
89
95
 
90
96
  type ProgressionAnswerItem = {
@@ -109,10 +115,18 @@ export type ProgressionState = {
109
115
  step: {
110
116
  current: number;
111
117
  };
118
+ stars: number;
112
119
  };
113
120
 
114
121
  export type ProgressionFromAPI = {
115
122
  _id: string;
123
+ content: {
124
+ type: 'skill';
125
+ ref: string;
126
+ };
127
+ engine: {
128
+ ref: 'review';
129
+ };
116
130
  state: ProgressionState;
117
131
  };
118
132
 
@@ -127,6 +141,12 @@ export type Services = {
127
141
  fetchSkills(token: string): Promise<Skill[]>;
128
142
  fetchSlide(slideRef: string, token: string): Promise<SlideFromAPI | void>;
129
143
  postProgression(skillRef: string, token: string): Promise<ProgressionFromAPI>;
144
+ postAnswer(
145
+ skillRef: string,
146
+ token: string,
147
+ progressionId: string,
148
+ answer: string[]
149
+ ): Promise<ProgressionFromAPI>;
130
150
  };
131
151
 
132
152
  export type Options = {