@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
|
@@ -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
|
-
});
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import crossFetch from 'cross-fetch';
|
|
2
|
-
|
|
3
|
-
export const toResponse = (
|
|
4
|
-
statusCode: number,
|
|
5
|
-
statusText: string,
|
|
6
|
-
body: string
|
|
7
|
-
): Promise<Response> =>
|
|
8
|
-
Promise.resolve({
|
|
9
|
-
ok: statusCode < 400,
|
|
10
|
-
status: statusCode,
|
|
11
|
-
statusText,
|
|
12
|
-
json: (): Promise<unknown> => Promise.resolve(body).then(JSON.parse),
|
|
13
|
-
text: (): Promise<string> => Promise.resolve(body)
|
|
14
|
-
} as Response);
|
|
15
|
-
|
|
16
|
-
export const okJSONResponse =
|
|
17
|
-
(body: unknown): typeof crossFetch =>
|
|
18
|
-
() =>
|
|
19
|
-
toResponse(200, 'OK', JSON.stringify(body));
|
|
20
|
-
|
|
21
|
-
export const internalServerErrorJSONResponse =
|
|
22
|
-
(body: unknown): typeof crossFetch =>
|
|
23
|
-
() =>
|
|
24
|
-
toResponse(500, 'InternalServerError', JSON.stringify(body));
|
|
25
|
-
|
|
26
|
-
export const notFoundJSONResponse =
|
|
27
|
-
(body: unknown): typeof crossFetch =>
|
|
28
|
-
() =>
|
|
29
|
-
toResponse(404, 'Not Found', JSON.stringify(body));
|
|
30
|
-
|
|
31
|
-
export const okTextResponse =
|
|
32
|
-
(body: string): typeof crossFetch =>
|
|
33
|
-
() =>
|
|
34
|
-
toResponse(200, 'OK', body);
|
|
35
|
-
|
|
36
|
-
export const internalServerErrorTextResponse =
|
|
37
|
-
(body: string): typeof crossFetch =>
|
|
38
|
-
() =>
|
|
39
|
-
toResponse(500, 'InternalServerError', body);
|
|
40
|
-
|
|
41
|
-
export const token: string = process.env.API_TEST_TOKEN || 'no-API_TEST_TOKEN';
|
package/src/types/skills.ts
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|