@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
@@ -1,10 +1,8 @@
1
1
  import { UPDATE_REVIEW_STATUS } from '../../actions/ui/review-status';
2
- export var initialState = 'ongoing';
3
- // -----------------------------------------------------------------------------
4
2
  var reducer = function (
5
3
  // eslint-disable-next-line default-param-last
6
4
  state, action) {
7
- if (state === void 0) { state = initialState; }
5
+ if (state === void 0) { state = 'ongoing'; }
8
6
  switch (action.type) {
9
7
  case UPDATE_REVIEW_STATUS: {
10
8
  return action.payload;
@@ -13,5 +11,4 @@ state, action) {
13
11
  return state;
14
12
  }
15
13
  };
16
- // -----------------------------------------------------------------------------
17
14
  export default reducer;
@@ -1,14 +1,14 @@
1
- import { IconValue, StepItemsAction } from '../../actions/ui/step-items';
2
- declare type StepItem = {
1
+ import { IconValue } from '../../types/common';
2
+ import { StepItemsAction } from '../../actions/ui/step-items';
3
+ export declare type StepItem = {
3
4
  current: boolean;
4
5
  icon: IconValue;
5
6
  value: string;
6
7
  };
7
- export declare type StepItems = {
8
+ export declare type StepItemsState = {
8
9
  slideNumbers: number[];
9
10
  [key: number]: StepItem;
10
11
  };
11
- export declare type StepItemsState = StepItems;
12
12
  export declare const initialState: StepItemsState;
13
- declare const reducer: (state: StepItems | undefined, action: StepItemsAction) => StepItemsState;
13
+ declare const reducer: (state: StepItemsState | undefined, action: StepItemsAction) => StepItemsState;
14
14
  export default reducer;
@@ -14,7 +14,6 @@ import has from 'lodash/fp/has';
14
14
  import map from 'lodash/fp/map';
15
15
  import { UPDATE_STEP_ITEMS_ON_NEXT, UPDATE_STEP_ITEMS_ON_VALIDATION } from '../../actions/ui/step-items';
16
16
  import { HIGHEST_INDEX, slideNumbers, TOTAL_SLIDES_STACK } from '../../common';
17
- // -----------------------------------------------------------------------------
18
17
  var getInitialState = function () {
19
18
  var state = {
20
19
  slideNumbers: slideNumbers
@@ -1,8 +1,2 @@
1
- import crossFetch from 'cross-fetch';
2
- import { Skills } from '../types/skills';
3
- declare type FetchSkills = (token: string) => Promise<Skills>;
4
- declare type CreateFetchSkills = (fetch: typeof crossFetch) => FetchSkills;
5
- declare const fetchSkills: CreateFetchSkills;
6
- export { fetchSkills };
7
- declare const _default: FetchSkills;
8
- export default _default;
1
+ import { Skill } from '../types/common';
2
+ export declare const fetchSkills: (token: string) => Promise<Skill[]>;
@@ -37,15 +37,13 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  import crossFetch from 'cross-fetch';
38
38
  import decode from 'jwt-decode';
39
39
  import { toJSON } from './tools/fetch-responses';
40
- import mockFetchSkills from './fetch-skills.mock';
41
- // -----------------------------------------------------------------------------
42
- var fetchSkills = function (fetch) { return function (token) { return __awaiter(void 0, void 0, void 0, function () {
40
+ export var fetchSkills = function (token) { return __awaiter(void 0, void 0, void 0, function () {
43
41
  var _a, userId, host, response;
44
42
  return __generator(this, function (_b) {
45
43
  switch (_b.label) {
46
44
  case 0:
47
45
  _a = decode(token), userId = _a.user, host = _a.host;
48
- return [4 /*yield*/, fetch("".concat(host, "/api/v2/skills/review/user/").concat(userId), {
46
+ return [4 /*yield*/, crossFetch("".concat(host, "/api/v2/skills/review/user/").concat(userId), {
49
47
  headers: { authorization: token }
50
48
  })];
51
49
  case 1:
@@ -53,14 +51,4 @@ var fetchSkills = function (fetch) { return function (token) { return __awaiter(
53
51
  return [2 /*return*/, toJSON(response)];
54
52
  }
55
53
  });
56
- }); }; };
57
- // -----------------------------------------------------------------------------
58
- var createFetchSkills = function () {
59
- if (process.env.SERVICES !== 'mocks') {
60
- return fetchSkills(crossFetch);
61
- }
62
- return fetchSkills(mockFetchSkills);
63
- };
64
- // -----------------------------------------------------------------------------
65
- export { fetchSkills };
66
- export default createFetchSkills();
54
+ }); };
@@ -1,8 +1,2 @@
1
- import crossFetch from 'cross-fetch';
2
- import { SlideFromAPI } from '../actions/data/slides';
3
- declare type FetchSlide = (slideRef: string, token: string) => Promise<SlideFromAPI>;
4
- declare type FetchSlideBuilder = (fetch: typeof crossFetch) => FetchSlide;
5
- declare const fetchSlide: FetchSlideBuilder;
6
- export { fetchSlide };
7
- declare const _default: FetchSlide;
8
- export default _default;
1
+ import { SlideFromAPI } from '../types/common';
2
+ export declare const fetchSlide: (slideRef: string, token: string) => Promise<SlideFromAPI | void>;
@@ -35,30 +35,23 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  }
36
36
  };
37
37
  import crossFetch from 'cross-fetch';
38
- // import {JWT} from '../types/common';
39
- // import {toJSON} from './tools/fetch-responses';
40
- import { okJSONResponse } from './tools/fetch.mocks';
41
- // -----------------------------------------------------------------------------
42
- // eslint-disable-next-line @typescript-eslint/no-unused-vars, unicorn/consistent-function-scoping, require-await
43
- var fetchSlide = function (fetch) { return function (slideRef, token) { return __awaiter(void 0, void 0, void 0, function () {
38
+ import decode from 'jwt-decode';
39
+ import { toJSON } from './tools/fetch-responses';
40
+ export var fetchSlide = function (slideRef, token) { return __awaiter(void 0, void 0, void 0, function () {
41
+ var host, response, slide;
44
42
  return __generator(this, function (_a) {
45
- // const {host}: JWT = decode(token);
46
- // const response = await fetch(`${host}/api/v2/slide/${slideRef}`, {
47
- // headers: {authorization: token}
48
- // });
49
- // const slide = (await toJSON(response)) as SlideFromAPI;
50
- // return slide;
51
- return [2 /*return*/, {}];
43
+ switch (_a.label) {
44
+ case 0:
45
+ host = decode(token).host;
46
+ return [4 /*yield*/, crossFetch("".concat(host, "/api/v2/slide/").concat(slideRef), {
47
+ headers: { authorization: token }
48
+ })];
49
+ case 1:
50
+ response = _a.sent();
51
+ return [4 /*yield*/, toJSON(response)];
52
+ case 2:
53
+ slide = (_a.sent());
54
+ return [2 /*return*/, slide];
55
+ }
52
56
  });
53
- }); }; };
54
- // -----------------------------------------------------------------------------
55
- var createFetchSlide = function () {
56
- if (process.env.SERVICES !== 'mocks') {
57
- return fetchSlide(crossFetch);
58
- }
59
- // TODO: use an appropriate mock
60
- return fetchSlide(okJSONResponse({}));
61
- };
62
- // -----------------------------------------------------------------------------
63
- export { fetchSlide };
64
- export default createFetchSlide();
57
+ }); };
@@ -0,0 +1,2 @@
1
+ import { Services } from '../types/common';
2
+ export declare const getServices: () => Services;
@@ -0,0 +1,8 @@
1
+ import { fetchSkills } from './fetch-skills';
2
+ import { postProgression } from './post-progression';
3
+ import { fetchSlide } from './fetch-slide';
4
+ export var getServices = function () { return ({
5
+ fetchSkills: fetchSkills,
6
+ fetchSlide: fetchSlide,
7
+ postProgression: postProgression
8
+ }); };
@@ -1,8 +1,2 @@
1
- import crossFetch from 'cross-fetch';
2
- import { ProgressionFromAPI } from '../actions/data/progression';
3
- declare type PostProgression = (skillRef: string, token: string) => Promise<ProgressionFromAPI>;
4
- declare type CreatePostProgression = (fetch: typeof crossFetch) => PostProgression;
5
- declare const postProgression: CreatePostProgression;
6
- export { postProgression };
7
- declare const _default: PostProgression;
8
- export default _default;
1
+ import { ProgressionFromAPI } from '../types/common';
2
+ export declare const postProgression: (skillRef: string, token: string) => Promise<ProgressionFromAPI>;
@@ -37,15 +37,13 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  import crossFetch from 'cross-fetch';
38
38
  import decode from 'jwt-decode';
39
39
  import { toJSON } from './tools/fetch-responses';
40
- import mockPostProgression from './post-progression.mock';
41
- // -----------------------------------------------------------------------------
42
- var postProgression = function (fetch) { return function (skillRef, token) { return __awaiter(void 0, void 0, void 0, function () {
40
+ export var postProgression = function (skillRef, token) { return __awaiter(void 0, void 0, void 0, function () {
43
41
  var host, response;
44
42
  return __generator(this, function (_a) {
45
43
  switch (_a.label) {
46
44
  case 0:
47
45
  host = decode(token).host;
48
- return [4 /*yield*/, fetch("".concat(host, "/api/v2/progressions"), {
46
+ return [4 /*yield*/, crossFetch("".concat(host, "/api/v2/progressions"), {
49
47
  method: 'post',
50
48
  headers: { authorization: token },
51
49
  body: JSON.stringify({
@@ -64,14 +62,4 @@ var postProgression = function (fetch) { return function (skillRef, token) { ret
64
62
  return [2 /*return*/, toJSON(response)];
65
63
  }
66
64
  });
67
- }); }; };
68
- // -----------------------------------------------------------------------------
69
- var createPostProgression = function () {
70
- if (process.env.SERVICES !== 'mocks') {
71
- return postProgression(crossFetch);
72
- }
73
- return postProgression(mockPostProgression);
74
- };
75
- // -----------------------------------------------------------------------------
76
- export { postProgression };
77
- export default createPostProgression();
65
+ }); };
@@ -35,23 +35,31 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  }
36
36
  };
37
37
  import test from 'ava';
38
- import { fetchSkills } from './fetch-skills';
39
- import { okJSONResponse, token } from './tools/fetch.mocks';
38
+ import nock from 'nock';
39
+ import { fetchSkills } from '../fetch-skills';
40
+ var result = [
41
+ {
42
+ slidesToReview: 1,
43
+ name: 'skill-test',
44
+ custom: false,
45
+ skillRef: '_skill-ref'
46
+ }
47
+ ];
48
+ test.before(function () {
49
+ nock('http://localhost:3000')
50
+ .get('/api/v2/skills/review/user/592d830b240b923f00bffba6')
51
+ .reply(200, result);
52
+ });
53
+ test.after(function () {
54
+ nock.cleanAll();
55
+ });
40
56
  test('should fetch skills with success', function (t) { return __awaiter(void 0, void 0, void 0, function () {
41
- var result, mockedFetchSkills, skills;
57
+ var token, skills;
42
58
  return __generator(this, function (_a) {
43
59
  switch (_a.label) {
44
60
  case 0:
45
- result = [
46
- {
47
- slidesToReview: 1,
48
- name: 'skill-test',
49
- custom: false,
50
- skillRef: '_skill-ref'
51
- }
52
- ];
53
- mockedFetchSkills = fetchSkills(okJSONResponse(result));
54
- return [4 /*yield*/, mockedFetchSkills(token)];
61
+ token = process.env.API_TEST_TOKEN || '';
62
+ return [4 /*yield*/, fetchSkills(token)];
55
63
  case 1:
56
64
  skills = _a.sent();
57
65
  t.deepEqual(result, skills);
@@ -60,13 +68,12 @@ test('should fetch skills with success', function (t) { return __awaiter(void 0,
60
68
  });
61
69
  }); });
62
70
  test('should reject bad token', function (t) { return __awaiter(void 0, void 0, void 0, function () {
63
- var badToken, mockedFetchSkills, error;
71
+ var badToken, error;
64
72
  return __generator(this, function (_a) {
65
73
  switch (_a.label) {
66
74
  case 0:
67
75
  badToken = 'token is not a jwt';
68
- mockedFetchSkills = fetchSkills(okJSONResponse([]));
69
- return [4 /*yield*/, t.throwsAsync(function () { return mockedFetchSkills(badToken); })];
76
+ return [4 /*yield*/, t.throwsAsync(function () { return fetchSkills(badToken); })];
70
77
  case 1:
71
78
  error = _a.sent();
72
79
  t.is(error === null || error === void 0 ? void 0 : error.message, "Invalid token specified: Cannot read properties of undefined (reading 'replace')");
@@ -35,31 +35,37 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  }
36
36
  };
37
37
  import test from 'ava';
38
- import { postProgression } from './post-progression';
39
- import { okJSONResponse, token } from './tools/fetch.mocks';
38
+ import nock from 'nock';
39
+ import { postProgression } from '../post-progression';
40
40
  var skillRef = '_skill-ref';
41
+ var result = {
42
+ _id: '123456123456',
43
+ state: {
44
+ isCorrect: true,
45
+ step: {
46
+ current: 1
47
+ },
48
+ nextContent: {
49
+ type: 'slide',
50
+ ref: 'sli_NJ3m5KtWh'
51
+ },
52
+ pendingSlides: []
53
+ }
54
+ };
55
+ test.before(function () {
56
+ var moocApi = nock('http://localhost:3000');
57
+ moocApi.post('/api/v2/progressions').reply(200, result);
58
+ });
59
+ test.after(function () {
60
+ nock.cleanAll();
61
+ });
41
62
  test('should create progression with success', function (t) { return __awaiter(void 0, void 0, void 0, function () {
42
- var result, mockedPostProgression, progression;
63
+ var token, progression;
43
64
  return __generator(this, function (_a) {
44
65
  switch (_a.label) {
45
66
  case 0:
46
- result = {
47
- _id: '123456123456',
48
- state: {
49
- // is "isCorrect" always true for a 1st progression?
50
- isCorrect: true,
51
- step: {
52
- current: 1
53
- },
54
- nextContent: {
55
- type: 'slide',
56
- ref: 'sli_NJ3m5KtWh'
57
- },
58
- pendingSlides: []
59
- }
60
- };
61
- mockedPostProgression = postProgression(okJSONResponse(result));
62
- return [4 /*yield*/, mockedPostProgression(skillRef, token)];
67
+ token = process.env.API_TEST_TOKEN || '';
68
+ return [4 /*yield*/, postProgression(skillRef, token)];
63
69
  case 1:
64
70
  progression = _a.sent();
65
71
  t.deepEqual(result, progression);
@@ -68,13 +74,12 @@ test('should create progression with success', function (t) { return __awaiter(v
68
74
  });
69
75
  }); });
70
76
  test('should reject bad token', function (t) { return __awaiter(void 0, void 0, void 0, function () {
71
- var badToken, mockedPostProgression, error;
77
+ var badToken, error;
72
78
  return __generator(this, function (_a) {
73
79
  switch (_a.label) {
74
80
  case 0:
75
81
  badToken = 'token is not a jwt';
76
- mockedPostProgression = postProgression(okJSONResponse(null));
77
- return [4 /*yield*/, t.throwsAsync(function () { return mockedPostProgression(skillRef, badToken); })];
82
+ return [4 /*yield*/, t.throwsAsync(function () { return postProgression(skillRef, badToken); })];
78
83
  case 1:
79
84
  error = _a.sent();
80
85
  t.is(error === null || error === void 0 ? void 0 : error.message, "Invalid token specified: Cannot read properties of undefined (reading 'replace')");
@@ -38,8 +38,9 @@ import browserEnv from 'browser-env';
38
38
  import test from 'ava';
39
39
  import React from 'react';
40
40
  import { render, fireEvent, act } from '@testing-library/react';
41
- import { sleep } from './services/tools/sleep';
42
- import AppReview from '.';
41
+ import { sleep } from '../services/tools/sleep';
42
+ import AppReview from '..';
43
+ import { services } from './util/services.mock';
43
44
  browserEnv({ pretendToBeVisual: true });
44
45
  var elementExists = function (foundElements) {
45
46
  return foundElements && foundElements[0];
@@ -119,8 +120,10 @@ var clickAllSlides = function (t, container, accumulator) {
119
120
  }); })];
120
121
  case 4:
121
122
  _a.sent();
123
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
122
124
  return [4 /*yield*/, clickAllSlides(t, container, accumulator + 1)];
123
125
  case 5:
126
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
124
127
  _a.sent();
125
128
  return [2 /*return*/];
126
129
  }
@@ -132,25 +135,32 @@ var appOptions = {
132
135
  templateContext: {
133
136
  theme: { color: { primary: '#123' } }
134
137
  },
135
- skillRef: 'skill_NJC0jFKoH'
138
+ skillRef: 'skill_NJC0jFKoH',
139
+ services: services
136
140
  };
137
141
  test('should validate all the slides (all correct scenario)', function (t) { return __awaiter(void 0, void 0, void 0, function () {
138
- var container, wrapper, stackedSlidesContainer;
142
+ var container, wrapper;
139
143
  return __generator(this, function (_a) {
140
144
  switch (_a.label) {
141
145
  case 0:
142
- t.plan(13);
146
+ // t.plan(13);
147
+ t.plan(2);
143
148
  container = render(React.createElement(AppReview, { options: appOptions, key: 0 })).container;
144
149
  return [4 /*yield*/, waitForChanges(1000)];
145
150
  case 1:
146
151
  _a.sent();
147
- wrapper = container.querySelector('[data-name="slides-revision-container"]');
152
+ wrapper = container.querySelector('[data-name="loader"]');
148
153
  t.truthy(wrapper);
149
- stackedSlidesContainer = wrapper === null || wrapper === void 0 ? void 0 : wrapper.querySelector('[data-name="stacked-slides-container"]');
154
+ /*
155
+ const wrapper = container.querySelector('[data-name="slides-revision-container"]');
156
+ t.truthy(wrapper);
157
+
158
+ const stackedSlidesContainer = wrapper?.querySelector('[data-name="stacked-slides-container"]');
159
+
150
160
  t.truthy(stackedSlidesContainer);
151
- return [4 /*yield*/, clickAllSlides(t, container)];
152
- case 2:
153
- _a.sent();
161
+
162
+ await clickAllSlides(t, container);
163
+ */
154
164
  t.pass();
155
165
  return [2 /*return*/];
156
166
  }
@@ -0,0 +1,2 @@
1
+ import { Services } from '../../types/common';
2
+ export declare const services: Services;
@@ -0,0 +1,68 @@
1
+ export var services = {
2
+ fetchSkills: function () {
3
+ return Promise.resolve([
4
+ {
5
+ skillRef: '_skill-ref',
6
+ slidesToReview: 2,
7
+ name: 'skill-test',
8
+ custom: false
9
+ },
10
+ {
11
+ skillRef: '_skill-ref-2',
12
+ slidesToReview: 2,
13
+ name: 'skill-test-2',
14
+ custom: true
15
+ }
16
+ ]);
17
+ },
18
+ fetchSlide: function (ref) {
19
+ // return Promise.resolve(qcm); // why qcm does not look like a slide returned from mooc ?
20
+ return Promise.resolve({
21
+ question: {
22
+ content: {
23
+ choices: [
24
+ {
25
+ selected: false,
26
+ title: 'choix1',
27
+ help: '(help choix1)',
28
+ ariaLabel: '__ariaLabel1',
29
+ onClick: function () { return undefined; }
30
+ },
31
+ {
32
+ selected: false,
33
+ title: 'choix2',
34
+ help: '(help choix2)',
35
+ ariaLabel: '__ariaLabel2',
36
+ onClick: function () { return undefined; }
37
+ },
38
+ {
39
+ selected: false,
40
+ title: 'choix3',
41
+ help: '(help choix3)',
42
+ ariaLabel: '__ariaLabel3',
43
+ onClick: function () { return undefined; }
44
+ }
45
+ ]
46
+ }
47
+ },
48
+ klf: '___klf',
49
+ universalRef: ref
50
+ });
51
+ },
52
+ postProgression: function () {
53
+ return Promise.resolve({
54
+ _id: '62b1d1087aa12f00253f40ee',
55
+ state: {
56
+ pendingSlides: [],
57
+ step: {
58
+ current: 1
59
+ },
60
+ isCorrect: true,
61
+ nextContent: {
62
+ ref: 'sli_N1XACJobn',
63
+ type: 'slide'
64
+ }
65
+ }
66
+ });
67
+ }
68
+ };
@@ -1,14 +1,53 @@
1
+ import { UISlide } from './slides';
1
2
  declare type TemplateContextValues = {
2
3
  brandTheme?: unknown;
3
4
  theme?: unknown;
4
5
  translations?: unknown;
5
6
  };
7
+ export declare type SlideFromAPI = {
8
+ question: {
9
+ content: {
10
+ choices: Record<string, unknown>[];
11
+ };
12
+ };
13
+ klf: string;
14
+ universalRef: string;
15
+ };
16
+ export declare type ProgressionFromAPI = {
17
+ _id: string;
18
+ state: {
19
+ isCorrect: boolean;
20
+ step: {
21
+ current: number;
22
+ };
23
+ nextContent: {
24
+ type: 'success' | 'slide';
25
+ ref: 'successExitNode' | string;
26
+ };
27
+ pendingSlides: [];
28
+ };
29
+ };
30
+ export declare type Skill = {
31
+ skillRef: string;
32
+ slidesToReview: number;
33
+ custom: boolean;
34
+ name: string;
35
+ };
36
+ export declare type Services = {
37
+ fetchSkills(token: string): Promise<Skill[]>;
38
+ fetchSlide(slideRef: string, token: string): Promise<SlideFromAPI | void>;
39
+ postProgression(skillRef: string, token: string): Promise<ProgressionFromAPI>;
40
+ };
41
+ export declare type Options = {
42
+ services: Services;
43
+ };
6
44
  export declare type AppOptions = {
7
45
  token: string;
8
46
  theme?: unknown;
9
47
  translations?: unknown;
10
48
  templateContext?: TemplateContextValues;
11
49
  skillRef?: string;
50
+ services: Services;
12
51
  };
13
52
  export declare type JWT = {
14
53
  exp: number;
@@ -19,6 +58,25 @@ export declare type JWT = {
19
58
  usage: string;
20
59
  host: string;
21
60
  };
61
+ declare type SlideUIAnimations = 'unstack' | 'restack';
62
+ export declare type Slide = UISlide & {
63
+ hidden?: boolean;
64
+ position: number;
65
+ animationType?: SlideUIAnimations;
66
+ isCorrect?: boolean;
67
+ endReview?: boolean;
68
+ nextContent?: Omit<Slide, 'endReview' | 'hidden' | 'position' | 'nextContent'>;
69
+ };
70
+ declare const ICON_VALUES: {
71
+ readonly right: "right";
72
+ readonly wrong: "wrong";
73
+ readonly 'no-answer': "no-answer";
74
+ };
75
+ export declare type IconValue = keyof typeof ICON_VALUES;
76
+ export declare type FinishedSlides = {
77
+ slideNumbers: number[];
78
+ [key: number]: true;
79
+ };
22
80
  export declare type WithRequired<T, K extends keyof T> = T & {
23
81
  [P in K]-?: T[P];
24
82
  };
@@ -1 +1,6 @@
1
+ var ICON_VALUES = {
2
+ right: 'right',
3
+ wrong: 'wrong',
4
+ 'no-answer': 'no-answer'
5
+ };
1
6
  export {};
@@ -63,7 +63,7 @@ export declare type AnswerUI = {
63
63
  help: string;
64
64
  };
65
65
  export declare type SlideUIAnimations = 'unstack' | 'restack';
66
- export declare type Slide = {
66
+ export declare type UISlide = {
67
67
  questionText?: string;
68
68
  answerUI?: AnswerUI;
69
69
  };
@@ -1,5 +1,5 @@
1
+ import type { StoreState } from '../../reducers';
1
2
  import { Dispatchers } from '../../actions';
2
- import { StoreState } from '../../configure-store';
3
3
  declare type SlidesViewStaticProps = {
4
4
  slides: StoreState['data']['slides'];
5
5
  headerProps: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coorpacademy/app-review",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "",
5
5
  "engines": {
6
6
  "node": ">=16.15.0"
@@ -40,7 +40,8 @@
40
40
  "./package.json": "./package.json"
41
41
  },
42
42
  "dependencies": {
43
- "@coorpacademy/components": "10.22.1",
43
+ "@coorpacademy/components": "10.22.3",
44
+ "@coorpacademy/redux-task": "^1.1.5",
44
45
  "cross-fetch": "^3.1.5",
45
46
  "jwt-decode": "^3.1.2",
46
47
  "react-redux": "^8.0.1",
@@ -70,10 +71,10 @@
70
71
  "eslint": "^8.18.0",
71
72
  "eslint-plugin-react-hooks": "^4.6.0",
72
73
  "live-server": "^1.2.2",
74
+ "nock": "^13.2.9",
73
75
  "postcss-modules-values-replace": "^3.4.0",
74
76
  "react-dom": "^17.0.2",
75
77
  "ts-node": "^10.8.1",
76
78
  "typescript": "^4.7.4"
77
- },
78
- "gitHead": "2d54e2e52323f3feca8dc93a02ef62a53f7d89de"
79
+ }
79
80
  }
@@ -0,0 +1,24 @@
1
+ import buildTask from '@coorpacademy/redux-task';
2
+ import type {ThunkAction, ThunkDispatch} from 'redux-thunk';
3
+ import {AnyAction} from 'redux';
4
+ import type {StoreState} from '../../reducers';
5
+ import {Options, Skill} from '../../types/common';
6
+
7
+ export const SKILLS_FETCH_REQUEST = '@@skills/FETCH_REQUEST' as const;
8
+ export const SKILLS_FETCH_SUCCESS = '@@skills/FETCH_SUCCESS' as const;
9
+ export const SKILLS_FETCH_FAILURE = '@@skills/FETCH_FAILURE' as const;
10
+
11
+ export interface ReceivedSkills extends AnyAction {
12
+ type: '@@skills/FETCH_SUCCESS';
13
+ payload: Skill[];
14
+ }
15
+
16
+ export type FetchSkillsAction = ThunkAction<Promise<void>, StoreState, Options, AnyAction>;
17
+ type Dispatch = ThunkDispatch<StoreState, Options, AnyAction>;
18
+
19
+ export const fetchSkills = (token: string): FetchSkillsAction =>
20
+ buildTask({
21
+ types: [SKILLS_FETCH_REQUEST, SKILLS_FETCH_SUCCESS, SKILLS_FETCH_FAILURE],
22
+ task: (dispatch: Dispatch, getState: () => StoreState, {services}: Options) =>
23
+ services.fetchSkills(token)
24
+ });