@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,22 +0,0 @@
|
|
|
1
|
-
import get from 'lodash/fp/get';
|
|
2
|
-
// eslint-disable-next-line import/no-named-as-default
|
|
3
|
-
import fetchSlide from '../services/fetch-slide';
|
|
4
|
-
import { errorFetchingSlide, storeFirstSlide } from '../actions/data/slides';
|
|
5
|
-
import { RECEIVE_PROGRESSION } from '../actions/data/progression';
|
|
6
|
-
const onReceiveProgression = ({ dispatch }) => next => (action) => {
|
|
7
|
-
if (action.type === RECEIVE_PROGRESSION) {
|
|
8
|
-
const { progression, token } = action.payload;
|
|
9
|
-
const slideRef = get('state.nextContent.ref', progression);
|
|
10
|
-
// TOASK: do we need to check for exit nodes before fetching??
|
|
11
|
-
// TODO: To implement fetchSlide in next ticket
|
|
12
|
-
fetchSlide(slideRef, token)
|
|
13
|
-
.then(slide => {
|
|
14
|
-
return dispatch(storeFirstSlide(slide));
|
|
15
|
-
})
|
|
16
|
-
.catch(err => {
|
|
17
|
-
return dispatch(errorFetchingSlide(err));
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
return next(action);
|
|
21
|
-
};
|
|
22
|
-
export default onReceiveProgression;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import test from 'ava';
|
|
2
|
-
import { receiveProgression } from '../actions/data/progression';
|
|
3
|
-
import { mockedProgression } from '../services/post-progression.mock';
|
|
4
|
-
import { sleep } from '../services/tools/sleep';
|
|
5
|
-
import { STORE_FIRST_SLIDE } from '../actions/data/slides';
|
|
6
|
-
import onReceiveProgression from './on-receive-progression';
|
|
7
|
-
const appOptions = {
|
|
8
|
-
token: process.env.API_TEST_TOKEN || ''
|
|
9
|
-
};
|
|
10
|
-
const otherAction = (payload) => ({
|
|
11
|
-
type: '@@other/OTHER',
|
|
12
|
-
payload
|
|
13
|
-
});
|
|
14
|
-
test('should not dispatch anything if action is not RECEIVE_PROGRESSION', t => {
|
|
15
|
-
t.plan(1);
|
|
16
|
-
const dispatch = () => {
|
|
17
|
-
t.fail();
|
|
18
|
-
};
|
|
19
|
-
const next = () => {
|
|
20
|
-
return t.pass();
|
|
21
|
-
};
|
|
22
|
-
onReceiveProgression({ dispatch })(next)(otherAction('other'));
|
|
23
|
-
});
|
|
24
|
-
test('should dispatch actions: STORE_FIRST_SLIDE', async (t) => {
|
|
25
|
-
t.plan(2);
|
|
26
|
-
const dispatch = (action) => {
|
|
27
|
-
switch (action.type) {
|
|
28
|
-
case STORE_FIRST_SLIDE: {
|
|
29
|
-
const slide = action.payload;
|
|
30
|
-
t.deepEqual(slide, {});
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
default:
|
|
34
|
-
t.fail();
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
const next = () => {
|
|
39
|
-
return t.pass();
|
|
40
|
-
};
|
|
41
|
-
onReceiveProgression({ dispatch })(next)(receiveProgression({ token: appOptions.token, progression: mockedProgression }));
|
|
42
|
-
await sleep(1000); // wait for the .then to fire
|
|
43
|
-
});
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { VIEWS } from '../common';
|
|
2
|
-
import { storeToken } from '../actions/data/token';
|
|
3
|
-
import { receivedSkills, errorFetchingSkills } from '../actions/data/skills';
|
|
4
|
-
import { navigateTo, START_APP } from '../actions/ui/navigation';
|
|
5
|
-
// eslint-disable-next-line import/no-named-as-default
|
|
6
|
-
import fetchSkills from '../services/fetch-skills';
|
|
7
|
-
// eslint-disable-next-line import/no-named-as-default
|
|
8
|
-
import postProgression from '../services/post-progression';
|
|
9
|
-
import { errorCreatingProgression, receiveProgression } from '../actions/data/progression';
|
|
10
|
-
const onStartApp = ({ dispatch }) => next => (action) => {
|
|
11
|
-
if (action.type === START_APP) {
|
|
12
|
-
const { skillRef, token } = action.payload;
|
|
13
|
-
dispatch(storeToken(token));
|
|
14
|
-
if (skillRef) {
|
|
15
|
-
postProgression(skillRef, token)
|
|
16
|
-
.then(progression => {
|
|
17
|
-
return dispatch(receiveProgression({ progression, token }));
|
|
18
|
-
})
|
|
19
|
-
.catch(err => {
|
|
20
|
-
return dispatch(errorCreatingProgression(err));
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
fetchSkills(token)
|
|
25
|
-
.then(skills => {
|
|
26
|
-
return dispatch(receivedSkills(skills));
|
|
27
|
-
})
|
|
28
|
-
.catch(err => {
|
|
29
|
-
return dispatch(errorFetchingSkills(err));
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
const initialView = skillRef ? VIEWS.slides : VIEWS.skills;
|
|
33
|
-
dispatch(navigateTo(initialView));
|
|
34
|
-
}
|
|
35
|
-
return next(action);
|
|
36
|
-
};
|
|
37
|
-
export default onStartApp;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import test from 'ava';
|
|
2
|
-
import { STORE_TOKEN } from '../actions/data/token';
|
|
3
|
-
import { RECEIVE_PROGRESSION } from '../actions/data/progression';
|
|
4
|
-
import { NAVIGATE_TO, startApp } from '../actions/ui/navigation';
|
|
5
|
-
import { mockedProgression } from '../services/post-progression.mock';
|
|
6
|
-
import { VIEWS } from '../common';
|
|
7
|
-
import { sleep } from '../services/tools/sleep';
|
|
8
|
-
import onStartApp from './on-start-app';
|
|
9
|
-
const appOptions = {
|
|
10
|
-
token: process.env.API_TEST_TOKEN || '',
|
|
11
|
-
skillRef: 'skill_NJC0jFKoH'
|
|
12
|
-
};
|
|
13
|
-
const otherAction = (payload) => ({
|
|
14
|
-
type: '@@other/OTHER',
|
|
15
|
-
payload
|
|
16
|
-
});
|
|
17
|
-
test('should not dispatch anything if action is not START_APP', t => {
|
|
18
|
-
t.plan(1);
|
|
19
|
-
const dispatch = () => {
|
|
20
|
-
t.fail();
|
|
21
|
-
};
|
|
22
|
-
const next = () => {
|
|
23
|
-
return t.pass();
|
|
24
|
-
};
|
|
25
|
-
onStartApp({ dispatch })(next)(otherAction('other'));
|
|
26
|
-
});
|
|
27
|
-
test('should dispatch actions: STORE_TOKEN && RECEIVE_PROGRESSION if an skillRef is given, on a successful response', async (t) => {
|
|
28
|
-
t.plan(5);
|
|
29
|
-
const dispatch = (action) => {
|
|
30
|
-
switch (action.type) {
|
|
31
|
-
case STORE_TOKEN:
|
|
32
|
-
t.is(action.payload, appOptions.token);
|
|
33
|
-
return;
|
|
34
|
-
case RECEIVE_PROGRESSION: {
|
|
35
|
-
const { token, progression } = action.payload;
|
|
36
|
-
t.is(token, appOptions.token);
|
|
37
|
-
t.deepEqual(progression, JSON.parse(JSON.stringify(mockedProgression)));
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
case NAVIGATE_TO:
|
|
41
|
-
t.is(action.payload, VIEWS.slides);
|
|
42
|
-
return;
|
|
43
|
-
default:
|
|
44
|
-
t.fail();
|
|
45
|
-
break;
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
const next = () => {
|
|
49
|
-
return t.pass();
|
|
50
|
-
};
|
|
51
|
-
onStartApp({ dispatch })(next)(startApp(appOptions));
|
|
52
|
-
await sleep(1000); // wait for the .then to fire
|
|
53
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { okJSONResponse } from './tools/fetch.mocks';
|
|
2
|
-
const 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
|
-
const mockFetchSkills = okJSONResponse(result);
|
|
17
|
-
export default mockFetchSkills;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import test from 'ava';
|
|
2
|
-
import { fetchSkills } from './fetch-skills';
|
|
3
|
-
import { okJSONResponse, token } from './tools/fetch.mocks';
|
|
4
|
-
test('should fetch skills with success', async (t) => {
|
|
5
|
-
const result = [
|
|
6
|
-
{
|
|
7
|
-
slidesToReview: 1,
|
|
8
|
-
name: 'skill-test',
|
|
9
|
-
custom: false,
|
|
10
|
-
skillRef: '_skill-ref'
|
|
11
|
-
}
|
|
12
|
-
];
|
|
13
|
-
const mockedFetchSkills = fetchSkills(okJSONResponse(result));
|
|
14
|
-
const skills = await mockedFetchSkills(token);
|
|
15
|
-
t.deepEqual(result, skills);
|
|
16
|
-
});
|
|
17
|
-
test('should reject bad token', async (t) => {
|
|
18
|
-
const badToken = 'token is not a jwt';
|
|
19
|
-
const mockedFetchSkills = fetchSkills(okJSONResponse([]));
|
|
20
|
-
const error = await t.throwsAsync(() => mockedFetchSkills(badToken));
|
|
21
|
-
t.is(error?.message, "Invalid token specified: Cannot read properties of undefined (reading 'replace')");
|
|
22
|
-
});
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { okJSONResponse } from './tools/fetch.mocks';
|
|
2
|
-
export const 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
|
-
const mockCreateProgression = okJSONResponse(mockedProgression);
|
|
31
|
-
export default mockCreateProgression;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import test from 'ava';
|
|
2
|
-
import { postProgression } from './post-progression';
|
|
3
|
-
import { okJSONResponse, token } from './tools/fetch.mocks';
|
|
4
|
-
const skillRef = '_skill-ref';
|
|
5
|
-
test('should create progression with success', async (t) => {
|
|
6
|
-
const result = {
|
|
7
|
-
_id: '123456123456',
|
|
8
|
-
state: {
|
|
9
|
-
// is "isCorrect" always true for a 1st progression?
|
|
10
|
-
isCorrect: true,
|
|
11
|
-
step: {
|
|
12
|
-
current: 1
|
|
13
|
-
},
|
|
14
|
-
nextContent: {
|
|
15
|
-
type: 'slide',
|
|
16
|
-
ref: 'sli_NJ3m5KtWh'
|
|
17
|
-
},
|
|
18
|
-
pendingSlides: []
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
const mockedPostProgression = postProgression(okJSONResponse(result));
|
|
22
|
-
const progression = await mockedPostProgression(skillRef, token);
|
|
23
|
-
t.deepEqual(result, progression);
|
|
24
|
-
});
|
|
25
|
-
test('should reject bad token', async (t) => {
|
|
26
|
-
const badToken = 'token is not a jwt';
|
|
27
|
-
const mockedPostProgression = postProgression(okJSONResponse(null));
|
|
28
|
-
const error = await t.throwsAsync(() => mockedPostProgression(skillRef, badToken));
|
|
29
|
-
t.is(error?.message, "Invalid token specified: Cannot read properties of undefined (reading 'replace')");
|
|
30
|
-
});
|
|
@@ -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,13 +0,0 @@
|
|
|
1
|
-
export const toResponse = (statusCode, statusText, body) => Promise.resolve({
|
|
2
|
-
ok: statusCode < 400,
|
|
3
|
-
status: statusCode,
|
|
4
|
-
statusText,
|
|
5
|
-
json: () => Promise.resolve(body).then(JSON.parse),
|
|
6
|
-
text: () => Promise.resolve(body)
|
|
7
|
-
});
|
|
8
|
-
export const okJSONResponse = (body) => () => toResponse(200, 'OK', JSON.stringify(body));
|
|
9
|
-
export const internalServerErrorJSONResponse = (body) => () => toResponse(500, 'InternalServerError', JSON.stringify(body));
|
|
10
|
-
export const notFoundJSONResponse = (body) => () => toResponse(404, 'Not Found', JSON.stringify(body));
|
|
11
|
-
export const okTextResponse = (body) => () => toResponse(200, 'OK', body);
|
|
12
|
-
export const internalServerErrorTextResponse = (body) => () => toResponse(500, 'InternalServerError', body);
|
|
13
|
-
export const token = process.env.API_TEST_TOKEN || 'no-API_TEST_TOKEN';
|
package/es/types/skills.d.ts
DELETED
package/es/types/skills.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export declare type ProgressionFromAPI = {
|
|
2
|
-
_id: string;
|
|
3
|
-
state: {
|
|
4
|
-
isCorrect: boolean;
|
|
5
|
-
step: {
|
|
6
|
-
current: number;
|
|
7
|
-
};
|
|
8
|
-
nextContent: {
|
|
9
|
-
type: 'success' | 'slide';
|
|
10
|
-
ref: 'successExitNode' | string;
|
|
11
|
-
};
|
|
12
|
-
pendingSlides: [];
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
export declare const RECEIVE_PROGRESSION = "@@data/progression/RECEIVE_PROGRESSION";
|
|
16
|
-
export declare const ERROR_CREATING_PROGRESSION = "@@data/progression/ERROR_CREATING_PROGRESSION";
|
|
17
|
-
export declare type ReceiveProgressionPayload = {
|
|
18
|
-
progression: ProgressionFromAPI;
|
|
19
|
-
token: string;
|
|
20
|
-
};
|
|
21
|
-
export declare type ReceiveProgression = {
|
|
22
|
-
type: typeof RECEIVE_PROGRESSION;
|
|
23
|
-
payload: ReceiveProgressionPayload;
|
|
24
|
-
};
|
|
25
|
-
export declare type ErrorCreatingProgression = {
|
|
26
|
-
type: typeof ERROR_CREATING_PROGRESSION;
|
|
27
|
-
payload: Error;
|
|
28
|
-
};
|
|
29
|
-
export declare const receiveProgression: (payload: ReceiveProgressionPayload) => ReceiveProgression;
|
|
30
|
-
export declare const errorCreatingProgression: (error: Error) => ErrorCreatingProgression;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// -----------------------------------------------------------------------------
|
|
2
|
-
export var RECEIVE_PROGRESSION = '@@data/progression/RECEIVE_PROGRESSION';
|
|
3
|
-
export var ERROR_CREATING_PROGRESSION = '@@data/progression/ERROR_CREATING_PROGRESSION';
|
|
4
|
-
// -----------------------------------------------------------------------------
|
|
5
|
-
export var receiveProgression = function (payload) { return ({
|
|
6
|
-
type: RECEIVE_PROGRESSION,
|
|
7
|
-
payload: payload
|
|
8
|
-
}); };
|
|
9
|
-
export var errorCreatingProgression = function (error) { return ({
|
|
10
|
-
type: ERROR_CREATING_PROGRESSION,
|
|
11
|
-
payload: error
|
|
12
|
-
}); };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Skills } from '../../types/skills';
|
|
2
|
-
export declare const RECEIVED_SKILLS = "@@data/skills/RECEIVED_SKILLS";
|
|
3
|
-
export declare const ERROR_FETCHING_SKILLS = "@@data/skills/ERROR_FETCHING_SKILLS";
|
|
4
|
-
export declare type ReceivedSkills = {
|
|
5
|
-
type: '@@data/skills/RECEIVED_SKILLS';
|
|
6
|
-
payload: Skills;
|
|
7
|
-
};
|
|
8
|
-
export declare type ErrorFetchingSkills = {
|
|
9
|
-
type: '@@data/skills/ERROR_FETCHING_SKILLS';
|
|
10
|
-
payload: Error;
|
|
11
|
-
};
|
|
12
|
-
export declare const receivedSkills: (skills: Skills) => ReceivedSkills;
|
|
13
|
-
export declare const errorFetchingSkills: (error: Error) => ErrorFetchingSkills;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export var RECEIVED_SKILLS = '@@data/skills/RECEIVED_SKILLS';
|
|
2
|
-
export var ERROR_FETCHING_SKILLS = '@@data/skills/ERROR_FETCHING_SKILLS';
|
|
3
|
-
export var receivedSkills = function (skills) { return ({
|
|
4
|
-
type: RECEIVED_SKILLS,
|
|
5
|
-
payload: skills
|
|
6
|
-
}); };
|
|
7
|
-
export var errorFetchingSkills = function (error) { return ({
|
|
8
|
-
type: ERROR_FETCHING_SKILLS,
|
|
9
|
-
payload: error
|
|
10
|
-
}); };
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { Middleware, Store } from 'redux';
|
|
2
|
-
import { Dispatch } from 'redux';
|
|
3
|
-
import { ErrorFetchingSlide, StoreFirstSlide } from '../actions/data/slides';
|
|
4
|
-
import { ReceiveProgression } from '../actions/data/progression';
|
|
5
|
-
declare const onReceiveProgression: Middleware<{}, Store, Dispatch<ReceiveProgression | StoreFirstSlide | ErrorFetchingSlide>>;
|
|
6
|
-
export default onReceiveProgression;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import get from 'lodash/fp/get';
|
|
2
|
-
// eslint-disable-next-line import/no-named-as-default
|
|
3
|
-
import fetchSlide from '../services/fetch-slide';
|
|
4
|
-
import { errorFetchingSlide, storeFirstSlide } from '../actions/data/slides';
|
|
5
|
-
import { RECEIVE_PROGRESSION } from '../actions/data/progression';
|
|
6
|
-
var onReceiveProgression = function (_a) {
|
|
7
|
-
var dispatch = _a.dispatch;
|
|
8
|
-
return function (next) {
|
|
9
|
-
return function (action) {
|
|
10
|
-
if (action.type === RECEIVE_PROGRESSION) {
|
|
11
|
-
var _a = action.payload, progression = _a.progression, token = _a.token;
|
|
12
|
-
var slideRef = get('state.nextContent.ref', progression);
|
|
13
|
-
// TOASK: do we need to check for exit nodes before fetching??
|
|
14
|
-
// TODO: To implement fetchSlide in next ticket
|
|
15
|
-
fetchSlide(slideRef, token)
|
|
16
|
-
.then(function (slide) {
|
|
17
|
-
return dispatch(storeFirstSlide(slide));
|
|
18
|
-
})
|
|
19
|
-
.catch(function (err) {
|
|
20
|
-
return dispatch(errorFetchingSlide(err));
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
return next(action);
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
export default onReceiveProgression;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,88 +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 { receiveProgression } from '../actions/data/progression';
|
|
39
|
-
import { mockedProgression } from '../services/post-progression.mock';
|
|
40
|
-
import { sleep } from '../services/tools/sleep';
|
|
41
|
-
import { STORE_FIRST_SLIDE } from '../actions/data/slides';
|
|
42
|
-
import onReceiveProgression from './on-receive-progression';
|
|
43
|
-
var appOptions = {
|
|
44
|
-
token: process.env.API_TEST_TOKEN || ''
|
|
45
|
-
};
|
|
46
|
-
var otherAction = function (payload) { return ({
|
|
47
|
-
type: '@@other/OTHER',
|
|
48
|
-
payload: payload
|
|
49
|
-
}); };
|
|
50
|
-
test('should not dispatch anything if action is not RECEIVE_PROGRESSION', function (t) {
|
|
51
|
-
t.plan(1);
|
|
52
|
-
var dispatch = function () {
|
|
53
|
-
t.fail();
|
|
54
|
-
};
|
|
55
|
-
var next = function () {
|
|
56
|
-
return t.pass();
|
|
57
|
-
};
|
|
58
|
-
onReceiveProgression({ dispatch: dispatch })(next)(otherAction('other'));
|
|
59
|
-
});
|
|
60
|
-
test('should dispatch actions: STORE_FIRST_SLIDE', function (t) { return __awaiter(void 0, void 0, void 0, function () {
|
|
61
|
-
var dispatch, next;
|
|
62
|
-
return __generator(this, function (_a) {
|
|
63
|
-
switch (_a.label) {
|
|
64
|
-
case 0:
|
|
65
|
-
t.plan(2);
|
|
66
|
-
dispatch = function (action) {
|
|
67
|
-
switch (action.type) {
|
|
68
|
-
case STORE_FIRST_SLIDE: {
|
|
69
|
-
var slide = action.payload;
|
|
70
|
-
t.deepEqual(slide, {});
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
default:
|
|
74
|
-
t.fail();
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
next = function () {
|
|
79
|
-
return t.pass();
|
|
80
|
-
};
|
|
81
|
-
onReceiveProgression({ dispatch: dispatch })(next)(receiveProgression({ token: appOptions.token, progression: mockedProgression }));
|
|
82
|
-
return [4 /*yield*/, sleep(1000)];
|
|
83
|
-
case 1:
|
|
84
|
-
_a.sent(); // wait for the .then to fire
|
|
85
|
-
return [2 /*return*/];
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
}); });
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { VIEWS } from '../common';
|
|
2
|
-
import { storeToken } from '../actions/data/token';
|
|
3
|
-
import { receivedSkills, errorFetchingSkills } from '../actions/data/skills';
|
|
4
|
-
import { navigateTo, START_APP } from '../actions/ui/navigation';
|
|
5
|
-
// eslint-disable-next-line import/no-named-as-default
|
|
6
|
-
import fetchSkills from '../services/fetch-skills';
|
|
7
|
-
// eslint-disable-next-line import/no-named-as-default
|
|
8
|
-
import postProgression from '../services/post-progression';
|
|
9
|
-
import { errorCreatingProgression, receiveProgression } from '../actions/data/progression';
|
|
10
|
-
var onStartApp = function (_a) {
|
|
11
|
-
var dispatch = _a.dispatch;
|
|
12
|
-
return function (next) {
|
|
13
|
-
return function (action) {
|
|
14
|
-
if (action.type === START_APP) {
|
|
15
|
-
var _a = action.payload, skillRef = _a.skillRef, token_1 = _a.token;
|
|
16
|
-
dispatch(storeToken(token_1));
|
|
17
|
-
if (skillRef) {
|
|
18
|
-
postProgression(skillRef, token_1)
|
|
19
|
-
.then(function (progression) {
|
|
20
|
-
return dispatch(receiveProgression({ progression: progression, token: token_1 }));
|
|
21
|
-
})
|
|
22
|
-
.catch(function (err) {
|
|
23
|
-
return dispatch(errorCreatingProgression(err));
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
fetchSkills(token_1)
|
|
28
|
-
.then(function (skills) {
|
|
29
|
-
return dispatch(receivedSkills(skills));
|
|
30
|
-
})
|
|
31
|
-
.catch(function (err) {
|
|
32
|
-
return dispatch(errorFetchingSkills(err));
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
var initialView = skillRef ? VIEWS.slides : VIEWS.skills;
|
|
36
|
-
dispatch(navigateTo(initialView));
|
|
37
|
-
}
|
|
38
|
-
return next(action);
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
export default onStartApp;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|