@coorpacademy/app-review 0.1.7 → 0.1.8
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 +10 -0
- package/es/actions/api/fetch-skills.js +8 -0
- package/es/actions/api/fetch-slide.d.ts +10 -0
- package/es/actions/api/fetch-slide.js +8 -0
- package/es/actions/api/post-progression.d.ts +10 -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.js +38 -19
- 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 +10 -0
- package/lib/actions/api/fetch-skills.js +13 -0
- package/lib/actions/api/fetch-slide.d.ts +10 -0
- package/lib/actions/api/fetch-slide.js +13 -0
- package/lib/actions/api/post-progression.d.ts +10 -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.js +38 -63
- 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 -3
- package/src/actions/api/fetch-skills.ts +20 -0
- package/src/actions/api/fetch-slide.ts +20 -0
- package/src/actions/api/post-progression.ts +26 -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 +43 -19
- 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 -0
- 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
|
@@ -35,30 +35,23 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
37
|
import crossFetch from 'cross-fetch';
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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,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
|
|
2
|
-
|
|
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
|
-
|
|
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*/,
|
|
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
|
|
39
|
-
import {
|
|
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
|
|
57
|
+
var token, skills;
|
|
42
58
|
return __generator(this, function (_a) {
|
|
43
59
|
switch (_a.label) {
|
|
44
60
|
case 0:
|
|
45
|
-
|
|
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,
|
|
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
|
-
|
|
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
|
|
39
|
-
import {
|
|
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
|
|
63
|
+
var token, progression;
|
|
43
64
|
return __generator(this, function (_a) {
|
|
44
65
|
switch (_a.label) {
|
|
45
66
|
case 0:
|
|
46
|
-
|
|
47
|
-
|
|
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,
|
|
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
|
-
|
|
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 '
|
|
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
|
|
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="
|
|
152
|
+
wrapper = container.querySelector('[data-name="loader"]');
|
|
148
153
|
t.truthy(wrapper);
|
|
149
|
-
|
|
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
|
-
|
|
152
|
-
|
|
153
|
-
|
|
161
|
+
|
|
162
|
+
await clickAllSlides(t, container);
|
|
163
|
+
*/
|
|
154
164
|
t.pass();
|
|
155
165
|
return [2 /*return*/];
|
|
156
166
|
}
|
|
@@ -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
|
+
};
|
package/lib/types/common.d.ts
CHANGED
|
@@ -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
|
};
|
package/lib/types/common.js
CHANGED
package/lib/types/slides.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coorpacademy/app-review",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
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.
|
|
43
|
+
"@coorpacademy/components": "10.22.2",
|
|
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,11 @@
|
|
|
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
79
|
},
|
|
78
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "b07a280786c4e83e3632779731e62a547d8ba26c"
|
|
79
81
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import buildTask from '@coorpacademy/redux-task';
|
|
2
|
+
import {Action, Dispatch} from 'redux';
|
|
3
|
+
import type {StoreState} from '../../reducers';
|
|
4
|
+
import {Options, Skill} from '../../types/common';
|
|
5
|
+
|
|
6
|
+
export const SKILLS_FETCH_REQUEST = '@@skills/FETCH_REQUEST' as const;
|
|
7
|
+
export const SKILLS_FETCH_SUCCESS = '@@skills/FETCH_SUCCESS' as const;
|
|
8
|
+
export const SKILLS_FETCH_FAILURE = '@@skills/FETCH_FAILURE' as const;
|
|
9
|
+
|
|
10
|
+
export type ReceivedSkills = {
|
|
11
|
+
type: '@@skills/FETCH_SUCCESS';
|
|
12
|
+
payload: Skill[];
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const fetchSkills = (token: string): Action =>
|
|
16
|
+
buildTask({
|
|
17
|
+
types: [SKILLS_FETCH_REQUEST, SKILLS_FETCH_SUCCESS, SKILLS_FETCH_FAILURE],
|
|
18
|
+
task: (dispatch: Dispatch, getState: () => StoreState, {services}: Options) =>
|
|
19
|
+
services.fetchSkills(token)
|
|
20
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type {Action, Dispatch} from 'redux';
|
|
2
|
+
import buildTask from '@coorpacademy/redux-task';
|
|
3
|
+
import type {StoreState} from '../../reducers';
|
|
4
|
+
import {Options, SlideFromAPI} from '../../types/common';
|
|
5
|
+
|
|
6
|
+
export const SLIDE_FETCH_REQUEST = '@@slides/FETCH_REQUEST' as const;
|
|
7
|
+
export const SLIDE_FETCH_SUCCESS = '@@slides/FETCH_SUCCESS' as const;
|
|
8
|
+
export const SLIDE_FETCH_FAILURE = '@@slides/FETCH_FAILURE' as const;
|
|
9
|
+
|
|
10
|
+
export type ReceivedSlide = {
|
|
11
|
+
type: typeof SLIDE_FETCH_SUCCESS;
|
|
12
|
+
payload: SlideFromAPI;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const fetchSlide = (slideRef: string, token: string): Action =>
|
|
16
|
+
buildTask({
|
|
17
|
+
types: [SLIDE_FETCH_REQUEST, SLIDE_FETCH_SUCCESS, SLIDE_FETCH_FAILURE],
|
|
18
|
+
task: (dispatch: Dispatch, getState: () => StoreState, {services}: Options) =>
|
|
19
|
+
services.fetchSlide(slideRef, token)
|
|
20
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type {Action, Dispatch} from 'redux';
|
|
2
|
+
import buildTask from '@coorpacademy/redux-task';
|
|
3
|
+
import {Options, ProgressionFromAPI} from '../../types/common';
|
|
4
|
+
import type {StoreState} from '../../reducers';
|
|
5
|
+
import {fetchSlide} from './fetch-slide';
|
|
6
|
+
|
|
7
|
+
export const POST_PROGRESSION_REQUEST = '@@progression/POST_REQUEST' as const;
|
|
8
|
+
export const POST_PROGRESSION_SUCCESS = '@@progression/POST_SUCCESS' as const;
|
|
9
|
+
export const POST_PROGRESSION_FAILURE = '@@progression/POST_FAILURE' as const;
|
|
10
|
+
|
|
11
|
+
export type ReceiveProgression = {
|
|
12
|
+
type: typeof POST_PROGRESSION_SUCCESS;
|
|
13
|
+
payload: ProgressionFromAPI;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const postProgression = (skillRef: string, token: string): Action =>
|
|
17
|
+
buildTask({
|
|
18
|
+
types: [POST_PROGRESSION_REQUEST, POST_PROGRESSION_SUCCESS, POST_PROGRESSION_FAILURE],
|
|
19
|
+
task: (dispatch: Dispatch, getState: () => StoreState, {services}: Options) => {
|
|
20
|
+
return services.postProgression(skillRef, token).then((progression: ProgressionFromAPI) => {
|
|
21
|
+
const {ref} = progression.state.nextContent;
|
|
22
|
+
dispatch(fetchSlide(ref, token));
|
|
23
|
+
return progression;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
});
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {UISlide} from '../../types/slides';
|
|
2
|
+
import {ReceivedSlide} from '../api/fetch-slide';
|
|
2
3
|
|
|
3
4
|
// -----------------------------------------------------------------------------
|
|
4
5
|
|
|
5
|
-
export const STORE_FIRST_SLIDE = '@@slide/STORE_FIRST_SLIDE';
|
|
6
6
|
export const UPDATE_SLIDES_ON_VALIDATION = '@@slide/UPDATE_SLIDES_ON_VALIDATION';
|
|
7
7
|
export const UPDATE_SLIDES_ON_NEXT = '@@slide/UPDATE_SLIDES_ON_NEXT';
|
|
8
8
|
export const VALIDATE_SLIDE = '@@slide/VALIDATE';
|
|
9
|
-
export const FETCH_NEXT_CONTENT = '@@slide/FETCH_NEXT_CONTENT';
|
|
10
|
-
export const ERROR_FETCHING_SLIDE = '@@data/slide/ERROR_FETCHING_SLIDE';
|
|
11
9
|
|
|
12
10
|
// -----------------------------------------------------------------------------
|
|
13
11
|
|
|
@@ -23,16 +21,6 @@ export type Slide = UISlide & {
|
|
|
23
21
|
};
|
|
24
22
|
|
|
25
23
|
// TODO: complete or modify typing as needed on Fetch Slide ticket
|
|
26
|
-
export type SlideFromAPI = {
|
|
27
|
-
question: {
|
|
28
|
-
content: {
|
|
29
|
-
choices: Record<string, unknown>[];
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
klf: string;
|
|
33
|
-
universalRef: string;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
24
|
export type ValidationPayload = {
|
|
37
25
|
slideNumber: number;
|
|
38
26
|
newSlideContent: Slide;
|
|
@@ -44,11 +32,6 @@ export type OnNextPayload = Omit<ValidationPayload, 'nextContent'>;
|
|
|
44
32
|
|
|
45
33
|
// -----------------------------------------------------------------------------
|
|
46
34
|
|
|
47
|
-
export type StoreFirstSlide = {
|
|
48
|
-
type: typeof STORE_FIRST_SLIDE;
|
|
49
|
-
payload: SlideFromAPI;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
35
|
export type UpdateSlidesOnValidation = {
|
|
53
36
|
type: typeof UPDATE_SLIDES_ON_VALIDATION;
|
|
54
37
|
payload: ValidationPayload;
|
|
@@ -63,20 +46,10 @@ export type ValidateSlide = {
|
|
|
63
46
|
type: typeof VALIDATE_SLIDE;
|
|
64
47
|
};
|
|
65
48
|
|
|
66
|
-
export type
|
|
67
|
-
type: typeof ERROR_FETCHING_SLIDE;
|
|
68
|
-
payload: Error;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
export type SlidesAction = StoreFirstSlide | UpdateSlidesOnValidation | UpdateSlidesOnNext;
|
|
49
|
+
export type SlidesAction = ReceivedSlide | UpdateSlidesOnValidation | UpdateSlidesOnNext;
|
|
72
50
|
|
|
73
51
|
// -----------------------------------------------------------------------------
|
|
74
52
|
|
|
75
|
-
export const storeFirstSlide = (slide: SlideFromAPI): StoreFirstSlide => ({
|
|
76
|
-
type: STORE_FIRST_SLIDE,
|
|
77
|
-
payload: slide
|
|
78
|
-
});
|
|
79
|
-
|
|
80
53
|
export const updateSlidesOnValidation = (payload: ValidationPayload): UpdateSlidesOnValidation => ({
|
|
81
54
|
type: UPDATE_SLIDES_ON_VALIDATION,
|
|
82
55
|
payload
|
|
@@ -90,8 +63,3 @@ export const updateSlidesOnNext = (payload: OnNextPayload): UpdateSlidesOnNext =
|
|
|
90
63
|
export const validateSlide = (): ValidateSlide => ({
|
|
91
64
|
type: VALIDATE_SLIDE
|
|
92
65
|
});
|
|
93
|
-
|
|
94
|
-
export const errorFetchingSlide = (error: Error): ErrorFetchingSlide => ({
|
|
95
|
-
type: ERROR_FETCHING_SLIDE,
|
|
96
|
-
payload: error
|
|
97
|
-
});
|