@coorpacademy/app-review 0.1.7 → 0.1.9

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 (202) hide show
  1. package/es/actions/api/fetch-skills.d.ts +13 -0
  2. package/es/actions/api/fetch-skills.js +8 -0
  3. package/es/actions/api/fetch-slide.d.ts +13 -0
  4. package/es/actions/api/fetch-slide.js +8 -0
  5. package/es/actions/api/post-progression.d.ts +13 -0
  6. package/es/actions/api/post-progression.js +15 -0
  7. package/es/actions/data/slides.d.ts +3 -24
  8. package/es/actions/data/slides.js +0 -11
  9. package/es/actions/index.d.ts +5 -4
  10. package/es/actions/ui/navigation.d.ts +0 -1
  11. package/es/actions/ui/navigation.js +0 -4
  12. package/es/actions/ui/step-items.d.ts +2 -8
  13. package/es/actions/ui/step-items.js +0 -6
  14. package/es/configure-store.d.ts +3 -26
  15. package/es/configure-store.js +4 -5
  16. package/es/fixtures/qcm-slide.d.ts +2 -2
  17. package/es/index.d.ts +1 -1
  18. package/es/index.js +40 -26
  19. package/es/reducers/data/index.d.ts +16 -5
  20. package/es/reducers/data/progression.d.ts +1 -2
  21. package/es/reducers/data/progression.js +4 -7
  22. package/es/reducers/data/skills.d.ts +4 -5
  23. package/es/reducers/data/skills.js +3 -6
  24. package/es/reducers/data/slides.d.ts +2 -1
  25. package/es/reducers/data/slides.js +3 -3
  26. package/es/reducers/data/token.d.ts +0 -1
  27. package/es/reducers/data/token.js +1 -5
  28. package/es/reducers/index.d.ts +9 -3
  29. package/es/reducers/ui/finished-slides.d.ts +0 -1
  30. package/es/reducers/ui/finished-slides.js +1 -3
  31. package/es/reducers/ui/index.d.ts +14 -4
  32. package/es/reducers/ui/navigation.d.ts +0 -1
  33. package/es/reducers/ui/navigation.js +1 -3
  34. package/es/reducers/ui/review-status.d.ts +0 -1
  35. package/es/reducers/ui/review-status.js +1 -4
  36. package/es/reducers/ui/step-items.d.ts +5 -5
  37. package/es/reducers/ui/step-items.js +0 -1
  38. package/es/services/fetch-skills.d.ts +2 -8
  39. package/es/services/fetch-skills.js +2 -14
  40. package/es/services/fetch-slide.d.ts +2 -8
  41. package/es/services/fetch-slide.js +9 -24
  42. package/es/services/index.d.ts +2 -0
  43. package/es/services/index.js +8 -0
  44. package/es/services/post-progression.d.ts +2 -8
  45. package/es/services/post-progression.js +2 -14
  46. package/es/services/test/fetch-skills.test.js +29 -0
  47. package/es/services/test/post-progression.test.js +35 -0
  48. package/es/{index.test.js → test/index.test.js} +15 -4
  49. package/es/test/util/services.mock.d.ts +2 -0
  50. package/es/test/util/services.mock.js +68 -0
  51. package/es/types/common.d.ts +58 -0
  52. package/es/types/common.js +5 -0
  53. package/es/types/slides.d.ts +1 -1
  54. package/es/types/views/slides.d.ts +1 -1
  55. package/lib/actions/api/fetch-skills.d.ts +13 -0
  56. package/lib/actions/api/fetch-skills.js +13 -0
  57. package/lib/actions/api/fetch-slide.d.ts +13 -0
  58. package/lib/actions/api/fetch-slide.js +13 -0
  59. package/lib/actions/api/post-progression.d.ts +13 -0
  60. package/lib/actions/api/post-progression.js +18 -0
  61. package/lib/actions/data/slides.d.ts +3 -24
  62. package/lib/actions/data/slides.js +0 -11
  63. package/lib/actions/index.d.ts +5 -4
  64. package/lib/actions/ui/navigation.d.ts +0 -1
  65. package/lib/actions/ui/navigation.js +0 -4
  66. package/lib/actions/ui/step-items.d.ts +2 -8
  67. package/lib/actions/ui/step-items.js +0 -6
  68. package/lib/configure-store.d.ts +3 -26
  69. package/lib/configure-store.js +4 -5
  70. package/lib/fixtures/qcm-slide.d.ts +2 -2
  71. package/lib/index.d.ts +1 -1
  72. package/lib/index.js +40 -70
  73. package/lib/reducers/data/index.d.ts +16 -5
  74. package/lib/reducers/data/progression.d.ts +1 -2
  75. package/lib/reducers/data/progression.js +4 -7
  76. package/lib/reducers/data/skills.d.ts +4 -5
  77. package/lib/reducers/data/skills.js +3 -6
  78. package/lib/reducers/data/slides.d.ts +2 -1
  79. package/lib/reducers/data/slides.js +3 -3
  80. package/lib/reducers/data/token.d.ts +0 -1
  81. package/lib/reducers/data/token.js +1 -5
  82. package/lib/reducers/index.d.ts +9 -3
  83. package/lib/reducers/ui/finished-slides.d.ts +0 -1
  84. package/lib/reducers/ui/finished-slides.js +1 -3
  85. package/lib/reducers/ui/index.d.ts +14 -4
  86. package/lib/reducers/ui/navigation.d.ts +0 -1
  87. package/lib/reducers/ui/navigation.js +1 -3
  88. package/lib/reducers/ui/review-status.d.ts +0 -1
  89. package/lib/reducers/ui/review-status.js +1 -4
  90. package/lib/reducers/ui/step-items.d.ts +5 -5
  91. package/lib/reducers/ui/step-items.js +0 -1
  92. package/lib/services/fetch-skills.d.ts +2 -8
  93. package/lib/services/fetch-skills.js +3 -15
  94. package/lib/services/fetch-slide.d.ts +2 -8
  95. package/lib/services/fetch-slide.js +18 -25
  96. package/lib/services/index.d.ts +2 -0
  97. package/lib/services/index.js +8 -0
  98. package/lib/services/post-progression.d.ts +2 -8
  99. package/lib/services/post-progression.js +3 -15
  100. package/lib/services/{fetch-skills.test.js → test/fetch-skills.test.js} +23 -16
  101. package/lib/services/{post-progression.test.js → test/post-progression.test.js} +28 -23
  102. package/lib/{index.test.js → test/index.test.js} +20 -10
  103. package/lib/test/util/services.mock.d.ts +2 -0
  104. package/lib/test/util/services.mock.js +68 -0
  105. package/lib/types/common.d.ts +58 -0
  106. package/lib/types/common.js +5 -0
  107. package/lib/types/slides.d.ts +1 -1
  108. package/lib/types/views/slides.d.ts +1 -1
  109. package/package.json +5 -4
  110. package/src/actions/api/fetch-skills.ts +24 -0
  111. package/src/actions/api/fetch-slide.ts +24 -0
  112. package/src/actions/api/post-progression.ts +36 -0
  113. package/src/actions/data/slides.ts +3 -35
  114. package/src/actions/index.ts +5 -11
  115. package/src/actions/ui/navigation.ts +0 -5
  116. package/src/actions/ui/step-items.ts +2 -14
  117. package/src/configure-store.ts +6 -37
  118. package/src/fixtures/qcm-slide.ts +2 -2
  119. package/src/index.tsx +47 -38
  120. package/src/reducers/data/index.ts +12 -4
  121. package/src/reducers/data/progression.ts +5 -15
  122. package/src/reducers/data/skills.ts +5 -10
  123. package/src/reducers/data/slides.ts +4 -8
  124. package/src/reducers/data/token.ts +1 -11
  125. package/src/reducers/index.ts +7 -2
  126. package/src/reducers/ui/finished-slides.ts +1 -7
  127. package/src/reducers/ui/index.ts +11 -4
  128. package/src/reducers/ui/navigation.ts +1 -6
  129. package/src/reducers/ui/review-status.ts +1 -8
  130. package/src/reducers/ui/step-items.ts +5 -14
  131. package/src/services/fetch-skills.ts +4 -29
  132. package/src/services/fetch-slide.ts +10 -38
  133. package/src/services/index.ts +10 -0
  134. package/src/services/post-progression.ts +6 -28
  135. package/src/services/test/fetch-skills.test.ts +39 -0
  136. package/src/services/test/post-progression.test.ts +45 -0
  137. package/src/{index.test.tsx → test/index.test.tsx} +13 -5
  138. package/src/test/util/services.mock.ts +70 -0
  139. package/src/types/common.ts +70 -0
  140. package/src/types/globals.d.ts +1 -5
  141. package/src/types/slides.ts +1 -1
  142. package/src/types/views/slides.ts +1 -1
  143. package/es/actions/data/progression.d.ts +0 -30
  144. package/es/actions/data/progression.js +0 -12
  145. package/es/actions/data/skills.d.ts +0 -13
  146. package/es/actions/data/skills.js +0 -10
  147. package/es/middlewares/on-receive-progression.d.ts +0 -6
  148. package/es/middlewares/on-receive-progression.js +0 -22
  149. package/es/middlewares/on-receive-progression.test.d.ts +0 -1
  150. package/es/middlewares/on-receive-progression.test.js +0 -43
  151. package/es/middlewares/on-start-app.d.ts +0 -5
  152. package/es/middlewares/on-start-app.js +0 -37
  153. package/es/middlewares/on-start-app.test.d.ts +0 -1
  154. package/es/middlewares/on-start-app.test.js +0 -53
  155. package/es/services/fetch-skills.mock.d.ts +0 -3
  156. package/es/services/fetch-skills.mock.js +0 -17
  157. package/es/services/fetch-skills.test.js +0 -22
  158. package/es/services/post-progression.mock.d.ts +0 -5
  159. package/es/services/post-progression.mock.js +0 -31
  160. package/es/services/post-progression.test.js +0 -30
  161. package/es/services/tools/fetch.mocks.d.ts +0 -8
  162. package/es/services/tools/fetch.mocks.js +0 -13
  163. package/es/types/skills.d.ts +0 -7
  164. package/es/types/skills.js +0 -1
  165. package/lib/actions/data/progression.d.ts +0 -30
  166. package/lib/actions/data/progression.js +0 -12
  167. package/lib/actions/data/skills.d.ts +0 -13
  168. package/lib/actions/data/skills.js +0 -10
  169. package/lib/middlewares/on-receive-progression.d.ts +0 -6
  170. package/lib/middlewares/on-receive-progression.js +0 -27
  171. package/lib/middlewares/on-receive-progression.test.d.ts +0 -1
  172. package/lib/middlewares/on-receive-progression.test.js +0 -88
  173. package/lib/middlewares/on-start-app.d.ts +0 -5
  174. package/lib/middlewares/on-start-app.js +0 -42
  175. package/lib/middlewares/on-start-app.test.d.ts +0 -1
  176. package/lib/middlewares/on-start-app.test.js +0 -98
  177. package/lib/services/fetch-skills.mock.d.ts +0 -3
  178. package/lib/services/fetch-skills.mock.js +0 -17
  179. package/lib/services/post-progression.mock.d.ts +0 -5
  180. package/lib/services/post-progression.mock.js +0 -31
  181. package/lib/services/tools/fetch.mocks.d.ts +0 -8
  182. package/lib/services/tools/fetch.mocks.js +0 -35
  183. package/lib/types/skills.d.ts +0 -7
  184. package/lib/types/skills.js +0 -1
  185. package/src/actions/data/progression.ts +0 -50
  186. package/src/actions/data/skills.ts +0 -24
  187. package/src/middlewares/on-receive-progression.test.ts +0 -60
  188. package/src/middlewares/on-receive-progression.ts +0 -42
  189. package/src/middlewares/on-start-app.test.ts +0 -68
  190. package/src/middlewares/on-start-app.ts +0 -50
  191. package/src/services/fetch-skills.mock.ts +0 -21
  192. package/src/services/fetch-skills.test.ts +0 -32
  193. package/src/services/post-progression.mock.ts +0 -35
  194. package/src/services/post-progression.test.ts +0 -41
  195. package/src/services/tools/fetch.mocks.ts +0 -41
  196. package/src/types/skills.ts +0 -8
  197. /package/es/services/{fetch-skills.test.d.ts → test/fetch-skills.test.d.ts} +0 -0
  198. /package/es/services/{post-progression.test.d.ts → test/post-progression.test.d.ts} +0 -0
  199. /package/es/{index.test.d.ts → test/index.test.d.ts} +0 -0
  200. /package/lib/services/{fetch-skills.test.d.ts → test/fetch-skills.test.d.ts} +0 -0
  201. /package/lib/services/{post-progression.test.d.ts → test/post-progression.test.d.ts} +0 -0
  202. /package/lib/{index.test.d.ts → test/index.test.d.ts} +0 -0
