@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.
- package/es/actions/api/fetch-skills.d.ts +13 -0
- package/es/actions/api/fetch-skills.js +8 -0
- package/es/actions/api/fetch-slide.d.ts +13 -0
- package/es/actions/api/fetch-slide.js +8 -0
- package/es/actions/api/post-progression.d.ts +13 -0
- package/es/actions/api/post-progression.js +15 -0
- package/es/actions/data/slides.d.ts +3 -24
- package/es/actions/data/slides.js +0 -11
- package/es/actions/index.d.ts +5 -4
- package/es/actions/ui/navigation.d.ts +0 -1
- package/es/actions/ui/navigation.js +0 -4
- package/es/actions/ui/step-items.d.ts +2 -8
- package/es/actions/ui/step-items.js +0 -6
- package/es/configure-store.d.ts +3 -26
- package/es/configure-store.js +4 -5
- package/es/fixtures/qcm-slide.d.ts +2 -2
- package/es/index.d.ts +1 -1
- package/es/index.js +40 -26
- package/es/reducers/data/index.d.ts +16 -5
- package/es/reducers/data/progression.d.ts +1 -2
- package/es/reducers/data/progression.js +4 -7
- package/es/reducers/data/skills.d.ts +4 -5
- package/es/reducers/data/skills.js +3 -6
- package/es/reducers/data/slides.d.ts +2 -1
- package/es/reducers/data/slides.js +3 -3
- package/es/reducers/data/token.d.ts +0 -1
- package/es/reducers/data/token.js +1 -5
- package/es/reducers/index.d.ts +9 -3
- package/es/reducers/ui/finished-slides.d.ts +0 -1
- package/es/reducers/ui/finished-slides.js +1 -3
- package/es/reducers/ui/index.d.ts +14 -4
- package/es/reducers/ui/navigation.d.ts +0 -1
- package/es/reducers/ui/navigation.js +1 -3
- package/es/reducers/ui/review-status.d.ts +0 -1
- package/es/reducers/ui/review-status.js +1 -4
- package/es/reducers/ui/step-items.d.ts +5 -5
- package/es/reducers/ui/step-items.js +0 -1
- package/es/services/fetch-skills.d.ts +2 -8
- package/es/services/fetch-skills.js +2 -14
- package/es/services/fetch-slide.d.ts +2 -8
- package/es/services/fetch-slide.js +9 -24
- package/es/services/index.d.ts +2 -0
- package/es/services/index.js +8 -0
- package/es/services/post-progression.d.ts +2 -8
- package/es/services/post-progression.js +2 -14
- package/es/services/test/fetch-skills.test.js +29 -0
- package/es/services/test/post-progression.test.js +35 -0
- package/es/{index.test.js → test/index.test.js} +15 -4
- package/es/test/util/services.mock.d.ts +2 -0
- package/es/test/util/services.mock.js +68 -0
- package/es/types/common.d.ts +58 -0
- package/es/types/common.js +5 -0
- package/es/types/slides.d.ts +1 -1
- package/es/types/views/slides.d.ts +1 -1
- package/lib/actions/api/fetch-skills.d.ts +13 -0
- package/lib/actions/api/fetch-skills.js +13 -0
- package/lib/actions/api/fetch-slide.d.ts +13 -0
- package/lib/actions/api/fetch-slide.js +13 -0
- package/lib/actions/api/post-progression.d.ts +13 -0
- package/lib/actions/api/post-progression.js +18 -0
- package/lib/actions/data/slides.d.ts +3 -24
- package/lib/actions/data/slides.js +0 -11
- package/lib/actions/index.d.ts +5 -4
- package/lib/actions/ui/navigation.d.ts +0 -1
- package/lib/actions/ui/navigation.js +0 -4
- package/lib/actions/ui/step-items.d.ts +2 -8
- package/lib/actions/ui/step-items.js +0 -6
- package/lib/configure-store.d.ts +3 -26
- package/lib/configure-store.js +4 -5
- package/lib/fixtures/qcm-slide.d.ts +2 -2
- package/lib/index.d.ts +1 -1
- package/lib/index.js +40 -70
- package/lib/reducers/data/index.d.ts +16 -5
- package/lib/reducers/data/progression.d.ts +1 -2
- package/lib/reducers/data/progression.js +4 -7
- package/lib/reducers/data/skills.d.ts +4 -5
- package/lib/reducers/data/skills.js +3 -6
- package/lib/reducers/data/slides.d.ts +2 -1
- package/lib/reducers/data/slides.js +3 -3
- package/lib/reducers/data/token.d.ts +0 -1
- package/lib/reducers/data/token.js +1 -5
- package/lib/reducers/index.d.ts +9 -3
- package/lib/reducers/ui/finished-slides.d.ts +0 -1
- package/lib/reducers/ui/finished-slides.js +1 -3
- package/lib/reducers/ui/index.d.ts +14 -4
- package/lib/reducers/ui/navigation.d.ts +0 -1
- package/lib/reducers/ui/navigation.js +1 -3
- package/lib/reducers/ui/review-status.d.ts +0 -1
- package/lib/reducers/ui/review-status.js +1 -4
- package/lib/reducers/ui/step-items.d.ts +5 -5
- package/lib/reducers/ui/step-items.js +0 -1
- package/lib/services/fetch-skills.d.ts +2 -8
- package/lib/services/fetch-skills.js +3 -15
- package/lib/services/fetch-slide.d.ts +2 -8
- package/lib/services/fetch-slide.js +18 -25
- package/lib/services/index.d.ts +2 -0
- package/lib/services/index.js +8 -0
- package/lib/services/post-progression.d.ts +2 -8
- package/lib/services/post-progression.js +3 -15
- package/lib/services/{fetch-skills.test.js → test/fetch-skills.test.js} +23 -16
- package/lib/services/{post-progression.test.js → test/post-progression.test.js} +28 -23
- package/lib/{index.test.js → test/index.test.js} +20 -10
- package/lib/test/util/services.mock.d.ts +2 -0
- package/lib/test/util/services.mock.js +68 -0
- package/lib/types/common.d.ts +58 -0
- package/lib/types/common.js +5 -0
- package/lib/types/slides.d.ts +1 -1
- package/lib/types/views/slides.d.ts +1 -1
- package/package.json +5 -4
- package/src/actions/api/fetch-skills.ts +24 -0
- package/src/actions/api/fetch-slide.ts +24 -0
- package/src/actions/api/post-progression.ts +36 -0
- package/src/actions/data/slides.ts +3 -35
- package/src/actions/index.ts +5 -11
- package/src/actions/ui/navigation.ts +0 -5
- package/src/actions/ui/step-items.ts +2 -14
- package/src/configure-store.ts +6 -37
- package/src/fixtures/qcm-slide.ts +2 -2
- package/src/index.tsx +47 -38
- package/src/reducers/data/index.ts +12 -4
- package/src/reducers/data/progression.ts +5 -15
- package/src/reducers/data/skills.ts +5 -10
- package/src/reducers/data/slides.ts +4 -8
- package/src/reducers/data/token.ts +1 -11
- package/src/reducers/index.ts +7 -2
- package/src/reducers/ui/finished-slides.ts +1 -7
- package/src/reducers/ui/index.ts +11 -4
- package/src/reducers/ui/navigation.ts +1 -6
- package/src/reducers/ui/review-status.ts +1 -8
- package/src/reducers/ui/step-items.ts +5 -14
- package/src/services/fetch-skills.ts +4 -29
- package/src/services/fetch-slide.ts +10 -38
- package/src/services/index.ts +10 -0
- package/src/services/post-progression.ts +6 -28
- package/src/services/test/fetch-skills.test.ts +39 -0
- package/src/services/test/post-progression.test.ts +45 -0
- package/src/{index.test.tsx → test/index.test.tsx} +13 -5
- package/src/test/util/services.mock.ts +70 -0
- package/src/types/common.ts +70 -0
- package/src/types/globals.d.ts +1 -5
- package/src/types/slides.ts +1 -1
- package/src/types/views/slides.ts +1 -1
- package/es/actions/data/progression.d.ts +0 -30
- package/es/actions/data/progression.js +0 -12
- package/es/actions/data/skills.d.ts +0 -13
- package/es/actions/data/skills.js +0 -10
- package/es/middlewares/on-receive-progression.d.ts +0 -6
- package/es/middlewares/on-receive-progression.js +0 -22
- package/es/middlewares/on-receive-progression.test.d.ts +0 -1
- package/es/middlewares/on-receive-progression.test.js +0 -43
- package/es/middlewares/on-start-app.d.ts +0 -5
- package/es/middlewares/on-start-app.js +0 -37
- package/es/middlewares/on-start-app.test.d.ts +0 -1
- package/es/middlewares/on-start-app.test.js +0 -53
- package/es/services/fetch-skills.mock.d.ts +0 -3
- package/es/services/fetch-skills.mock.js +0 -17
- package/es/services/fetch-skills.test.js +0 -22
- package/es/services/post-progression.mock.d.ts +0 -5
- package/es/services/post-progression.mock.js +0 -31
- package/es/services/post-progression.test.js +0 -30
- package/es/services/tools/fetch.mocks.d.ts +0 -8
- package/es/services/tools/fetch.mocks.js +0 -13
- package/es/types/skills.d.ts +0 -7
- package/es/types/skills.js +0 -1
- package/lib/actions/data/progression.d.ts +0 -30
- package/lib/actions/data/progression.js +0 -12
- package/lib/actions/data/skills.d.ts +0 -13
- package/lib/actions/data/skills.js +0 -10
- package/lib/middlewares/on-receive-progression.d.ts +0 -6
- package/lib/middlewares/on-receive-progression.js +0 -27
- package/lib/middlewares/on-receive-progression.test.d.ts +0 -1
- package/lib/middlewares/on-receive-progression.test.js +0 -88
- package/lib/middlewares/on-start-app.d.ts +0 -5
- package/lib/middlewares/on-start-app.js +0 -42
- package/lib/middlewares/on-start-app.test.d.ts +0 -1
- package/lib/middlewares/on-start-app.test.js +0 -98
- package/lib/services/fetch-skills.mock.d.ts +0 -3
- package/lib/services/fetch-skills.mock.js +0 -17
- package/lib/services/post-progression.mock.d.ts +0 -5
- package/lib/services/post-progression.mock.js +0 -31
- package/lib/services/tools/fetch.mocks.d.ts +0 -8
- package/lib/services/tools/fetch.mocks.js +0 -35
- package/lib/types/skills.d.ts +0 -7
- package/lib/types/skills.js +0 -1
- package/src/actions/data/progression.ts +0 -50
- package/src/actions/data/skills.ts +0 -24
- package/src/middlewares/on-receive-progression.test.ts +0 -60
- package/src/middlewares/on-receive-progression.ts +0 -42
- package/src/middlewares/on-start-app.test.ts +0 -68
- package/src/middlewares/on-start-app.ts +0 -50
- package/src/services/fetch-skills.mock.ts +0 -21
- package/src/services/fetch-skills.test.ts +0 -32
- package/src/services/post-progression.mock.ts +0 -35
- package/src/services/post-progression.test.ts +0 -41
- package/src/services/tools/fetch.mocks.ts +0 -41
- package/src/types/skills.ts +0 -8
- /package/es/services/{fetch-skills.test.d.ts → test/fetch-skills.test.d.ts} +0 -0
- /package/es/services/{post-progression.test.d.ts → test/post-progression.test.d.ts} +0 -0
- /package/es/{index.test.d.ts → test/index.test.d.ts} +0 -0
- /package/lib/services/{fetch-skills.test.d.ts → test/fetch-skills.test.d.ts} +0 -0
- /package/lib/services/{post-progression.test.d.ts → test/post-progression.test.d.ts} +0 -0
- /package/lib/{index.test.d.ts → test/index.test.d.ts} +0 -0
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
-
function step(op) {
|
|
15
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
-
while (_) try {
|
|
17
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
-
switch (op[0]) {
|
|
20
|
-
case 0: case 1: t = op; break;
|
|
21
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
-
default:
|
|
25
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
-
if (t[2]) _.ops.pop();
|
|
30
|
-
_.trys.pop(); continue;
|
|
31
|
-
}
|
|
32
|
-
op = body.call(thisArg, _);
|
|
33
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
import test from 'ava';
|
|
38
|
-
import { STORE_TOKEN } from '../actions/data/token';
|
|
39
|
-
import { RECEIVE_PROGRESSION } from '../actions/data/progression';
|
|
40
|
-
import { NAVIGATE_TO, startApp } from '../actions/ui/navigation';
|
|
41
|
-
import { mockedProgression } from '../services/post-progression.mock';
|
|
42
|
-
import { VIEWS } from '../common';
|
|
43
|
-
import { sleep } from '../services/tools/sleep';
|
|
44
|
-
import onStartApp from './on-start-app';
|
|
45
|
-
var appOptions = {
|
|
46
|
-
token: process.env.API_TEST_TOKEN || '',
|
|
47
|
-
skillRef: 'skill_NJC0jFKoH'
|
|
48
|
-
};
|
|
49
|
-
var otherAction = function (payload) { return ({
|
|
50
|
-
type: '@@other/OTHER',
|
|
51
|
-
payload: payload
|
|
52
|
-
}); };
|
|
53
|
-
test('should not dispatch anything if action is not START_APP', function (t) {
|
|
54
|
-
t.plan(1);
|
|
55
|
-
var dispatch = function () {
|
|
56
|
-
t.fail();
|
|
57
|
-
};
|
|
58
|
-
var next = function () {
|
|
59
|
-
return t.pass();
|
|
60
|
-
};
|
|
61
|
-
onStartApp({ dispatch: dispatch })(next)(otherAction('other'));
|
|
62
|
-
});
|
|
63
|
-
test('should dispatch actions: STORE_TOKEN && RECEIVE_PROGRESSION if an skillRef is given, on a successful response', function (t) { return __awaiter(void 0, void 0, void 0, function () {
|
|
64
|
-
var dispatch, next;
|
|
65
|
-
return __generator(this, function (_a) {
|
|
66
|
-
switch (_a.label) {
|
|
67
|
-
case 0:
|
|
68
|
-
t.plan(5);
|
|
69
|
-
dispatch = function (action) {
|
|
70
|
-
switch (action.type) {
|
|
71
|
-
case STORE_TOKEN:
|
|
72
|
-
t.is(action.payload, appOptions.token);
|
|
73
|
-
return;
|
|
74
|
-
case RECEIVE_PROGRESSION: {
|
|
75
|
-
var _a = action.payload, token = _a.token, progression = _a.progression;
|
|
76
|
-
t.is(token, appOptions.token);
|
|
77
|
-
t.deepEqual(progression, JSON.parse(JSON.stringify(mockedProgression)));
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
case NAVIGATE_TO:
|
|
81
|
-
t.is(action.payload, VIEWS.slides);
|
|
82
|
-
return;
|
|
83
|
-
default:
|
|
84
|
-
t.fail();
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
next = function () {
|
|
89
|
-
return t.pass();
|
|
90
|
-
};
|
|
91
|
-
onStartApp({ dispatch: dispatch })(next)(startApp(appOptions));
|
|
92
|
-
return [4 /*yield*/, sleep(1000)];
|
|
93
|
-
case 1:
|
|
94
|
-
_a.sent(); // wait for the .then to fire
|
|
95
|
-
return [2 /*return*/];
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
}); });
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { okJSONResponse } from './tools/fetch.mocks';
|
|
2
|
-
var result = [
|
|
3
|
-
{
|
|
4
|
-
skillRef: '_skill-ref',
|
|
5
|
-
slidesToReview: 2,
|
|
6
|
-
name: 'skill-test',
|
|
7
|
-
custom: false
|
|
8
|
-
},
|
|
9
|
-
{
|
|
10
|
-
skillRef: '_skill-ref-2',
|
|
11
|
-
slidesToReview: 2,
|
|
12
|
-
name: 'skill-test-2',
|
|
13
|
-
custom: true
|
|
14
|
-
}
|
|
15
|
-
];
|
|
16
|
-
var mockFetchSkills = okJSONResponse(result);
|
|
17
|
-
export default mockFetchSkills;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { okJSONResponse } from './tools/fetch.mocks';
|
|
2
|
-
export var mockedProgression = {
|
|
3
|
-
_id: '62b1d1087aa12f00253f40ee',
|
|
4
|
-
state: {
|
|
5
|
-
// ------------------------------------------------------
|
|
6
|
-
// unused for now / to decide whether to use it when the
|
|
7
|
-
// validation-progression is plugged in
|
|
8
|
-
pendingSlides: [],
|
|
9
|
-
step: {
|
|
10
|
-
current: Number.NaN
|
|
11
|
-
},
|
|
12
|
-
// ------------------------------------------------------
|
|
13
|
-
isCorrect: true,
|
|
14
|
-
nextContent: {
|
|
15
|
-
ref: 'sli_N1XACJobn',
|
|
16
|
-
type: 'slide'
|
|
17
|
-
}
|
|
18
|
-
// slides: [
|
|
19
|
-
// 'sli_NJ3m5KtWh',
|
|
20
|
-
// 'sli_V1gKpYYZ2',
|
|
21
|
-
// 'sli_VJzOgotbh',
|
|
22
|
-
// 'sli_V1ug-dtZn',
|
|
23
|
-
// 'sli_VyZU-ejW3',
|
|
24
|
-
// 'sli_Vy8ChgjZh',
|
|
25
|
-
// 'sli_V1ijS1oWh',
|
|
26
|
-
// 'sli_N1XACJobn'
|
|
27
|
-
// ],
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
var mockCreateProgression = okJSONResponse(mockedProgression);
|
|
31
|
-
export default mockCreateProgression;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import crossFetch from 'cross-fetch';
|
|
2
|
-
export declare const toResponse: (statusCode: number, statusText: string, body: string) => Promise<Response>;
|
|
3
|
-
export declare const okJSONResponse: (body: unknown) => typeof crossFetch;
|
|
4
|
-
export declare const internalServerErrorJSONResponse: (body: unknown) => typeof crossFetch;
|
|
5
|
-
export declare const notFoundJSONResponse: (body: unknown) => typeof crossFetch;
|
|
6
|
-
export declare const okTextResponse: (body: string) => typeof crossFetch;
|
|
7
|
-
export declare const internalServerErrorTextResponse: (body: string) => typeof crossFetch;
|
|
8
|
-
export declare const token: string;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export var toResponse = function (statusCode, statusText, body) {
|
|
2
|
-
return Promise.resolve({
|
|
3
|
-
ok: statusCode < 400,
|
|
4
|
-
status: statusCode,
|
|
5
|
-
statusText: statusText,
|
|
6
|
-
json: function () { return Promise.resolve(body).then(JSON.parse); },
|
|
7
|
-
text: function () { return Promise.resolve(body); }
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
export var okJSONResponse = function (body) {
|
|
11
|
-
return function () {
|
|
12
|
-
return toResponse(200, 'OK', JSON.stringify(body));
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
export var internalServerErrorJSONResponse = function (body) {
|
|
16
|
-
return function () {
|
|
17
|
-
return toResponse(500, 'InternalServerError', JSON.stringify(body));
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
export var notFoundJSONResponse = function (body) {
|
|
21
|
-
return function () {
|
|
22
|
-
return toResponse(404, 'Not Found', JSON.stringify(body));
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
export var okTextResponse = function (body) {
|
|
26
|
-
return function () {
|
|
27
|
-
return toResponse(200, 'OK', body);
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
export var internalServerErrorTextResponse = function (body) {
|
|
31
|
-
return function () {
|
|
32
|
-
return toResponse(500, 'InternalServerError', body);
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
export var token = process.env.API_TEST_TOKEN || 'no-API_TEST_TOKEN';
|
package/lib/types/skills.d.ts
DELETED
package/lib/types/skills.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
export 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
|
-
|
|
16
|
-
// -----------------------------------------------------------------------------
|
|
17
|
-
|
|
18
|
-
export const RECEIVE_PROGRESSION = '@@data/progression/RECEIVE_PROGRESSION';
|
|
19
|
-
export const ERROR_CREATING_PROGRESSION = '@@data/progression/ERROR_CREATING_PROGRESSION';
|
|
20
|
-
|
|
21
|
-
// -----------------------------------------------------------------------------
|
|
22
|
-
|
|
23
|
-
export type ReceiveProgressionPayload = {
|
|
24
|
-
progression: ProgressionFromAPI;
|
|
25
|
-
token: string;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
// -----------------------------------------------------------------------------
|
|
29
|
-
|
|
30
|
-
export type ReceiveProgression = {
|
|
31
|
-
type: typeof RECEIVE_PROGRESSION;
|
|
32
|
-
payload: ReceiveProgressionPayload;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export type ErrorCreatingProgression = {
|
|
36
|
-
type: typeof ERROR_CREATING_PROGRESSION;
|
|
37
|
-
payload: Error;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
// -----------------------------------------------------------------------------
|
|
41
|
-
|
|
42
|
-
export const receiveProgression = (payload: ReceiveProgressionPayload): ReceiveProgression => ({
|
|
43
|
-
type: RECEIVE_PROGRESSION,
|
|
44
|
-
payload
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
export const errorCreatingProgression = (error: Error): ErrorCreatingProgression => ({
|
|
48
|
-
type: ERROR_CREATING_PROGRESSION,
|
|
49
|
-
payload: error
|
|
50
|
-
});
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import {Skills} from '../../types/skills';
|
|
2
|
-
|
|
3
|
-
export const RECEIVED_SKILLS = '@@data/skills/RECEIVED_SKILLS';
|
|
4
|
-
export const ERROR_FETCHING_SKILLS = '@@data/skills/ERROR_FETCHING_SKILLS';
|
|
5
|
-
|
|
6
|
-
export type ReceivedSkills = {
|
|
7
|
-
type: '@@data/skills/RECEIVED_SKILLS';
|
|
8
|
-
payload: Skills;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export type ErrorFetchingSkills = {
|
|
12
|
-
type: '@@data/skills/ERROR_FETCHING_SKILLS';
|
|
13
|
-
payload: Error;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const receivedSkills = (skills: Skills): ReceivedSkills => ({
|
|
17
|
-
type: RECEIVED_SKILLS,
|
|
18
|
-
payload: skills
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
export const errorFetchingSkills = (error: Error): ErrorFetchingSkills => ({
|
|
22
|
-
type: ERROR_FETCHING_SKILLS,
|
|
23
|
-
payload: error
|
|
24
|
-
});
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import test from 'ava';
|
|
2
|
-
import {AnyAction, Dispatch, MiddlewareAPI} from 'redux';
|
|
3
|
-
import {receiveProgression} from '../actions/data/progression';
|
|
4
|
-
import {Action} from '../actions';
|
|
5
|
-
import {AppOptions} from '../types/common';
|
|
6
|
-
import {mockedProgression} from '../services/post-progression.mock';
|
|
7
|
-
import {sleep} from '../services/tools/sleep';
|
|
8
|
-
import {STORE_FIRST_SLIDE} from '../actions/data/slides';
|
|
9
|
-
import onReceiveProgression from './on-receive-progression';
|
|
10
|
-
|
|
11
|
-
const appOptions: AppOptions = {
|
|
12
|
-
token: process.env.API_TEST_TOKEN || ''
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const otherAction = (
|
|
16
|
-
payload: string
|
|
17
|
-
): {
|
|
18
|
-
type: string;
|
|
19
|
-
payload: string;
|
|
20
|
-
} => ({
|
|
21
|
-
type: '@@other/OTHER',
|
|
22
|
-
payload
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test('should not dispatch anything if action is not RECEIVE_PROGRESSION', t => {
|
|
26
|
-
t.plan(1);
|
|
27
|
-
const dispatch = (): void => {
|
|
28
|
-
t.fail();
|
|
29
|
-
};
|
|
30
|
-
const next = (): boolean => {
|
|
31
|
-
return t.pass();
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
onReceiveProgression({dispatch} as unknown as MiddlewareAPI)(next as Dispatch<AnyAction>)(
|
|
35
|
-
otherAction('other')
|
|
36
|
-
);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test('should dispatch actions: STORE_FIRST_SLIDE', async t => {
|
|
40
|
-
t.plan(2);
|
|
41
|
-
const dispatch = (action: Action): void => {
|
|
42
|
-
switch (action.type) {
|
|
43
|
-
case STORE_FIRST_SLIDE: {
|
|
44
|
-
const slide = action.payload;
|
|
45
|
-
t.deepEqual(slide, {});
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
default:
|
|
49
|
-
t.fail();
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
const next = (): boolean => {
|
|
54
|
-
return t.pass();
|
|
55
|
-
};
|
|
56
|
-
onReceiveProgression({dispatch} as MiddlewareAPI)(next as Dispatch<AnyAction>)(
|
|
57
|
-
receiveProgression({token: appOptions.token, progression: mockedProgression})
|
|
58
|
-
);
|
|
59
|
-
await sleep(1000); // wait for the .then to fire
|
|
60
|
-
});
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type {Middleware, Store} from 'redux';
|
|
2
|
-
import {Dispatch} from 'redux';
|
|
3
|
-
import get from 'lodash/fp/get';
|
|
4
|
-
|
|
5
|
-
// eslint-disable-next-line import/no-named-as-default
|
|
6
|
-
import fetchSlide from '../services/fetch-slide';
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
ErrorFetchingSlide,
|
|
10
|
-
errorFetchingSlide,
|
|
11
|
-
StoreFirstSlide,
|
|
12
|
-
storeFirstSlide
|
|
13
|
-
} from '../actions/data/slides';
|
|
14
|
-
import {ReceiveProgression, RECEIVE_PROGRESSION} from '../actions/data/progression';
|
|
15
|
-
|
|
16
|
-
const onReceiveProgression: Middleware<
|
|
17
|
-
{},
|
|
18
|
-
Store,
|
|
19
|
-
Dispatch<ReceiveProgression | StoreFirstSlide | ErrorFetchingSlide>
|
|
20
|
-
> =
|
|
21
|
-
({dispatch}) =>
|
|
22
|
-
next =>
|
|
23
|
-
(action: ReceiveProgression) => {
|
|
24
|
-
if (action.type === RECEIVE_PROGRESSION) {
|
|
25
|
-
const {progression, token} = action.payload;
|
|
26
|
-
const slideRef: string = get('state.nextContent.ref', progression);
|
|
27
|
-
// TOASK: do we need to check for exit nodes before fetching??
|
|
28
|
-
|
|
29
|
-
// TODO: To implement fetchSlide in next ticket
|
|
30
|
-
fetchSlide(slideRef, token)
|
|
31
|
-
.then(slide => {
|
|
32
|
-
return dispatch(storeFirstSlide(slide));
|
|
33
|
-
})
|
|
34
|
-
.catch(err => {
|
|
35
|
-
return dispatch(errorFetchingSlide(err));
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return next(action);
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export default onReceiveProgression;
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import test from 'ava';
|
|
2
|
-
import {AnyAction, Dispatch, MiddlewareAPI} from 'redux';
|
|
3
|
-
import {STORE_TOKEN} from '../actions/data/token';
|
|
4
|
-
import {RECEIVE_PROGRESSION} from '../actions/data/progression';
|
|
5
|
-
import {Action} from '../actions';
|
|
6
|
-
import {AppOptions} from '../types/common';
|
|
7
|
-
import {NAVIGATE_TO, startApp} from '../actions/ui/navigation';
|
|
8
|
-
import {mockedProgression} from '../services/post-progression.mock';
|
|
9
|
-
import {VIEWS} from '../common';
|
|
10
|
-
import {sleep} from '../services/tools/sleep';
|
|
11
|
-
import onStartApp from './on-start-app';
|
|
12
|
-
|
|
13
|
-
const appOptions: AppOptions = {
|
|
14
|
-
token: process.env.API_TEST_TOKEN || '',
|
|
15
|
-
skillRef: 'skill_NJC0jFKoH'
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const otherAction = (
|
|
19
|
-
payload: string
|
|
20
|
-
): {
|
|
21
|
-
type: string;
|
|
22
|
-
payload: string;
|
|
23
|
-
} => ({
|
|
24
|
-
type: '@@other/OTHER',
|
|
25
|
-
payload
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test('should not dispatch anything if action is not START_APP', t => {
|
|
29
|
-
t.plan(1);
|
|
30
|
-
const dispatch = (): void => {
|
|
31
|
-
t.fail();
|
|
32
|
-
};
|
|
33
|
-
const next = (): boolean => {
|
|
34
|
-
return t.pass();
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
onStartApp({dispatch} as unknown as MiddlewareAPI)(next as Dispatch<AnyAction>)(
|
|
38
|
-
otherAction('other')
|
|
39
|
-
);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test('should dispatch actions: STORE_TOKEN && RECEIVE_PROGRESSION if an skillRef is given, on a successful response', async t => {
|
|
43
|
-
t.plan(5);
|
|
44
|
-
const dispatch = (action: Action): void => {
|
|
45
|
-
switch (action.type) {
|
|
46
|
-
case STORE_TOKEN:
|
|
47
|
-
t.is(action.payload, appOptions.token);
|
|
48
|
-
return;
|
|
49
|
-
case RECEIVE_PROGRESSION: {
|
|
50
|
-
const {token, progression} = action.payload;
|
|
51
|
-
t.is(token, appOptions.token);
|
|
52
|
-
t.deepEqual(progression, JSON.parse(JSON.stringify(mockedProgression)));
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
case NAVIGATE_TO:
|
|
56
|
-
t.is(action.payload, VIEWS.slides);
|
|
57
|
-
return;
|
|
58
|
-
default:
|
|
59
|
-
t.fail();
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
const next = (): boolean => {
|
|
64
|
-
return t.pass();
|
|
65
|
-
};
|
|
66
|
-
onStartApp({dispatch} as MiddlewareAPI)(next as Dispatch<AnyAction>)(startApp(appOptions));
|
|
67
|
-
await sleep(1000); // wait for the .then to fire
|
|
68
|
-
});
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type {Middleware, Store} from 'redux';
|
|
2
|
-
import {Dispatch} from 'redux';
|
|
3
|
-
|
|
4
|
-
import {VIEWS} from '../common';
|
|
5
|
-
import {Action} from '../actions';
|
|
6
|
-
import {storeToken} from '../actions/data/token';
|
|
7
|
-
import {receivedSkills, errorFetchingSkills} from '../actions/data/skills';
|
|
8
|
-
import {navigateTo, START_APP, ViewPath} from '../actions/ui/navigation';
|
|
9
|
-
|
|
10
|
-
// eslint-disable-next-line import/no-named-as-default
|
|
11
|
-
import fetchSkills from '../services/fetch-skills';
|
|
12
|
-
// eslint-disable-next-line import/no-named-as-default
|
|
13
|
-
import postProgression from '../services/post-progression';
|
|
14
|
-
import {errorCreatingProgression, receiveProgression} from '../actions/data/progression';
|
|
15
|
-
|
|
16
|
-
const onStartApp: Middleware<{}, Store, Dispatch<Action>> =
|
|
17
|
-
({dispatch}) =>
|
|
18
|
-
next =>
|
|
19
|
-
(action: Action) => {
|
|
20
|
-
if (action.type === START_APP) {
|
|
21
|
-
const {skillRef, token} = action.payload;
|
|
22
|
-
|
|
23
|
-
dispatch(storeToken(token));
|
|
24
|
-
|
|
25
|
-
if (skillRef) {
|
|
26
|
-
postProgression(skillRef, token)
|
|
27
|
-
.then(progression => {
|
|
28
|
-
return dispatch(receiveProgression({progression, token}));
|
|
29
|
-
})
|
|
30
|
-
.catch(err => {
|
|
31
|
-
return dispatch(errorCreatingProgression(err));
|
|
32
|
-
});
|
|
33
|
-
} else {
|
|
34
|
-
fetchSkills(token)
|
|
35
|
-
.then(skills => {
|
|
36
|
-
return dispatch(receivedSkills(skills));
|
|
37
|
-
})
|
|
38
|
-
.catch(err => {
|
|
39
|
-
return dispatch(errorFetchingSkills(err));
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const initialView: ViewPath = skillRef ? VIEWS.slides : VIEWS.skills;
|
|
44
|
-
dispatch(navigateTo(initialView));
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return next(action);
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export default onStartApp;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import crossFetch from 'cross-fetch';
|
|
2
|
-
import {Skills} from '../types/skills';
|
|
3
|
-
import {okJSONResponse} from './tools/fetch.mocks';
|
|
4
|
-
|
|
5
|
-
const result: Skills = [
|
|
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
|
-
const mockFetchSkills: typeof crossFetch = okJSONResponse(result);
|
|
21
|
-
export default mockFetchSkills;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import test from 'ava';
|
|
2
|
-
import {Skills} from '../types/skills';
|
|
3
|
-
import {fetchSkills} from './fetch-skills';
|
|
4
|
-
import {okJSONResponse, token} from './tools/fetch.mocks';
|
|
5
|
-
|
|
6
|
-
test('should fetch skills with success', async t => {
|
|
7
|
-
const result: Skills = [
|
|
8
|
-
{
|
|
9
|
-
slidesToReview: 1,
|
|
10
|
-
name: 'skill-test',
|
|
11
|
-
custom: false,
|
|
12
|
-
skillRef: '_skill-ref'
|
|
13
|
-
}
|
|
14
|
-
];
|
|
15
|
-
|
|
16
|
-
const mockedFetchSkills = fetchSkills(okJSONResponse(result));
|
|
17
|
-
const skills = await mockedFetchSkills(token);
|
|
18
|
-
|
|
19
|
-
t.deepEqual(result, skills);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test('should reject bad token', async t => {
|
|
23
|
-
const badToken = 'token is not a jwt';
|
|
24
|
-
const mockedFetchSkills = fetchSkills(okJSONResponse([]));
|
|
25
|
-
|
|
26
|
-
const error = await t.throwsAsync(() => mockedFetchSkills(badToken));
|
|
27
|
-
|
|
28
|
-
t.is(
|
|
29
|
-
error?.message,
|
|
30
|
-
"Invalid token specified: Cannot read properties of undefined (reading 'replace')"
|
|
31
|
-
);
|
|
32
|
-
});
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import crossFetch from 'cross-fetch';
|
|
2
|
-
import {ProgressionFromAPI} from '../actions/data/progression';
|
|
3
|
-
import {okJSONResponse} from './tools/fetch.mocks';
|
|
4
|
-
|
|
5
|
-
export const mockedProgression: ProgressionFromAPI = {
|
|
6
|
-
_id: '62b1d1087aa12f00253f40ee',
|
|
7
|
-
state: {
|
|
8
|
-
// ------------------------------------------------------
|
|
9
|
-
// unused for now / to decide whether to use it when the
|
|
10
|
-
// validation-progression is plugged in
|
|
11
|
-
pendingSlides: [],
|
|
12
|
-
step: {
|
|
13
|
-
current: Number.NaN
|
|
14
|
-
},
|
|
15
|
-
// ------------------------------------------------------
|
|
16
|
-
isCorrect: true,
|
|
17
|
-
nextContent: {
|
|
18
|
-
ref: 'sli_N1XACJobn',
|
|
19
|
-
type: 'slide'
|
|
20
|
-
}
|
|
21
|
-
// slides: [
|
|
22
|
-
// 'sli_NJ3m5KtWh',
|
|
23
|
-
// 'sli_V1gKpYYZ2',
|
|
24
|
-
// 'sli_VJzOgotbh',
|
|
25
|
-
// 'sli_V1ug-dtZn',
|
|
26
|
-
// 'sli_VyZU-ejW3',
|
|
27
|
-
// 'sli_Vy8ChgjZh',
|
|
28
|
-
// 'sli_V1ijS1oWh',
|
|
29
|
-
// 'sli_N1XACJobn'
|
|
30
|
-
// ],
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const mockCreateProgression: typeof crossFetch = okJSONResponse(mockedProgression);
|
|
35
|
-
export default mockCreateProgression;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import test from 'ava';
|
|
2
|
-
import {ProgressionFromAPI} from '../actions/data/progression';
|
|
3
|
-
import {postProgression} from './post-progression';
|
|
4
|
-
import {okJSONResponse, token} from './tools/fetch.mocks';
|
|
5
|
-
|
|
6
|
-
const skillRef = '_skill-ref';
|
|
7
|
-
|
|
8
|
-
test('should create progression with success', async t => {
|
|
9
|
-
const result: ProgressionFromAPI = {
|
|
10
|
-
_id: '123456123456',
|
|
11
|
-
state: {
|
|
12
|
-
// is "isCorrect" always true for a 1st progression?
|
|
13
|
-
isCorrect: true,
|
|
14
|
-
step: {
|
|
15
|
-
current: 1
|
|
16
|
-
},
|
|
17
|
-
nextContent: {
|
|
18
|
-
type: 'slide',
|
|
19
|
-
ref: 'sli_NJ3m5KtWh'
|
|
20
|
-
},
|
|
21
|
-
pendingSlides: []
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const mockedPostProgression = postProgression(okJSONResponse(result));
|
|
26
|
-
const progression = await mockedPostProgression(skillRef, token);
|
|
27
|
-
|
|
28
|
-
t.deepEqual(result, progression);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test('should reject bad token', async t => {
|
|
32
|
-
const badToken = 'token is not a jwt';
|
|
33
|
-
const mockedPostProgression = postProgression(okJSONResponse(null));
|
|
34
|
-
|
|
35
|
-
const error = await t.throwsAsync(() => mockedPostProgression(skillRef, badToken));
|
|
36
|
-
|
|
37
|
-
t.is(
|
|
38
|
-
error?.message,
|
|
39
|
-
"Invalid token specified: Cannot read properties of undefined (reading 'replace')"
|
|
40
|
-
);
|
|
41
|
-
});
|