Skip to content

Commit

Permalink
fixes + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdugne committed Sep 27, 2017
1 parent be7966b commit f45d4d7
Show file tree
Hide file tree
Showing 17 changed files with 134 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ import {
RANK_FETCH_END_SUCCESS
} from '../../api/rank';
import {EXIT_NODE_FETCH_REQUEST, EXIT_NODE_FETCH_SUCCESS} from '../../api/exit-nodes';
import {CONTENT_FETCH_REQUEST, CONTENT_FETCH_SUCCESS} from '../../api/contents';
import {
CONTENT_FETCH_REQUEST,
CONTENT_FETCH_SUCCESS,
CONTENT_INFO_FETCH_REQUEST,
CONTENT_INFO_FETCH_SUCCESS
} from '../../api/contents';
import {RECO_FETCH_REQUEST, RECO_FETCH_SUCCESS} from '../../api/recommendations';
import {UI_SELECT_ROUTE} from '../route';

Expand All @@ -43,6 +48,12 @@ const ContentService = (t, withContext) => ({
default:
throw new Error();
}
},
getInfo: (contentRef, engineRef, version) => {
t.is(contentRef, 'baz');
t.is(engineRef, 'qux');
t.is(version, 'quux');
return 'info';
}
});

Expand Down Expand Up @@ -184,6 +195,18 @@ test(
meta: {engine: {ref: 'qux', version: 'quux'}},
payload: 42
},
[
{
type: CONTENT_INFO_FETCH_REQUEST,
meta: {type: 'chapter', ref: 'baz'}
},
set('data.contents.chapter.entities.baz.info', null, {})
],
{
type: CONTENT_INFO_FETCH_SUCCESS,
meta: {type: 'chapter', ref: 'baz'},
payload: 'info'
},
[
{
type: CONTENT_FETCH_REQUEST,
Expand Down Expand Up @@ -300,6 +323,18 @@ test(
meta: {engine: {ref: 'qux', version: 'quux'}},
payload: 42
},
[
{
type: CONTENT_INFO_FETCH_REQUEST,
meta: {type: 'chapter', ref: 'baz'}
},
set('data.contents.chapter.entities.baz.info', null, {})
],
{
type: CONTENT_INFO_FETCH_SUCCESS,
meta: {type: 'chapter', ref: 'baz'},
payload: 'info'
},
[
{
type: CONTENT_FETCH_REQUEST,
Expand Down Expand Up @@ -430,6 +465,18 @@ test(
meta: {engine: {ref: 'qux', version: 'quux'}},
payload: 42
},
[
{
type: CONTENT_INFO_FETCH_REQUEST,
meta: {type: 'chapter', ref: 'baz'}
},
set('data.contents.chapter.entities.baz.info', null, {})
],
{
type: CONTENT_INFO_FETCH_SUCCESS,
meta: {type: 'chapter', ref: 'baz'},
payload: 'info'
},
[
{
type: RANK_FETCH_END_REQUEST
Expand Down
2 changes: 2 additions & 0 deletions packages/@coorpacademy-app-player/src/services/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ function getNbSlides(contentRef, engineRef, version) {
if (chapters.get(contentRef)) {
return maxNbSlides;
}

return -1;
}

export const getInfo = (contentRef, engineRef, version) => {
Expand Down
30 changes: 26 additions & 4 deletions packages/@coorpacademy-app-player/src/services/test/content.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import test from 'ava';
import head from 'lodash/fp/head';
import pipe from 'lodash/fp/pipe';
import unset from 'lodash/fp/unset';
import {pipe, head, get, unset} from 'lodash/fp';
import {getConfig} from '@coorpacademy/progression-engine';
import chaptersData from '../chapters.data';
import slidesData from '../slides.data';
import levelsData from '../levels.data';
import {find} from '../content';
import {find, getInfo} from '../content';

test('should throw error if content type is unknown', t => {
return t.throws(find('unknown', 'foo'));
Expand Down Expand Up @@ -40,3 +39,26 @@ test('should tell when a slide is not found', async t => {
const error = await t.throws(find('slide', 'unknownSlideId'));
t.is(error.message, 'Slide unknownSlideId not found');
});

test('should count slides for level', async t => {
const info = await getInfo('1.A', 'learner', 1);
t.deepEqual(info, {nbSlides: 8});
});

test('should return -1 when could not count slides for a content', async t => {
const info = await getInfo('foo', 'learner', 1);
t.deepEqual(info, {nbSlides: -1});
});

test('should count slides for chapter', async t => {
const engineRef = 'microlearning';
const version = 1;
const info = await getInfo('5.C8', engineRef, version);

const maxNbSlides = pipe(getConfig, get('slidesToComplete'))({
ref: engineRef,
version
});

t.deepEqual(info, {nbSlides: maxNbSlides});
});
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const createProgression = slide => ({
},
lives: 1,
step: {
total: 4,
current: 1
},
viewedResources: []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
"src": []
}
},
"info": {
"nbSlides": 4
},
"lessons": [
{
"type": "video",
Expand Down Expand Up @@ -67,7 +70,7 @@
"version": "1"
},
"content": {
"ref": "1.B2.3",
"ref": "1.B2.4",
"type": "slide"
},
"state": {
Expand All @@ -82,7 +85,6 @@
},
"lives": 1,
"step": {
"total": 4,
"current": 2
},
"isCorrect": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
"src": []
}
},
"info": {
"nbSlides": 1
},
"lessons": [
{
"type": "video",
Expand Down Expand Up @@ -67,7 +70,7 @@
"version": "1"
},
"content": {
"ref": "1.B2.3",
"ref": "1.B2.4",
"type": "slide"
},
"state": {
Expand All @@ -82,8 +85,7 @@
},
"lives": 1,
"step": {
"total": 4,
"current": 2
"current": 1
},
"isCorrect": false,
"stars": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
"src": []
}
},
"info": {
"nbSlides": 4
},
"lessons": [
{
"type": "video",
Expand Down Expand Up @@ -60,7 +63,7 @@
"version": "1"
},
"content": {
"ref": "1.B2.3",
"ref": "1.B2.4",
"type": "slide"
},
"state": {
Expand All @@ -75,7 +78,6 @@
},
"lives": 1,
"step": {
"total": 4,
"current": 2
},
"isCorrect": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
"src": []
}
},
"info": {
"nbSlides": 4
},
"lessons": [
{
"type": "video",
Expand Down Expand Up @@ -93,7 +96,6 @@
},
"lives": 0,
"step": {
"total": 4,
"current": 2
},
"isCorrect": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
"src": []
}
},
"info": {
"nbSlides": 4
},
"meta": {
"updatedAt": "2017-06-13T12:15:40.321Z",
"createdAt": "2017-06-13T12:15:40.321Z"
Expand Down Expand Up @@ -152,7 +155,6 @@
},
"lives": 1,
"step": {
"total": 4,
"current": 3
},
"isCorrect": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
"name": "chapter 1",
"stars": 20,
"freeRun": true,
"info": {
"nbSlides": 4
},
"meta": {
"updatedAt": "2017-06-29T14:39:19.495Z",
"createdAt": "2017-06-01T10:13:25.708Z"
Expand Down Expand Up @@ -431,7 +434,6 @@
"slides": ["sli_4ymMuMFb8", "sli_EyinLfF~X", "sli_4ymMuMFbB", "sli_NJ862PX7Q"],
"lives": 0,
"step": {
"total": 4,
"current": 5
},
"stars": 12,
Expand All @@ -442,36 +444,6 @@
"type": "slide"
}
},
"$promise": {
"$$state": {
"status": 1,
"value": {
"state": {
"nextContent": {
"ref": "failExitNode",
"type": "failure"
},
"isCorrect": false,
"slides": ["sli_4ymMuMFb8", "sli_EyinLfF~X", "sli_4ymMuMFbB", "sli_NJ862PX7Q"],
"lives": 0,
"step": {
"total": 4,
"current": 5
},
"stars": 12,
"requestedClues": [],
"viewedResources": [],
"content": {
"ref": "sli_NJ862PX7Q",
"type": "slide"
}
},
"correctAnswer": ["France", "Suisse"]
},
"processScheduled": false
}
},
"$resolved": true,
"correctAnswer": ["France", "Suisse"]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
},
"lives": 0,
"step": {
"total": 4,
"current": 2
},
"isCorrect": false,
Expand Down Expand Up @@ -175,6 +174,9 @@
"1.B2": {
"_id": "1.B2",
"stars": 20,
"info": {
"nbSlides": 4
},
"name": "Les réseaux sociaux au service du crowdfunding",
"poster": {
"subtitles": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
},
"lives": 0,
"step": {
"total": 4,
"current": 2
},
"isCorrect": false,
Expand Down Expand Up @@ -138,7 +137,10 @@
"chapter": {
"entities": {
"1.B2": {
"bestScore": 0
"bestScore": 0,
"info": {
"nbSlides": 4
}
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/@coorpacademy-app-player/src/view/test/slide.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ test('should display loading clue', async t => {
t.is(playerProps.typeClue, 'clue');
t.is(playerProps.text, null);

t.deepEqual(playerProps.step, {current: 2, total: 4});
t.deepEqual(playerProps.step, {current: 1, total: 1});

t.is(playerProps.question, "Écrivez le mot Text dans l'input.\n");
t.deepEqual(omit('onClick', playerProps.cta), {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const slidesByChapter: Array<{chapterId: string, slides: Array<Slide>}> = [
test('should return a new slide when user is still alive', t => {
const state: State = Object.freeze({
...stateForFirstSlide,
nextContent: {
content: {
type: 'slide',
ref: '1.A1.1'
},
Expand All @@ -40,7 +40,7 @@ test('should return a new slide when user is still alive', t => {
test('should return the fail endpoint, when user has no more lives', t => {
const state: State = Object.freeze({
...stateForFirstSlide,
nextContent: {
content: {
type: 'slide',
ref: '1.A1.1'
},
Expand All @@ -58,7 +58,7 @@ test('should return the fail endpoint, when user has no more lives', t => {
test('should switch chapters when user has answered `config.slidesToComplete` number of slides of a chapter', t => {
const state: State = Object.freeze({
...stateForFirstSlide,
nextContent: {
content: {
type: 'slide',
ref: '1.A1.4'
},
Expand All @@ -73,7 +73,7 @@ test('should switch chapters when user has answered `config.slidesToComplete` nu
test('should return the success endpoint when user has answered `config.slidesToComplete` number of slides of every chapter', t => {
const state: State = Object.freeze({
...stateForFirstSlide,
nextContent: {
content: {
type: 'slide',
ref: '2.A1.4'
},
Expand Down
Loading

0 comments on commit f45d4d7

Please sign in to comment.