@@ -5,16 +5,11 @@ import {
5
5
  NAVIGATE_TO
6
6
  } from '../../actions/ui/navigation';
7
7
 
8
- // -----------------------------------------------------------------------------
9
-
10
8
  export type NavigationState = Array<'skills' | 'onboarding' | 'slides'>;
11
- export const initialState: NavigationState = [];
12
-
13
- // -----------------------------------------------------------------------------
14
9
 
15
10
  const reducer = (
16
11
  // eslint-disable-next-line default-param-last
17
- state: NavigationState = initialState,
12
+ state: NavigationState = [],
18
13
  action: NavigateTo | NavigateBack
19
14
  ): NavigationState => {
20
15
  switch (action.type) {
@@ -1,15 +1,10 @@
1
1
  import {UpdateReviewStatus, UPDATE_REVIEW_STATUS} from '../../actions/ui/review-status';
2
2
 
3
- // -----------------------------------------------------------------------------
4
-
5
3
  export type ReviewStatusState = 'finished' | 'ongoing';
6
- export const initialState: ReviewStatusState = 'ongoing';
7
-
8
- // -----------------------------------------------------------------------------
9
4
 
10
5
  const reducer = (
11
6
  // eslint-disable-next-line default-param-last
12
- state: ReviewStatusState = initialState,
7
+ state: ReviewStatusState = 'ongoing',
13
8
  action: UpdateReviewStatus
14
9
  ): ReviewStatusState => {
15
10
  switch (action.type) {
@@ -21,6 +16,4 @@ const reducer = (
21
16
  }
22
17
  };
23
18
 
24
- // -----------------------------------------------------------------------------
25
-
26
19
  export default reducer;
@@ -1,36 +1,27 @@
1
1
  import get from 'lodash/fp/get';
2
2
  import has from 'lodash/fp/has';
3
3
  import map from 'lodash/fp/map';
4
+ import {IconValue, FinishedSlides} from '../../types/common';
4
5
  import {
5
- IconValue,
6
6
  StepItemsAction,
7
7
  UPDATE_STEP_ITEMS_ON_NEXT,
8
8
  UPDATE_STEP_ITEMS_ON_VALIDATION
9
9
  } from '../../actions/ui/step-items';
10
10
  import {HIGHEST_INDEX, slideNumbers, TOTAL_SLIDES_STACK} from '../../common';
11
- import {FinishedSlidesState} from './finished-slides';
12
11
 
13
- // -----------------------------------------------------------------------------
14
-
15
- type StepItem = {
12
+ export type StepItem = {
16
13
  current: boolean;
17
14
  icon: IconValue;
18
15
  value: string;
19
16
  };
20
17
 
21
- export type StepItems = {
18
+ export type StepItemsState = {
22
19
  slideNumbers: number[];
23
20
  [key: number]: StepItem;
24
21
  };
25
22
 
26
- // -----------------------------------------------------------------------------
27
-
28
- export type StepItemsState = StepItems;
29
-
30
- // -----------------------------------------------------------------------------
31
-
32
23
  const getInitialState = (): StepItemsState => {
33
- const state: StepItems = {
24
+ const state: StepItemsState = {
34
25
  slideNumbers
35
26
  };
36
27
 
@@ -55,7 +46,7 @@ const getNextIndex = (currentIndex: number): number =>
55
46
  // they have to be skipped)
56
47
  const calculateNextStepIndex = (
57
48
  currentStepNumber: number,
58
- finishedSlides: FinishedSlidesState,
49
+ finishedSlides: FinishedSlides,
59
50
  lastVisitedIndex = -1
60
51
  ): number => {
61
52
  // only one slide remaining, the step should stay on the same number
@@ -1,39 +1,14 @@
1
1
  import crossFetch from 'cross-fetch';
2
2
  import decode from 'jwt-decode';
3
3
 
4
- import {JWT} from '../types/common';
5
- import {Skills} from '../types/skills';
4
+ import {JWT, Skill} from '../types/common';
6
5
  import {toJSON} from './tools/fetch-responses';
7
- import mockFetchSkills from './fetch-skills.mock';
8
6
 
9
- // -----------------------------------------------------------------------------
10
-
11
- type FetchSkills = (token: string) => Promise<Skills>;
12
- type CreateFetchSkills = (fetch: typeof crossFetch) => FetchSkills;
13
- type CreateDefaultFetchSkills = () => FetchSkills;
14
-
15
- // -----------------------------------------------------------------------------
16
-
17
- const fetchSkills: CreateFetchSkills = fetch => async token => {
7
+ export const fetchSkills = async (token: string): Promise<Skill[]> => {
18
8
  const {user: userId, host}: JWT = decode(token);
19
- const response = await fetch(`${host}/api/v2/skills/review/user/${userId}`, {
9
+ const response = await crossFetch(`${host}/api/v2/skills/review/user/${userId}`, {
20
10
  headers: {authorization: token}
21
11
  });
22
12
 
23
- return toJSON<Skills>(response);
13
+ return toJSON<Skill[]>(response);
24
14
  };
25
-
26
- // -----------------------------------------------------------------------------
27
-
28
- const createFetchSkills: CreateDefaultFetchSkills = () => {
29
- if (process.env.SERVICES !== 'mocks') {
30
- return fetchSkills(crossFetch);
31
- }
32
-
33
- return fetchSkills(mockFetchSkills);
34
- };
35
-
36
- // -----------------------------------------------------------------------------
37
-
38
- export {fetchSkills};
39
- export default createFetchSkills();
@@ -1,43 +1,15 @@
1
1
  import crossFetch from 'cross-fetch';
2
- // import decode from 'jwt-decode';
2
+ import decode from 'jwt-decode';
3
3
 
4
- import {SlideFromAPI} from '../actions/data/slides';
5
- // import {JWT} from '../types/common';
6
- // import {toJSON} from './tools/fetch-responses';
7
- import {okJSONResponse} from './tools/fetch.mocks';
4
+ import {JWT, SlideFromAPI} from '../types/common';
5
+ import {toJSON} from './tools/fetch-responses';
8
6
 
9
- // -----------------------------------------------------------------------------
7
+ export const fetchSlide = async (slideRef: string, token: string): Promise<SlideFromAPI | void> => {
8
+ const {host}: JWT = decode(token);
9
+ const response = await crossFetch(`${host}/api/v2/slide/${slideRef}`, {
10
+ headers: {authorization: token}
11
+ });
10
12
 
11
- type FetchSlide = (slideRef: string, token: string) => Promise<SlideFromAPI>;
12
- type FetchSlideBuilder = (fetch: typeof crossFetch) => FetchSlide;
13
- type DefaultFetchSlideBuilder = () => FetchSlide;
14
-
15
- // -----------------------------------------------------------------------------
16
-
17
- // eslint-disable-next-line @typescript-eslint/no-unused-vars, unicorn/consistent-function-scoping, require-await
18
- const fetchSlide: FetchSlideBuilder = fetch => async (slideRef: string, token: string) => {
19
- // const {host}: JWT = decode(token);
20
- // const response = await fetch(`${host}/api/v2/slide/${slideRef}`, {
21
- // headers: {authorization: token}
22
- // });
23
-
24
- // const slide = (await toJSON(response)) as SlideFromAPI;
25
- // return slide;
26
- return {} as SlideFromAPI;
13
+ const slide = (await toJSON(response)) as SlideFromAPI;
14
+ return slide;
27
15
  };
28
-
29
- // -----------------------------------------------------------------------------
30
-
31
- const createFetchSlide: DefaultFetchSlideBuilder = () => {
32
- if (process.env.SERVICES !== 'mocks') {
33
- return fetchSlide(crossFetch);
34
- }
35
-
36
- // TODO: use an appropriate mock
37
- return fetchSlide(okJSONResponse({}));
38
- };
39
-
40
- // -----------------------------------------------------------------------------
41
-
42
- export {fetchSlide};
43
- export default createFetchSlide();
@@ -0,0 +1,10 @@
1
+ import {Services} from '../types/common';
2
+ import {fetchSkills} from './fetch-skills';
3
+ import {postProgression} from './post-progression';
4
+ import {fetchSlide} from './fetch-slide';
5
+
6
+ export const getServices = (): Services => ({
7
+ fetchSkills,
8
+ fetchSlide,
9
+ postProgression
10
+ });
@@ -1,22 +1,15 @@
1
1
  import crossFetch from 'cross-fetch';
2
2
  import decode from 'jwt-decode';
3
3
 
4
- import {ProgressionFromAPI} from '../actions/data/progression';
5
- import {JWT} from '../types/common';
4
+ import {JWT, ProgressionFromAPI} from '../types/common';
6
5
  import {toJSON} from './tools/fetch-responses';
7
- import mockPostProgression from './post-progression.mock';
8
6
 
9
- // -----------------------------------------------------------------------------
10
-
11
- type PostProgression = (skillRef: string, token: string) => Promise<ProgressionFromAPI>;
12
- type CreatePostProgression = (fetch: typeof crossFetch) => PostProgression;
13
- type DefaultCreatePostProgression = () => PostProgression;
14
-
15
- // -----------------------------------------------------------------------------
16
-
17
- const postProgression: CreatePostProgression = fetch => async (skillRef, token) => {
7
+ export const postProgression = async (
8
+ skillRef: string,
9
+ token: string
10
+ ): Promise<ProgressionFromAPI> => {
18
11
  const {host}: JWT = decode(token);
19
- const response = await fetch(`${host}/api/v2/progressions`, {
12
+ const response = await crossFetch(`${host}/api/v2/progressions`, {
20
13
  method: 'post',
21
14
  headers: {authorization: token},
22
15
  body: JSON.stringify({
@@ -33,18 +26,3 @@ const postProgression: CreatePostProgression = fetch => async (skillRef, token)
33
26
 
34
27
  return toJSON<ProgressionFromAPI>(response);
35
28
  };
36
-
37
- // -----------------------------------------------------------------------------
38
-
39
- const createPostProgression: DefaultCreatePostProgression = () => {
40
- if (process.env.SERVICES !== 'mocks') {
41
- return postProgression(crossFetch);
42
- }
43
-
44
- return postProgression(mockPostProgression);
45
- };
46
-
47
- // -----------------------------------------------------------------------------
48
-
49
- export {postProgression};
50
- export default createPostProgression();
@@ -0,0 +1,39 @@
1
+ import test from 'ava';
2
+ import nock from 'nock';
3
+ import {Skill} from '../../types/common';
4
+ import {fetchSkills} from '../fetch-skills';
5
+
6
+ const result: Skill[] = [
7
+ {
8
+ slidesToReview: 1,
9
+ name: 'skill-test',
10
+ custom: false,
11
+ skillRef: '_skill-ref'
12
+ }
13
+ ];
14
+
15
+ test.before(() => {
16
+ nock('http://localhost:3000')
17
+ .get('/api/v2/skills/review/user/592d830b240b923f00bffba6')
18
+ .reply(200, result);
19
+ });
20
+
21
+ test.after(() => {
22
+ nock.cleanAll();
23
+ });
24
+
25
+ test('should fetch skills with success', async t => {
26
+ const token = process.env.API_TEST_TOKEN || '';
27
+ const skills = await fetchSkills(token);
28
+ t.deepEqual(result, skills);
29
+ });
30
+
31
+ test('should reject bad token', async t => {
32
+ const badToken = 'token is not a jwt';
33
+ const error = await t.throwsAsync(() => fetchSkills(badToken));
34
+
35
+ t.is(
36
+ error?.message,
37
+ "Invalid token specified: Cannot read properties of undefined (reading 'replace')"
38
+ );
39
+ });
@@ -0,0 +1,45 @@
1
+ import test from 'ava';
2
+ import nock from 'nock';
3
+ import type {ProgressionFromAPI} from '../../types/common';
4
+ import {postProgression} from '../post-progression';
5
+
6
+ const skillRef = '_skill-ref';
7
+ const result: ProgressionFromAPI = {
8
+ _id: '123456123456',
9
+ state: {
10
+ isCorrect: true,
11
+ step: {
12
+ current: 1
13
+ },
14
+ nextContent: {
15
+ type: 'slide',
16
+ ref: 'sli_NJ3m5KtWh'
17
+ },
18
+ pendingSlides: []
19
+ }
20
+ };
21
+
22
+ test.before(() => {
23
+ const moocApi = nock('http://localhost:3000');
24
+ moocApi.post('/api/v2/progressions').reply(200, result);
25
+ });
26
+
27
+ test.after(() => {
28
+ nock.cleanAll();
29
+ });
30
+
31
+ test('should create progression with success', async t => {
32
+ const token = process.env.API_TEST_TOKEN || '';
33
+ const progression = await postProgression(skillRef, token);
34
+ t.deepEqual(result, progression);
35
+ });
36
+
37
+ test('should reject bad token', async t => {
38
+ const badToken = 'token is not a jwt';
39
+ const error = await t.throwsAsync(() => postProgression(skillRef, badToken));
40
+
41
+ t.is(
42
+ error?.message,
43
+ "Invalid token specified: Cannot read properties of undefined (reading 'replace')"
44
+ );
45
+ });
@@ -3,9 +3,10 @@ import test from 'ava';
3
3
  import type {ExecutionContext} from 'ava';
4
4
  import React from 'react';
5
5
  import {render, fireEvent, act} from '@testing-library/react';
6
- import type {AppOptions} from './types/common';
7
- import {sleep} from './services/tools/sleep';
8
- import AppReview from '.';
6
+ import type {AppOptions} from '../types/common';
7
+ import {sleep} from '../services/tools/sleep';
8
+ import AppReview from '..';
9
+ import {services} from './util/services.mock';
9
10
 
10
11
  browserEnv({pretendToBeVisual: true});
11
12
 
@@ -51,6 +52,7 @@ const clickAllSlides = async (
51
52
  await fireEvent.click(nextButton[0]);
52
53
  });
53
54
 
55
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
54
56
  await clickAllSlides(t, container, accumulator + 1);
55
57
  };
56
58
 
@@ -59,14 +61,19 @@ const appOptions: AppOptions = {
59
61
  templateContext: {
60
62
  theme: {color: {primary: '#123'}}
61
63
  },
62
- skillRef: 'skill_NJC0jFKoH'
64
+ skillRef: 'skill_NJC0jFKoH',
65
+ services
63
66
  };
64
67
 
65
68
  test('should validate all the slides (all correct scenario)', async t => {
66
- t.plan(13);
69
+ // t.plan(13);
70
+ t.plan(2);
67
71
  const {container} = render(<AppReview options={appOptions} key={0} />);
68
72
  await waitForChanges(1000);
69
73
 
74
+ const wrapper = container.querySelector('[data-name="loader"]');
75
+ t.truthy(wrapper);
76
+ /*
70
77
  const wrapper = container.querySelector('[data-name="slides-revision-container"]');
71
78
  t.truthy(wrapper);
72
79
 
@@ -75,6 +82,7 @@ test('should validate all the slides (all correct scenario)', async t => {
75
82
  t.truthy(stackedSlidesContainer);
76
83
 
77
84
  await clickAllSlides(t, container);
85
+ */
78
86
 
79
87
  t.pass();
80
88
  });
@@ -0,0 +1,70 @@
1
+ import {Services} from '../../types/common';
2
+
3
+ export const services: Services = {
4
+ fetchSkills: () => {
5
+ return Promise.resolve([
6
+ {
7
+ skillRef: '_skill-ref',
8
+ slidesToReview: 2,
9
+ name: 'skill-test',
10
+ custom: false
11
+ },
12
+ {
13
+ skillRef: '_skill-ref-2',
14
+ slidesToReview: 2,
15
+ name: 'skill-test-2',
16
+ custom: true
17
+ }
18
+ ]);
19
+ },
20
+ fetchSlide: ref => {
21
+ // return Promise.resolve(qcm); // why qcm does not look like a slide returned from mooc ?
22
+ return Promise.resolve({
23
+ question: {
24
+ content: {
25
+ choices: [
26
+ {
27
+ selected: false,
28
+ title: 'choix1',
29
+ help: '(help choix1)',
30
+ ariaLabel: '__ariaLabel1',
31
+ onClick: (): void => undefined
32
+ },
33
+ {
34
+ selected: false,
35
+ title: 'choix2',
36
+ help: '(help choix2)',
37
+ ariaLabel: '__ariaLabel2',
38
+ onClick: (): void => undefined
39
+ },
40
+ {
41
+ selected: false,
42
+ title: 'choix3',
43
+ help: '(help choix3)',
44
+ ariaLabel: '__ariaLabel3',
45
+ onClick: (): void => undefined
46
+ }
47
+ ]
48
+ }
49
+ },
50
+ klf: '___klf',
51
+ universalRef: ref
52
+ });
53
+ },
54
+ postProgression: () => {
55
+ return Promise.resolve({
56
+ _id: '62b1d1087aa12f00253f40ee',
57
+ state: {
58
+ pendingSlides: [],
59
+ step: {
60
+ current: 1
61
+ },
62
+ isCorrect: true,
63
+ nextContent: {
64
+ ref: 'sli_N1XACJobn',
65
+ type: 'slide'
66
+ }
67
+ }
68
+ });
69
+ }
70
+ };
@@ -1,3 +1,5 @@
1
+ import {UISlide} from './slides';
2
+
1
3
  // TODO use type from components
2
4
  type TemplateContextValues = {
3
5
  brandTheme?: unknown;
@@ -5,12 +7,55 @@ type TemplateContextValues = {
5
7
  translations?: unknown; // TODO type Translations
6
8
  };
7
9
 
10
+ export type SlideFromAPI = {
11
+ question: {
12
+ content: {
13
+ choices: Record<string, unknown>[];
14
+ };
15
+ };
16
+ klf: string;
17
+ universalRef: string;
18
+ };
19
+
20
+ export type ProgressionFromAPI = {
21
+ _id: string;
22
+ state: {
23
+ isCorrect: boolean;
24
+ step: {
25
+ current: number;
26
+ };
27
+ nextContent: {
28
+ type: 'success' | 'slide';
29
+ ref: 'successExitNode' | string;
30
+ };
31
+ pendingSlides: [];
32
+ };
33
+ };
34
+
35
+ export type Skill = {
36
+ skillRef: string;
37
+ slidesToReview: number;
38
+ custom: boolean;
39
+ name: string;
40
+ };
41
+
42
+ export type Services = {
43
+ fetchSkills(token: string): Promise<Skill[]>;
44
+ fetchSlide(slideRef: string, token: string): Promise<SlideFromAPI | void>;
45
+ postProgression(skillRef: string, token: string): Promise<ProgressionFromAPI>;
46
+ };
47
+
48
+ export type Options = {
49
+ services: Services;
50
+ };
51
+
8
52
  export type AppOptions = {
9
53
  token: string;
10
54
  theme?: unknown;
11
55
  translations?: unknown;
12
56
  templateContext?: TemplateContextValues;
13
57
  skillRef?: string;
58
+ services: Services;
14
59
  };
15
60
 
16
61
  export type JWT = {
@@ -23,6 +68,31 @@ export type JWT = {
23
68
  host: string;
24
69
  };
25
70
 
71
+ // -----------------------------------------------------------------------------
72
+ type SlideUIAnimations = 'unstack' | 'restack';
73
+ export type Slide = UISlide & {
74
+ hidden?: boolean;
75
+ position: number;
76
+ animationType?: SlideUIAnimations;
77
+ isCorrect?: boolean;
78
+ endReview?: boolean;
79
+ nextContent?: Omit<Slide, 'endReview' | 'hidden' | 'position' | 'nextContent'>;
80
+ };
81
+
82
+ const ICON_VALUES = {
83
+ right: 'right',
84
+ wrong: 'wrong',
85
+ 'no-answer': 'no-answer'
86
+ } as const;
87
+
88
+ export type IconValue = keyof typeof ICON_VALUES;
89
+ export type FinishedSlides = {
90
+ slideNumbers: number[];
91
+ [key: number]: true;
92
+ };
93
+
94
+ // -----------------------------------------------------------------------------
95
+
26
96
  export type WithRequired<T, K extends keyof T> = T & {
27
97
  // the "-" is a Mapping Modifier, removes optionality from a prop
28
98
  [P in K]-?: T[P];
@@ -2,8 +2,4 @@ declare module '*.css';
2
2
  declare module 'browser-env';
3
3
  declare module '@coorpacademy/components/es/template/app-review';
4
4
  declare module '@coorpacademy/components/es/template/app-review/template-context';
5
-
6
- // eslint-disable-next-line no-shadow
7
- declare interface Window {
8
- __REDUX_DEVTOOLS_EXTENSION_COMPOSE__?: Function;
9
- }
5
+ declare module '@coorpacademy/redux-task';
@@ -78,7 +78,7 @@ export type AnswerUI = {
78
78
 
79
79
  export type SlideUIAnimations = 'unstack' | 'restack';
80
80
 
81
- export type Slide = {
81
+ export type UISlide = {
82
82
  questionText?: string;
83
83
  answerUI?: AnswerUI;
84
84
  };
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import type {StoreState} from '../../reducers';
2
3
  import {Dispatchers} from '../../actions';
3
- import {StoreState} from '../../configure-store';
4
4
 
5
5
  type SlidesViewStaticProps = {
6
6
  slides: StoreState['data']['slides'];
@@ -1,30 +0,0 @@
1
- export declare type ProgressionFromAPI = {
2
- _id: string;
3
- state: {
4
- isCorrect: boolean;
5
- step: {
6
- current: number;
7
- };
8
- nextContent: {
9
- type: 'success' | 'slide';
10
- ref: 'successExitNode' | string;
11
- };
12
- pendingSlides: [];
13
- };
14
- };
15
- export declare const RECEIVE_PROGRESSION = "@@data/progression/RECEIVE_PROGRESSION";
16
- export declare const ERROR_CREATING_PROGRESSION = "@@data/progression/ERROR_CREATING_PROGRESSION";
17
- export declare type ReceiveProgressionPayload = {
18
- progression: ProgressionFromAPI;
19
- token: string;
20
- };
21
- export declare type ReceiveProgression = {
22
- type: typeof RECEIVE_PROGRESSION;
23
- payload: ReceiveProgressionPayload;
24
- };
25
- export declare type ErrorCreatingProgression = {
26
- type: typeof ERROR_CREATING_PROGRESSION;
27
- payload: Error;
28
- };
29
- export declare const receiveProgression: (payload: ReceiveProgressionPayload) => ReceiveProgression;
30
- export declare const errorCreatingProgression: (error: Error) => ErrorCreatingProgression;
@@ -1,12 +0,0 @@
1
- // -----------------------------------------------------------------------------
2
- export const RECEIVE_PROGRESSION = '@@data/progression/RECEIVE_PROGRESSION';
3
- export const ERROR_CREATING_PROGRESSION = '@@data/progression/ERROR_CREATING_PROGRESSION';
4
- // -----------------------------------------------------------------------------
5
- export const receiveProgression = (payload) => ({
6
- type: RECEIVE_PROGRESSION,
7
- payload
8
- });
9
- export const errorCreatingProgression = (error) => ({
10
- type: ERROR_CREATING_PROGRESSION,
11
- payload: error
12
- });
@@ -1,13 +0,0 @@
1
- import { Skills } from '../../types/skills';
2
- export declare const RECEIVED_SKILLS = "@@data/skills/RECEIVED_SKILLS";
3
- export declare const ERROR_FETCHING_SKILLS = "@@data/skills/ERROR_FETCHING_SKILLS";
4
- export declare type ReceivedSkills = {
5
- type: '@@data/skills/RECEIVED_SKILLS';
6
- payload: Skills;
7
- };
8
- export declare type ErrorFetchingSkills = {
9
- type: '@@data/skills/ERROR_FETCHING_SKILLS';
10
- payload: Error;
11
- };
12
- export declare const receivedSkills: (skills: Skills) => ReceivedSkills;
13
- export declare const errorFetchingSkills: (error: Error) => ErrorFetchingSkills;
@@ -1,10 +0,0 @@
1
- export const RECEIVED_SKILLS = '@@data/skills/RECEIVED_SKILLS';
2
- export const ERROR_FETCHING_SKILLS = '@@data/skills/ERROR_FETCHING_SKILLS';
3
- export const receivedSkills = (skills) => ({
4
- type: RECEIVED_SKILLS,
5
- payload: skills
6
- });
7
- export const errorFetchingSkills = (error) => ({
8
- type: ERROR_FETCHING_SKILLS,
9
- payload: error
10
- });
@@ -1,6 +0,0 @@
1
- import type { Middleware, Store } from 'redux';
2
- import { Dispatch } from 'redux';
3
- import { ErrorFetchingSlide, StoreFirstSlide } from '../actions/data/slides';
4
- import { ReceiveProgression } from '../actions/data/progression';
5
- declare const onReceiveProgression: Middleware<{}, Store, Dispatch<ReceiveProgression | StoreFirstSlide | ErrorFetchingSlide>>;
6
- export default onReceiveProgression;