-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): change instruction to instructions
- Loading branch information
Showing
10 changed files
with
103 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
import { challengeService } from '../services/challenge.js'; | ||
|
||
export async function getChallenge({ id, challengeRepository }) { | ||
const challenge = await challengeRepository.get(id); | ||
return challengeService.mapChallenge(challenge); | ||
return challengeRepository.get(id); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
api/src/school/infrastructure/serializers/challenge-serializer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import jsonapiSerializer from 'jsonapi-serializer'; | ||
|
||
const { Serializer } = jsonapiSerializer; | ||
|
||
const serialize = function (challenges) { | ||
return new Serializer('challenge', { | ||
attributes: [ | ||
'type', | ||
'instructions', | ||
'proposals', | ||
'illustrationUrl', | ||
'embedUrl', | ||
'embedTitle', | ||
'embedHeight', | ||
'webComponentTagName', | ||
'webComponentProps', | ||
'illustrationAlt', | ||
'format', | ||
'autoReply', | ||
'focused', | ||
'shuffled', | ||
], | ||
transform: (challenge) => { | ||
return { | ||
...challenge, | ||
instructions: challenge.instruction?.split('***'), | ||
}; | ||
}, | ||
}).serialize(challenges); | ||
}; | ||
|
||
export { serialize }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
api/tests/school/unit/infrastructure/serializers/challenge-serializer_test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import * as serializer from '../../../../../src/school/infrastructure/serializers/challenge-serializer.js'; | ||
import { Challenge } from '../../../../../src/shared/domain/models/index.js'; | ||
import { expect } from '../../../../test-helper.js'; | ||
|
||
describe('Unit | Serializer | challenge-serializer', function () { | ||
describe('#serialize()', function () { | ||
it('should convert a Challenge model object into JSON API data', function () { | ||
// given | ||
const challenge = new Challenge({ | ||
id: 'challenge_id', | ||
instruction: 'Une première bulle.<br/>Pour tout mettre***Une deuxième bulle\n sur plusieurs lignes', | ||
proposals: | ||
'- Ils sont bio.\n- Ils pèsent plus de 63 grammes.\n- Ce sont des oeufs frais.\n- Ils sont destinés aux consommateurs.\n- Ils ne sont pas lavés.\n', | ||
type: 'QCM', | ||
illustrationUrl: 'http://illustration.url', | ||
timer: 300, | ||
competenceId: 'competence_id', | ||
embedUrl: 'url', | ||
embedTitle: 'title', | ||
embedHeight: 12, | ||
webComponentTagName: 'tagName', | ||
webComponentProps: { | ||
prop1: 'value 1', | ||
prop2: 'value 2', | ||
}, | ||
format: 'mots', | ||
shuffled: false, | ||
locales: ['fr', 'en'], | ||
focused: false, | ||
illustrationAlt: 'alt', | ||
autoReply: false, | ||
}); | ||
|
||
// when | ||
const json = serializer.serialize(challenge); | ||
|
||
// then | ||
expect(json).to.deep.equal({ | ||
data: { | ||
type: 'challenges', | ||
id: challenge.id, | ||
attributes: { | ||
instructions: ['Une première bulle.<br/>Pour tout mettre', 'Une deuxième bulle\n sur plusieurs lignes'], | ||
proposals: challenge.proposals, | ||
type: challenge.type, | ||
'illustration-url': challenge.illustrationUrl, | ||
format: 'mots', | ||
shuffled: false, | ||
focused: false, | ||
'embed-url': 'url', | ||
'embed-title': 'title', | ||
'embed-height': 12, | ||
'web-component-tag-name': 'tagName', | ||
'web-component-props': { | ||
prop1: 'value 1', | ||
prop2: 'value 2', | ||
}, | ||
'illustration-alt': 'alt', | ||
'auto-reply': false, | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |