@coorpacademy/app-review 0.1.14 → 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 (295) 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 +27 -4
  5. package/es/actions/api/post-progression.d.ts +4 -6
  6. package/es/actions/api/post-progression.js +13 -9
  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.js +102 -0
  12. package/es/actions/index.d.ts +1 -10
  13. package/es/actions/ui/answers.d.ts +7 -0
  14. package/es/actions/ui/answers.js +7 -0
  15. package/es/actions/ui/is-fetching.js +0 -2
  16. package/es/actions/ui/slides.d.ts +26 -0
  17. package/es/actions/ui/slides.js +9 -0
  18. package/es/common/index.d.ts +3 -1
  19. package/es/common/index.js +3 -1
  20. package/es/fixtures/qcm-slide.d.ts +2 -2
  21. package/es/fixtures/temp-fixture.d.ts +2 -2
  22. package/es/index.js +22 -92
  23. package/es/reducers/data/index.d.ts +2 -2
  24. package/es/reducers/data/progression.d.ts +3 -16
  25. package/es/reducers/data/progression.js +3 -22
  26. package/es/reducers/data/slides.d.ts +5 -6
  27. package/es/reducers/data/slides.js +9 -108
  28. package/es/reducers/data/test/progression.test.js +38 -0
  29. package/es/reducers/data/test/skills.test.js +12 -0
  30. package/es/reducers/data/test/slides.test.js +20 -0
  31. package/es/reducers/data/test/token.test.js +11 -0
  32. package/es/reducers/index.d.ts +3 -4
  33. package/es/reducers/ui/answers.d.ts +4 -0
  34. package/es/reducers/ui/{review-status.js → answers.js} +3 -3
  35. package/es/reducers/ui/current-slide-ref.d.ts +4 -0
  36. package/es/reducers/ui/current-slide-ref.js +13 -0
  37. package/es/reducers/ui/index.d.ts +7 -10
  38. package/es/reducers/ui/index.js +4 -6
  39. package/es/reducers/ui/test/answers.test.js +11 -0
  40. package/es/reducers/ui/test/current-slide-ref.test.d.ts +1 -0
  41. package/es/reducers/ui/test/current-slide-ref.test.js +12 -0
  42. package/es/reducers/ui/test/navigation.test.d.ts +1 -0
  43. package/es/reducers/ui/test/navigation.test.js +15 -0
  44. package/es/services/fetch-slide.js +1 -1
  45. package/es/services/index.js +3 -1
  46. package/es/services/post-answer.d.ts +2 -0
  47. package/es/services/post-answer.js +18 -0
  48. package/es/services/test/fetch-slide.test.d.ts +1 -0
  49. package/es/services/test/fetch-slide.test.js +22 -0
  50. package/es/services/test/post-answer.test.d.ts +1 -0
  51. package/es/services/test/post-answer.test.js +57 -0
  52. package/es/services/test/post-progression.test.js +14 -4
  53. package/es/test/util/services.mock.js +46 -4
  54. package/es/types/common.d.ts +61 -30
  55. package/es/types/common.js +0 -5
  56. package/es/types/slides.d.ts +0 -4
  57. package/{lib/types/views/skills.d.ts → es/views/skills/index.d.ts} +2 -0
  58. package/es/views/skills/index.js +25 -0
  59. package/es/views/slides/index.d.ts +79 -0
  60. package/es/views/slides/index.js +151 -0
  61. package/es/views/slides/map-api-slide-to-ui.d.ts +8 -0
  62. package/es/views/slides/map-api-slide-to-ui.js +172 -0
  63. package/es/views/slides/test/fixtures/free-text.d.ts +3 -0
  64. package/es/views/slides/test/fixtures/free-text.js +38 -0
  65. package/es/views/slides/test/fixtures/qcm-drag.d.ts +3 -0
  66. package/es/views/slides/test/fixtures/qcm-drag.js +108 -0
  67. package/es/views/slides/test/fixtures/qcm-graphic.d.ts +3 -0
  68. package/es/views/slides/test/fixtures/qcm-graphic.js +88 -0
  69. package/es/views/slides/test/fixtures/qcm.d.ts +3 -0
  70. package/es/{helpers → views/slides}/test/fixtures/qcm.js +37 -27
  71. package/es/views/slides/test/fixtures/select-template.d.ts +3 -0
  72. package/es/views/slides/test/fixtures/select-template.js +92 -0
  73. package/es/views/slides/test/fixtures/slider.d.ts +3 -0
  74. package/es/views/slides/test/fixtures/slider.js +36 -0
  75. package/es/views/slides/test/fixtures/text-template.d.ts +3 -0
  76. package/es/{helpers → views/slides}/test/fixtures/text-template.js +21 -11
  77. package/es/views/slides/test/map-api-slide-to-ui.test.d.ts +1 -0
  78. package/es/{helpers → views/slides}/test/map-api-slide-to-ui.test.js +19 -9
  79. package/lib/actions/api/fetch-skills.d.ts +4 -6
  80. package/lib/actions/api/fetch-skills.js +55 -7
  81. package/lib/actions/api/fetch-slide.d.ts +14 -7
  82. package/lib/actions/api/fetch-slide.js +75 -7
  83. package/lib/actions/api/post-progression.d.ts +4 -6
  84. package/lib/actions/api/post-progression.js +63 -10
  85. package/lib/actions/api/test/create-test-store.d.ts +5 -0
  86. package/lib/actions/api/test/create-test-store.js +18 -0
  87. package/lib/actions/api/test/fetch-skills.test.d.ts +1 -0
  88. package/lib/actions/api/test/fetch-skills.test.js +113 -0
  89. package/lib/actions/api/test/fetch-slide.test.d.ts +1 -0
  90. package/lib/actions/api/test/fetch-slide.test.js +120 -0
  91. package/lib/actions/api/test/post-progression.test.d.ts +1 -0
  92. package/lib/actions/api/test/post-progression.test.js +160 -0
  93. package/lib/actions/index.d.ts +1 -10
  94. package/lib/actions/ui/answers.d.ts +7 -0
  95. package/lib/actions/ui/answers.js +9 -0
  96. package/lib/actions/ui/is-fetching.js +0 -2
  97. package/lib/actions/ui/slides.d.ts +26 -0
  98. package/lib/actions/ui/slides.js +9 -0
  99. package/lib/common/index.d.ts +3 -1
  100. package/lib/common/index.js +3 -1
  101. package/lib/fixtures/qcm-slide.d.ts +2 -2
  102. package/lib/fixtures/temp-fixture.d.ts +2 -2
  103. package/lib/index.js +33 -94
  104. package/lib/reducers/data/index.d.ts +2 -2
  105. package/lib/reducers/data/progression.d.ts +3 -16
  106. package/lib/reducers/data/progression.js +3 -22
  107. package/lib/reducers/data/slides.d.ts +5 -6
  108. package/lib/reducers/data/slides.js +9 -114
  109. package/lib/reducers/data/test/progression.test.d.ts +1 -0
  110. package/lib/reducers/data/test/progression.test.js +38 -0
  111. package/lib/reducers/data/test/skills.test.d.ts +1 -0
  112. package/lib/reducers/data/test/skills.test.js +12 -0
  113. package/lib/reducers/data/test/slides.test.d.ts +1 -0
  114. package/lib/reducers/data/test/slides.test.js +20 -0
  115. package/lib/reducers/data/test/token.test.d.ts +1 -0
  116. package/lib/reducers/data/test/token.test.js +11 -0
  117. package/lib/reducers/index.d.ts +3 -4
  118. package/lib/reducers/ui/answers.d.ts +4 -0
  119. package/lib/reducers/ui/{review-status.js → answers.js} +3 -3
  120. package/lib/reducers/ui/current-slide-ref.d.ts +4 -0
  121. package/lib/reducers/ui/current-slide-ref.js +14 -0
  122. package/lib/reducers/ui/index.d.ts +7 -10
  123. package/lib/reducers/ui/index.js +4 -6
  124. package/lib/reducers/ui/test/answers.test.d.ts +1 -0
  125. package/lib/reducers/ui/test/answers.test.js +11 -0
  126. package/lib/reducers/ui/test/current-slide-ref.test.d.ts +1 -0
  127. package/lib/reducers/ui/test/current-slide-ref.test.js +12 -0
  128. package/lib/reducers/ui/test/navigation.test.d.ts +1 -0
  129. package/lib/reducers/ui/test/navigation.test.js +15 -0
  130. package/lib/services/fetch-slide.js +1 -1
  131. package/lib/services/index.js +3 -1
  132. package/lib/services/post-answer.d.ts +2 -0
  133. package/lib/services/post-answer.js +62 -0
  134. package/lib/services/test/fetch-slide.test.d.ts +1 -0
  135. package/lib/services/test/fetch-slide.test.js +76 -0
  136. package/lib/services/test/post-answer.test.d.ts +1 -0
  137. package/lib/services/test/post-answer.test.js +111 -0
  138. package/lib/services/test/post-progression.test.js +14 -4
  139. package/lib/test/util/services.mock.js +46 -4
  140. package/lib/types/common.d.ts +61 -30
  141. package/lib/types/common.js +0 -5
  142. package/lib/types/slides.d.ts +0 -4
  143. package/{es/types/views/skills.d.ts → lib/views/skills/index.d.ts} +2 -0
  144. package/lib/views/skills/index.js +25 -0
  145. package/lib/views/slides/index.d.ts +79 -0
  146. package/lib/views/slides/index.js +155 -0
  147. package/lib/views/slides/map-api-slide-to-ui.d.ts +8 -0
  148. package/lib/views/slides/map-api-slide-to-ui.js +178 -0
  149. package/lib/views/slides/test/fixtures/free-text.d.ts +3 -0
  150. package/lib/views/slides/test/fixtures/free-text.js +38 -0
  151. package/lib/views/slides/test/fixtures/qcm-drag.d.ts +3 -0
  152. package/lib/views/slides/test/fixtures/qcm-drag.js +108 -0
  153. package/lib/views/slides/test/fixtures/qcm-graphic.d.ts +3 -0
  154. package/lib/views/slides/test/fixtures/qcm-graphic.js +88 -0
  155. package/lib/views/slides/test/fixtures/qcm.d.ts +3 -0
  156. package/lib/{helpers → views/slides}/test/fixtures/qcm.js +37 -27
  157. package/lib/views/slides/test/fixtures/select-template.d.ts +3 -0
  158. package/lib/views/slides/test/fixtures/select-template.js +92 -0
  159. package/lib/views/slides/test/fixtures/slider.d.ts +3 -0
  160. package/lib/views/slides/test/fixtures/slider.js +36 -0
  161. package/lib/views/slides/test/fixtures/text-template.d.ts +3 -0
  162. package/lib/{helpers → views/slides}/test/fixtures/text-template.js +21 -11
  163. package/lib/views/slides/test/map-api-slide-to-ui.test.d.ts +1 -0
  164. package/lib/{helpers → views/slides}/test/map-api-slide-to-ui.test.js +19 -9
  165. package/package.json +4 -3
  166. package/src/actions/api/fetch-skills.ts +12 -12
  167. package/src/actions/api/fetch-slide.ts +38 -13
  168. package/src/actions/api/post-progression.ts +18 -22
  169. package/src/actions/api/test/create-test-store.ts +25 -0
  170. package/src/actions/api/test/fetch-skills.test.ts +70 -0
  171. package/src/actions/api/test/fetch-slide.test.ts +77 -0
  172. package/src/actions/api/test/post-progression.test.ts +119 -0
  173. package/src/actions/index.ts +1 -10
  174. package/src/actions/ui/answers.ts +16 -0
  175. package/src/actions/ui/is-fetching.ts +0 -6
  176. package/src/actions/ui/slides.ts +35 -0
  177. package/src/common/index.ts +7 -1
  178. package/src/fixtures/qcm-slide.ts +2 -2
  179. package/src/fixtures/temp-fixture.ts +2 -2
  180. package/src/index.tsx +26 -110
  181. package/src/reducers/data/index.ts +1 -1
  182. package/src/reducers/data/progression.ts +5 -40
  183. package/src/reducers/data/slides.ts +17 -125
  184. package/src/reducers/data/test/progression.test.ts +42 -0
  185. package/src/reducers/data/test/skills.test.ts +14 -0
  186. package/src/reducers/data/test/slides.test.ts +26 -0
  187. package/src/reducers/data/test/token.test.ts +13 -0
  188. package/src/reducers/ui/answers.ts +19 -0
  189. package/src/reducers/ui/current-slide-ref.ts +19 -0
  190. package/src/reducers/ui/index.ts +6 -9
  191. package/src/reducers/ui/test/answers.test.ts +13 -0
  192. package/src/reducers/ui/test/current-slide-ref.test.ts +14 -0
  193. package/src/reducers/ui/test/navigation.test.ts +19 -0
  194. package/src/services/fetch-slide.ts +1 -1
  195. package/src/services/index.ts +3 -1
  196. package/src/services/post-answer.ts +27 -0
  197. package/src/services/test/fetch-slide.test.ts +30 -0
  198. package/src/services/test/post-answer.test.ts +68 -0
  199. package/src/services/test/post-progression.test.ts +14 -4
  200. package/src/test/util/services.mock.ts +46 -4
  201. package/src/types/common.ts +77 -40
  202. package/src/types/slides.ts +0 -5
  203. package/src/views/skills/index.ts +56 -0
  204. package/src/views/slides/index.ts +251 -0
  205. package/src/views/slides/map-api-slide-to-ui.ts +251 -0
  206. package/src/views/slides/test/fixtures/free-text.ts +43 -0
  207. package/src/views/slides/test/fixtures/qcm-drag.ts +111 -0
  208. package/src/views/slides/test/fixtures/qcm-graphic.ts +94 -0
  209. package/src/{helpers → views/slides}/test/fixtures/qcm.ts +43 -33
  210. package/src/views/slides/test/fixtures/select-template.ts +98 -0
  211. package/src/views/slides/test/fixtures/slider.ts +41 -0
  212. package/src/{helpers → views/slides}/test/fixtures/text-template.ts +23 -14
  213. package/src/{helpers → views/slides}/test/map-api-slide-to-ui.test.ts +22 -20
  214. package/es/actions/data/slides.d.ts +0 -37
  215. package/es/actions/data/slides.js +0 -16
  216. package/es/actions/ui/finished-slides.d.ts +0 -10
  217. package/es/actions/ui/finished-slides.js +0 -8
  218. package/es/actions/ui/review-status.d.ts +0 -7
  219. package/es/actions/ui/review-status.js +0 -7
  220. package/es/actions/ui/step-items.d.ts +0 -24
  221. package/es/actions/ui/step-items.js +0 -11
  222. package/es/helpers/map-api-slide-to-ui.d.ts +0 -8
  223. package/es/helpers/map-api-slide-to-ui.js +0 -175
  224. package/es/helpers/test/fixtures/free-text.d.ts +0 -4
  225. package/es/helpers/test/fixtures/free-text.js +0 -24
  226. package/es/helpers/test/fixtures/qcm-drag.d.ts +0 -4
  227. package/es/helpers/test/fixtures/qcm-drag.js +0 -106
  228. package/es/helpers/test/fixtures/qcm-graphic.d.ts +0 -4
  229. package/es/helpers/test/fixtures/qcm-graphic.js +0 -70
  230. package/es/helpers/test/fixtures/qcm.d.ts +0 -4
  231. package/es/helpers/test/fixtures/select-template.d.ts +0 -4
  232. package/es/helpers/test/fixtures/select-template.js +0 -88
  233. package/es/helpers/test/fixtures/slider.d.ts +0 -4
  234. package/es/helpers/test/fixtures/slider.js +0 -27
  235. package/es/helpers/test/fixtures/text-template.d.ts +0 -4
  236. package/es/reducers/ui/finished-slides.d.ts +0 -7
  237. package/es/reducers/ui/finished-slides.js +0 -33
  238. package/es/reducers/ui/review-status.d.ts +0 -4
  239. package/es/reducers/ui/step-items.d.ts +0 -14
  240. package/es/reducers/ui/step-items.js +0 -74
  241. package/es/types/ui-progression.d.ts +0 -10
  242. package/es/types/views/slides.d.ts +0 -60
  243. package/lib/actions/data/slides.d.ts +0 -37
  244. package/lib/actions/data/slides.js +0 -16
  245. package/lib/actions/ui/finished-slides.d.ts +0 -10
  246. package/lib/actions/ui/finished-slides.js +0 -8
  247. package/lib/actions/ui/review-status.d.ts +0 -7
  248. package/lib/actions/ui/review-status.js +0 -7
  249. package/lib/actions/ui/step-items.d.ts +0 -24
  250. package/lib/actions/ui/step-items.js +0 -11
  251. package/lib/helpers/map-api-slide-to-ui.d.ts +0 -8
  252. package/lib/helpers/map-api-slide-to-ui.js +0 -181
  253. package/lib/helpers/test/fixtures/free-text.d.ts +0 -4
  254. package/lib/helpers/test/fixtures/free-text.js +0 -24
  255. package/lib/helpers/test/fixtures/qcm-drag.d.ts +0 -4
  256. package/lib/helpers/test/fixtures/qcm-drag.js +0 -106
  257. package/lib/helpers/test/fixtures/qcm-graphic.d.ts +0 -4
  258. package/lib/helpers/test/fixtures/qcm-graphic.js +0 -70
  259. package/lib/helpers/test/fixtures/qcm.d.ts +0 -4
  260. package/lib/helpers/test/fixtures/select-template.d.ts +0 -4
  261. package/lib/helpers/test/fixtures/select-template.js +0 -88
  262. package/lib/helpers/test/fixtures/slider.d.ts +0 -4
  263. package/lib/helpers/test/fixtures/slider.js +0 -27
  264. package/lib/helpers/test/fixtures/text-template.d.ts +0 -4
  265. package/lib/reducers/ui/finished-slides.d.ts +0 -7
  266. package/lib/reducers/ui/finished-slides.js +0 -45
  267. package/lib/reducers/ui/review-status.d.ts +0 -4
  268. package/lib/reducers/ui/step-items.d.ts +0 -14
  269. package/lib/reducers/ui/step-items.js +0 -86
  270. package/lib/types/ui-progression.d.ts +0 -10
  271. package/lib/types/views/slides.d.ts +0 -60
  272. package/src/actions/data/slides.ts +0 -65
  273. package/src/actions/ui/finished-slides.ts +0 -21
  274. package/src/actions/ui/review-status.ts +0 -19
  275. package/src/actions/ui/step-items.ts +0 -45
  276. package/src/helpers/map-api-slide-to-ui.ts +0 -253
  277. package/src/helpers/test/fixtures/free-text.ts +0 -28
  278. package/src/helpers/test/fixtures/qcm-drag.ts +0 -110
  279. package/src/helpers/test/fixtures/qcm-graphic.ts +0 -74
  280. package/src/helpers/test/fixtures/select-template.ts +0 -92
  281. package/src/helpers/test/fixtures/slider.ts +0 -31
  282. package/src/reducers/ui/finished-slides.ts +0 -52
  283. package/src/reducers/ui/review-status.ts +0 -19
  284. package/src/reducers/ui/step-items.ts +0 -116
  285. package/src/types/ui-progression.ts +0 -25
  286. package/src/types/views/skills.ts +0 -27
  287. package/src/types/views/slides.ts +0 -65
  288. /package/es/{helpers/test/map-api-slide-to-ui.test.d.ts → actions/api/test/fetch-skills.test.d.ts} +0 -0
  289. /package/es/{types/ui-progression.js → actions/api/test/fetch-slide.test.d.ts} +0 -0
  290. /package/es/{types/views/skills.js → actions/api/test/post-progression.test.d.ts} +0 -0
  291. /package/es/{types/views/slides.js → reducers/data/test/progression.test.d.ts} +0 -0
  292. /package/{lib/helpers/test/map-api-slide-to-ui.test.d.ts → es/reducers/data/test/skills.test.d.ts} +0 -0
  293. /package/{lib/types/ui-progression.js → es/reducers/data/test/slides.test.d.ts} +0 -0
  294. /package/{lib/types/views/skills.js → es/reducers/data/test/token.test.d.ts} +0 -0
  295. /package/{lib/types/views/slides.js → es/reducers/ui/test/answers.test.d.ts} +0 -0
@@ -0,0 +1,2 @@
1
+ import { ProgressionFromAPI } from '../types/common';
2
+ export declare const postAnswer: (skillRef: string, token: string, progressionId: string, answer: string[]) => Promise<ProgressionFromAPI>;
@@ -0,0 +1,18 @@
1
+ import crossFetch from 'cross-fetch';
2
+ import decode from 'jwt-decode';
3
+ import { toJSON } from './tools/fetch-responses';
4
+ export const postAnswer = async (skillRef, token, progressionId, answer) => {
5
+ const { host } = decode(token);
6
+ const response = await crossFetch(`${host}/api/v2/progressions/${progressionId}/answers`, {
7
+ method: 'post',
8
+ headers: { authorization: token },
9
+ body: JSON.stringify({
10
+ content: {
11
+ ref: skillRef,
12
+ type: 'slide'
13
+ },
14
+ answer
15
+ })
16
+ });
17
+ return toJSON(response);
18
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,22 @@
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
+ test.before(() => {
6
+ nock('http://localhost:3000')
7
+ .get('/api/v2/slide/sli_123546/parentContentTitle')
8
+ .reply(200, qcmDragSlide);
9
+ });
10
+ test.after(() => {
11
+ nock.cleanAll();
12
+ });
13
+ test('should fetch a slide with the parentTitleContent info successfully', async (t) => {
14
+ const token = process.env.API_TEST_TOKEN || '';
15
+ const slide = await fetchSlide('sli_123546', token);
16
+ t.deepEqual(qcmDragSlide, slide);
17
+ });
18
+ test('should reject if a bad token is passed', async (t) => {
19
+ const badToken = 'token is not a jwt';
20
+ const error = await t.throwsAsync(() => fetchSlide('sli_123546', badToken));
21
+ t.is(error?.message, "Invalid token specified: Cannot read properties of undefined (reading 'replace')");
22
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,57 @@
1
+ import test from 'ava';
2
+ import nock from 'nock';
3
+ import { postAnswer } from '../post-answer';
4
+ const progressionId = '123456789123';
5
+ const skillRef = '_skill-ref';
6
+ const answer = ['Lister vos tâches pour vous libérer l’esprit', 'Vous isoler dans un lieu calme'];
7
+ const result = {
8
+ content: {
9
+ type: 'skill',
10
+ ref: skillRef
11
+ },
12
+ engine: {
13
+ ref: 'review'
14
+ },
15
+ _id: '123456123456',
16
+ state: {
17
+ allAnswers: [
18
+ {
19
+ slideRef: 'sli_NkvrWPFF2',
20
+ isCorrect: true,
21
+ answer
22
+ }
23
+ ],
24
+ isCorrect: true,
25
+ nextContent: {
26
+ type: 'slide',
27
+ ref: 'sli_NJ3m5KtWh'
28
+ },
29
+ pendingSlides: [],
30
+ slides: ['sli_NkvrWPFF2'],
31
+ content: {
32
+ ref: 'sli_NkvrWPFF2',
33
+ type: 'slide'
34
+ },
35
+ step: {
36
+ current: 2
37
+ },
38
+ stars: 4
39
+ }
40
+ };
41
+ test.before(() => {
42
+ const moocApi = nock('http://localhost:3000');
43
+ moocApi.post(`/api/v2/progressions/${progressionId}/answers`).reply(200, result);
44
+ });
45
+ test.after(() => {
46
+ nock.cleanAll();
47
+ });
48
+ test('should post the answers successfully', async (t) => {
49
+ const token = process.env.API_TEST_TOKEN || '';
50
+ const progression = await postAnswer(skillRef, token, progressionId, answer);
51
+ t.deepEqual(result, progression);
52
+ });
53
+ test('should reject bad token', async (t) => {
54
+ const badToken = 'token is not a jwt';
55
+ const error = await t.throwsAsync(() => postAnswer(skillRef, badToken, progressionId, answer));
56
+ t.is(error?.message, "Invalid token specified: Cannot read properties of undefined (reading 'replace')");
57
+ });
@@ -4,16 +4,26 @@ import { postProgression } from '../post-progression';
4
4
  const skillRef = '_skill-ref';
5
5
  const result = {
6
6
  _id: '123456123456',
7
+ content: {
8
+ ref: '_skill-ref',
9
+ type: 'skill'
10
+ },
11
+ engine: {
12
+ ref: 'review'
13
+ },
7
14
  state: {
15
+ allAnswers: [],
8
16
  isCorrect: true,
9
- step: {
10
- current: 1
11
- },
12
17
  nextContent: {
13
18
  type: 'slide',
14
19
  ref: 'sli_NJ3m5KtWh'
15
20
  },
16
- pendingSlides: []
21
+ pendingSlides: [],
22
+ slides: [],
23
+ step: {
24
+ current: 1
25
+ },
26
+ stars: 0
17
27
  }
18
28
  };
19
29
  test.before(() => {
@@ -1,4 +1,4 @@
1
- import { qcmSlide } from '../../helpers/test/fixtures/qcm';
1
+ import { freeTextSlide } from '../../views/slides/test/fixtures/free-text';
2
2
  export const services = {
3
3
  fetchSkills: () => {
4
4
  return Promise.resolve([
@@ -17,21 +17,63 @@ export const services = {
17
17
  ]);
18
18
  },
19
19
  fetchSlide: ref => {
20
- return Promise.resolve({ ...qcmSlide, universalRef: ref, id: ref });
20
+ return Promise.resolve({ ...freeTextSlide, universalRef: ref, id: ref });
21
21
  },
22
22
  postProgression: () => {
23
23
  return Promise.resolve({
24
24
  _id: '62b1d1087aa12f00253f40ee',
25
+ content: {
26
+ ref: '_skill-ref',
27
+ type: 'skill'
28
+ },
29
+ engine: {
30
+ ref: 'review'
31
+ },
25
32
  state: {
33
+ allAnswers: [],
34
+ isCorrect: true,
35
+ nextContent: {
36
+ ref: 'sli_N1XACJobn',
37
+ type: 'slide'
38
+ },
26
39
  pendingSlides: [],
40
+ slides: [],
27
41
  step: {
28
42
  current: 1
29
43
  },
44
+ stars: 0
45
+ }
46
+ });
47
+ },
48
+ postAnswer: () => {
49
+ return Promise.resolve({
50
+ _id: '62b1d1087aa12f00253f40ee',
51
+ content: {
52
+ ref: '_skill-ref',
53
+ type: 'skill'
54
+ },
55
+ engine: {
56
+ ref: 'review'
57
+ },
58
+ state: {
59
+ allAnswers: [
60
+ {
61
+ slideRef: 'sli_N1XACJobn',
62
+ isCorrect: true,
63
+ answer: ['Le créateur peut fixer un pourcentage pour chaque transaction future']
64
+ }
65
+ ],
30
66
  isCorrect: true,
31
67
  nextContent: {
32
- ref: 'sli_N1XACJobn',
68
+ ref: 'sli_VkSQroQnx',
33
69
  type: 'slide'
34
- }
70
+ },
71
+ pendingSlides: [],
72
+ slides: ['sli_N1XACJobn'],
73
+ step: {
74
+ current: 2
75
+ },
76
+ stars: 4
35
77
  }
36
78
  });
37
79
  }
@@ -1,4 +1,5 @@
1
- import { UISlide } from './slides';
1
+ import { SlideIndexes } from '../common';
2
+ import { AnswerUI } from './slides';
2
3
  declare type TemplateContextValues = {
3
4
  brandTheme?: unknown;
4
5
  theme?: unknown;
@@ -22,21 +23,21 @@ declare type BaseContent = {
22
23
  media?: unknown;
23
24
  choices: ChoiceFromAPI[];
24
25
  };
25
- declare type Question = {
26
+ declare type BaseQuestion = {
26
27
  header?: string;
27
28
  content: BaseContent;
28
29
  explanation?: string;
29
30
  };
30
- export declare type QcmQuestion = Question & {
31
+ export declare type QcmQuestion = BaseQuestion & {
31
32
  type: 'qcm';
32
33
  };
33
- export declare type QcmGraphicQuestion = Question & {
34
+ export declare type QcmGraphicQuestion = BaseQuestion & {
34
35
  type: 'qcmGraphic';
35
36
  };
36
- export declare type QcmDragQuestion = Question & {
37
+ export declare type QcmDragQuestion = BaseQuestion & {
37
38
  type: 'qcmDrag';
38
39
  };
39
- export declare type BasicQuestion = Omit<Question, 'content'> & {
40
+ export declare type BasicQuestion = Omit<BaseQuestion, 'content'> & {
40
41
  type: 'basic';
41
42
  content: {
42
43
  media?: unknown;
@@ -45,7 +46,7 @@ export declare type BasicQuestion = Omit<Question, 'content'> & {
45
46
  id: string;
46
47
  };
47
48
  };
48
- export declare type SliderQuestion = Omit<Question, 'content'> & {
49
+ export declare type SliderQuestion = Omit<BaseQuestion, 'content'> & {
49
50
  content: {
50
51
  media?: unknown;
51
52
  unitLabel: string;
@@ -55,34 +56,59 @@ export declare type SliderQuestion = Omit<Question, 'content'> & {
55
56
  };
56
57
  type: 'slider';
57
58
  };
58
- export declare type TemplateQuestion = Omit<Question, 'content'> & {
59
+ export declare type TemplateQuestion = Omit<BaseQuestion, 'content'> & {
59
60
  content: BaseContent & {
60
61
  template: string;
61
62
  };
62
63
  type: 'template';
63
64
  };
65
+ export declare type Question = QcmQuestion | QcmGraphicQuestion | QcmDragQuestion | BasicQuestion | SliderQuestion | TemplateQuestion;
64
66
  export declare type SlideFromAPI = {
65
- question: QcmQuestion | QcmGraphicQuestion | QcmDragQuestion | BasicQuestion | SliderQuestion | TemplateQuestion;
67
+ question: Question;
66
68
  klf: string;
67
69
  universalRef: string;
68
70
  tips?: string;
69
71
  clue?: string;
70
72
  hasClue?: boolean;
71
- id?: string;
73
+ id: string;
74
+ parentContentTitle: {
75
+ title: string;
76
+ type: 'chapter' | 'course';
77
+ };
78
+ };
79
+ declare type ProgressionAnswerItem = {
80
+ isCorrect: boolean;
81
+ slideRef: string;
82
+ answer: string[];
83
+ };
84
+ export declare type ProgressionState = {
85
+ allAnswers: ProgressionAnswerItem[];
86
+ content?: {
87
+ ref: string;
88
+ type: string;
89
+ };
90
+ isCorrect: boolean;
91
+ nextContent: {
92
+ type: 'success' | 'slide';
93
+ ref: 'successExitNode' | string;
94
+ };
95
+ pendingSlides: string[];
96
+ slides: string[];
97
+ step: {
98
+ current: number;
99
+ };
100
+ stars: number;
72
101
  };
73
102
  export declare type ProgressionFromAPI = {
74
103
  _id: string;
75
- state: {
76
- isCorrect: boolean;
77
- step: {
78
- current: number;
79
- };
80
- nextContent: {
81
- type: 'success' | 'slide';
82
- ref: 'successExitNode' | string;
83
- };
84
- pendingSlides: [];
104
+ content: {
105
+ type: 'skill';
106
+ ref: string;
85
107
  };
108
+ engine: {
109
+ ref: 'review';
110
+ };
111
+ state: ProgressionState;
86
112
  };
87
113
  export declare type Skill = {
88
114
  skillRef: string;
@@ -94,6 +120,7 @@ export declare type Services = {
94
120
  fetchSkills(token: string): Promise<Skill[]>;
95
121
  fetchSlide(slideRef: string, token: string): Promise<SlideFromAPI | void>;
96
122
  postProgression(skillRef: string, token: string): Promise<ProgressionFromAPI>;
123
+ postAnswer(skillRef: string, token: string, progressionId: string, answer: string[]): Promise<ProgressionFromAPI>;
97
124
  };
98
125
  export declare type Options = {
99
126
  services: Services;
@@ -116,23 +143,27 @@ export declare type JWT = {
116
143
  host: string;
117
144
  };
118
145
  declare type SlideUIAnimations = 'unstack' | 'restack';
119
- export declare type Slide = UISlide & {
146
+ export declare type NextUISlide = {
147
+ questionText?: string;
148
+ answerUI?: AnswerUI;
120
149
  hidden?: boolean;
121
- position: number;
150
+ position?: number;
122
151
  animationType?: SlideUIAnimations;
123
152
  isCorrect?: boolean;
124
153
  endReview?: boolean;
125
- nextContent?: Omit<Slide, 'endReview' | 'hidden' | 'position' | 'nextContent'>;
126
154
  };
127
- declare const ICON_VALUES: {
128
- readonly right: "right";
129
- readonly wrong: "wrong";
130
- readonly 'no-answer': "no-answer";
155
+ export declare type UISlide = {
156
+ questionText?: string;
157
+ answerUI?: AnswerUI;
158
+ hidden?: boolean;
159
+ position: number;
160
+ animationType?: SlideUIAnimations;
161
+ isCorrect?: boolean;
162
+ endReview?: boolean;
163
+ nextContent?: NextUISlide;
131
164
  };
132
- export declare type IconValue = keyof typeof ICON_VALUES;
133
165
  export declare type FinishedSlides = {
134
- slideNumbers: number[];
135
- [key: number]: true;
166
+ [key in SlideIndexes]?: true;
136
167
  };
137
168
  export declare type WithRequired<T, K extends keyof T> = T & {
138
169
  [P in K]-?: T[P];
@@ -1,6 +1 @@
1
- const ICON_VALUES = {
2
- right: 'right',
3
- wrong: 'wrong',
4
- 'no-answer': 'no-answer'
5
- };
6
1
  export {};
@@ -74,7 +74,3 @@ export declare type AnswerUI = {
74
74
  help: string;
75
75
  };
76
76
  export declare type SlideUIAnimations = 'unstack' | 'restack';
77
- export declare type UISlide = {
78
- questionText?: string;
79
- answerUI?: AnswerUI;
80
- };
@@ -1,3 +1,4 @@
1
+ import { StoreState } from '../../reducers';
1
2
  declare type SkillCard = {
2
3
  'aria-label': string;
3
4
  skillTitle: string;
@@ -22,3 +23,4 @@ declare type SkillsProps = NoSkillsProps & {
22
23
  listSkills: SkillCard[];
23
24
  };
24
25
  export { SkillsProps };
26
+ export declare const mapStateToSkillsProps: (state: StoreState) => SkillsProps | null;
@@ -0,0 +1,25 @@
1
+ export const mapStateToSkillsProps = (state) => {
2
+ if (!state.data.skills) {
3
+ return null;
4
+ }
5
+ return {
6
+ title: '@todo title',
7
+ titleNoSkills: '@todo titleNoSkills',
8
+ textNoSkills: '@todo textNoSkills',
9
+ iconSkillAriaLabel: '@todo iconSkillAriaLabel',
10
+ isLoading: false,
11
+ isLoadingAriaLabel: '@todo loading',
12
+ listSkills: state.data.skills.map(skill => ({
13
+ 'aria-label': '',
14
+ isCustom: skill.custom,
15
+ skillTitle: skill.name,
16
+ skillAriaLabel: '@todo skill aria label',
17
+ buttonLabel: '@todo button',
18
+ buttonAriaLabel: '@todo button aria label',
19
+ reviseLabel: '@todo revise',
20
+ reviseAriaLabel: '@todo revise aria label',
21
+ // eslint-disable-next-line no-console
22
+ onClick: () => console.log('@todo plug dispatcher select skill')
23
+ }))
24
+ };
25
+ };
@@ -0,0 +1,79 @@
1
+ import { Dispatch } from 'redux';
2
+ import { UISlide } from '../../types/common';
3
+ import { SlideIndexes } from '../../common';
4
+ import { StoreState } from '../../reducers';
5
+ declare const ICON_VALUES: {
6
+ readonly right: "right";
7
+ readonly wrong: "wrong";
8
+ readonly 'no-answer': "no-answer";
9
+ };
10
+ declare type IconValue = keyof typeof ICON_VALUES;
11
+ declare type StepItem = {
12
+ current: boolean;
13
+ icon: IconValue;
14
+ value: string;
15
+ };
16
+ declare type SlidesStack = {
17
+ [key in SlideIndexes]: UISlide;
18
+ };
19
+ export declare type CorrectionPopinProps = {
20
+ klf: {
21
+ label: string;
22
+ onClick: Function;
23
+ tooltip: string;
24
+ };
25
+ information: {
26
+ label: string;
27
+ message: string;
28
+ };
29
+ next: {
30
+ label: string;
31
+ ariaLabel: string;
32
+ };
33
+ successLabel: string;
34
+ failureLabel: string;
35
+ };
36
+ export declare type SlidesViewProps = {
37
+ header: {
38
+ mode: string;
39
+ skillName: string;
40
+ onQuitClick: Function;
41
+ 'aria-label'?: string;
42
+ closeButtonAriaLabel: string;
43
+ steps: StepItem[];
44
+ };
45
+ stack: {
46
+ slides: SlidesStack;
47
+ validateButton: {
48
+ label: string;
49
+ disabled: boolean;
50
+ onClick: Function;
51
+ };
52
+ correctionPopinProps?: CorrectionPopinProps;
53
+ endReview: boolean;
54
+ };
55
+ reviewBackgroundAriaLabel?: string;
56
+ congratsProps?: {
57
+ 'aria-label'?: string;
58
+ 'data-name'?: string;
59
+ animationLottie: unknown;
60
+ title: string;
61
+ cardCongratsStar: unknown;
62
+ cardCongratsRank: unknown;
63
+ buttonRevising: {
64
+ 'aria-label'?: string;
65
+ label: string;
66
+ onClick: Function;
67
+ type: string;
68
+ };
69
+ buttonRevisingSkill: {
70
+ 'aria-label'?: string;
71
+ label: string;
72
+ onClick: Function;
73
+ type: string;
74
+ };
75
+ };
76
+ };
77
+ export declare const initialState: SlidesStack;
78
+ export declare const mapStateToSlidesProps: (state: StoreState, dispatch: Dispatch) => SlidesViewProps | null;
79
+ export {};
@@ -0,0 +1,151 @@
1
+ import concat from 'lodash/fp/concat';
2
+ import get from 'lodash/fp/get';
3
+ import getOr from 'lodash/fp/getOr';
4
+ import isEmpty from 'lodash/fp/isEmpty';
5
+ import pipe from 'lodash/fp/pipe';
6
+ import reduce from 'lodash/fp/reduce';
7
+ import set from 'lodash/fp/set';
8
+ import slice from 'lodash/fp/slice';
9
+ import toInteger from 'lodash/fp/toInteger';
10
+ import { mapApiSlideToUi } from './map-api-slide-to-ui';
11
+ const ICON_VALUES = {
12
+ right: 'right',
13
+ wrong: 'wrong',
14
+ 'no-answer': 'no-answer'
15
+ };
16
+ export const initialState = {
17
+ '0': {
18
+ hidden: false,
19
+ position: 0
20
+ },
21
+ '1': {
22
+ hidden: false,
23
+ position: 1
24
+ },
25
+ '2': {
26
+ hidden: false,
27
+ position: 2
28
+ },
29
+ '3': {
30
+ hidden: false,
31
+ position: 3
32
+ },
33
+ '4': {
34
+ hidden: false,
35
+ position: 4
36
+ }
37
+ };
38
+ const getProgressionSlidesRef = (progression) => {
39
+ if (progression.state.step.current < 5) {
40
+ const slideRef = progression.state.nextContent.ref;
41
+ return concat([slideRef], progression.state.slides);
42
+ }
43
+ return slice(0, 5, progression.state.slides);
44
+ };
45
+ const buildStackSlides = (state, dispatch) => {
46
+ const currentSlideRef = state.ui.currentSlideRef;
47
+ const progression = state.data.progression;
48
+ if (!currentSlideRef || !progression)
49
+ return initialState;
50
+ const slideRefs = getProgressionSlidesRef(progression);
51
+ // @ts-expect-error typescript does not support capped versions of lodash functions
52
+ const stack = reduce.convert({ cap: false })((acc, uiSlide, index) => {
53
+ const slideRef = slideRefs[toInteger(index)];
54
+ if (!slideRef)
55
+ return set(index, uiSlide, acc);
56
+ const slideFromAPI = get(slideRef, state.data.slides);
57
+ const answers = state.ui.answers;
58
+ const { questionText, answerUI } = mapApiSlideToUi(dispatch)(slideFromAPI, answers);
59
+ const parentContentTitle = getOr('', 'parentContentTitle.title', slideFromAPI);
60
+ const parentContentType = getOr('', 'parentContentTitle.type', slideFromAPI);
61
+ const updatedUiSlide = pipe(set(['questionText'], questionText), set(['answerUI'], answerUI), set(['parentContentTitle'], `From "${parentContentTitle}" ${parentContentType}`) // TODO translate: -From- .... -Course/chapter-
62
+ // TODO: Set position according to currentSlideRef et slideRefs (or maybe a value on the state ui.slidePositions !!)
63
+ )(uiSlide);
64
+ return set(index, updatedUiSlide, acc);
65
+ }, initialState, initialState);
66
+ return stack;
67
+ };
68
+ const buildStepItems = (state) => {
69
+ const { progression } = state.data;
70
+ const { currentSlideRef } = state.ui;
71
+ if (!progression)
72
+ return [];
73
+ const defaultProps = [
74
+ {
75
+ icon: 'no-answer',
76
+ current: true,
77
+ value: '1'
78
+ },
79
+ {
80
+ icon: 'no-answer',
81
+ current: false,
82
+ value: '2'
83
+ },
84
+ {
85
+ icon: 'no-answer',
86
+ current: false,
87
+ value: '3'
88
+ },
89
+ {
90
+ icon: 'no-answer',
91
+ current: false,
92
+ value: '4'
93
+ },
94
+ {
95
+ icon: 'no-answer',
96
+ current: false,
97
+ value: '5'
98
+ }
99
+ ];
100
+ const allAnswers = progression.state.allAnswers;
101
+ const step = progression.state.step;
102
+ if (isEmpty(allAnswers))
103
+ return defaultProps;
104
+ const steps = defaultProps.map((stepItem, index) => {
105
+ const givenAnswer = allAnswers[index];
106
+ if (!givenAnswer) {
107
+ return {
108
+ ...stepItem,
109
+ current: step.current === index + 1
110
+ };
111
+ }
112
+ return {
113
+ ...stepItem,
114
+ icon: givenAnswer.isCorrect ? 'right' : 'wrong',
115
+ current: givenAnswer.slideRef === currentSlideRef
116
+ };
117
+ });
118
+ return steps;
119
+ };
120
+ export const mapStateToSlidesProps = (state, dispatch) => {
121
+ if (!state.data.slides) {
122
+ return null;
123
+ }
124
+ return {
125
+ header: {
126
+ mode: '__revision_mode',
127
+ skillName: '__agility',
128
+ onQuitClick: () => {
129
+ // eslint-disable-next-line no-console
130
+ console.log('onQuitClick');
131
+ },
132
+ 'aria-label': 'aria-header-wrapper',
133
+ closeButtonAriaLabel: 'aria-close-button',
134
+ steps: buildStepItems(state)
135
+ },
136
+ stack: {
137
+ slides: buildStackSlides(state, dispatch),
138
+ validateButton: {
139
+ label: '__validate',
140
+ disabled: true,
141
+ onClick: () => {
142
+ // eslint-disable-next-line no-console
143
+ console.log('TODO: validate question');
144
+ }
145
+ },
146
+ correctionPopinProps: undefined,
147
+ endReview: false
148
+ },
149
+ congratsProps: undefined
150
+ };
151
+ };
@@ -0,0 +1,8 @@
1
+ import { Dispatch } from 'redux';
2
+ import { AnswerUI } from '../../types/slides';
3
+ import { Question, SlideFromAPI } from '../../types/common';
4
+ export declare const getQuestionType: (question: Question) => Question['type'];
5
+ export declare const mapApiSlideToUi: (dispatch: Dispatch) => (slide: SlideFromAPI, answers: string[]) => {
6
+ questionText: string;
7
+ answerUI: AnswerUI;
8
+ };