-
Notifications
You must be signed in to change notification settings - Fork 20
[#465] [FEATURE] Amélioration de la gestion des tests adaptatifs (US-604). #465
Conversation
Bon il ne reste plus qu'à :
|
6b73e99
to
12572dd
Compare
I've deployed this PR to http://improve-adaptive-tests.pix.beta.gouv.fr. Please check it out |
1 similar comment
I've deployed this PR to http://improve-adaptive-tests.pix.beta.gouv.fr. Please check it out |
J'ai eu une erreur chelou mais c'est quand même passé à la question suivante :
Vous savez d'où ça vient ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quelques remarques/suggestions que je te soumet à chaud. Je n'ai pas encore regardé les tests mais Good Job !
const challengesLength = _.get(course, 'challenges.length', 0); | ||
coursePix = course; | ||
const challengePromises = coursePix.challenges.map(challengeId => challengeRepository.get(challengeId)); | ||
return Promise.all(challengePromises); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum ici tu on faire un return directement de la ligne au dessus.
Le résultat sera directement dispo pour le prochain then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
Il est possible d'aplatir la chaine de promise de la même manière que le getNextChallenge() juste au dessus. Dispo si besoin d'un coup de main sur les promises.
|
||
if (!course.isAdaptive) { | ||
if (!coursePix.isAdaptive) { | ||
return challengesLength > 0 && _.isEqual(answersLength, challengesLength); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
La présence du return nous dispense du else.
On peut donc le virer :)
api/lib/cat/answer.js
Outdated
} | ||
|
||
get binaryOutcome() { | ||
if(this.result === 'ok') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ici on pourrait procéder de deux façons:
1- Comme le précédent commentaire, plus besoin du else.
2- Je propose ce petit shortcut (à adapter):
get binaryOutcome() {
const isResultOk = this.result === 'ok';
return Math.floor(isResultOk);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ou simplement une ternaire, ce serait pas gênant ici.
return if(this.result === 'ok') ? 1 : 0;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
@@ -0,0 +1,119 @@ | |||
Set.prototype.union = function(setB) { | |||
const union = new Set(this); | |||
for (const elem of setB) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Je ne sais pas si j'ai bien compris l'intention mais je me dis qu'un coup de map ferait peut-être l'affaire.
genre:
return setB.map(union.add);
Tu me diras :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
J'aurais plutôt parié sur un reduce() du coup, mais je suis pas sûr.
Par contre, j'aurais bien aimé quelques tests sur les opérations (union, difference).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Je préfère laisser un for..each car c'est l'implem exacte donnée par la doc de Set.
Par ailleurs, ça permet d'avoir une implem très proche entre union
et difference
(dans le second cas, on peut aussi utiliser reduce, mais ce serait incompréhensible).
👍 pour les tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
api/lib/cat/assessment.js
Outdated
const validated = new Set(); | ||
this.answers.forEach(answer => { | ||
if (answer.result === 'ok') { | ||
answer.challenge.skills.forEach(skill => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ici j'aurai pris ce raccourci: Avec Map ou ForeEach
return answer.challenge.skills.map((skill)=>{
return skill.getEasierWithin(this.course.tubes).forEach(validated.add);
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
const assessment = AssessmentAdapter.getAdaptedAssessment(assessmentPix, answersPix, challengesPix); | ||
if (assessment.nextChallenge) { | ||
return assessment.nextChallenge.id; | ||
} else { // end of the test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idem pour le return statement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
const challengesLength = _.get(course, 'challenges.length', 0); | ||
coursePix = course; | ||
const challengePromises = coursePix.challenges.map(challengeId => challengeRepository.get(challengeId)); | ||
return Promise.all(challengePromises); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
Il est possible d'aplatir la chaine de promise de la même manière que le getNextChallenge() juste au dessus. Dispo si besoin d'un coup de main sur les promises.
api/lib/cat/answer.js
Outdated
} | ||
|
||
get binaryOutcome() { | ||
if(this.result === 'ok') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ou simplement une ternaire, ce serait pas gênant ici.
return if(this.result === 'ok') ? 1 : 0;
@@ -0,0 +1,119 @@ | |||
Set.prototype.union = function(setB) { | |||
const union = new Set(this); | |||
for (const elem of setB) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
J'aurais plutôt parié sur un reduce() du coup, mais je suis pas sûr.
Par contre, j'aurais bien aimé quelques tests sur les opérations (union, difference).
api/tests/unit/cat/course.spec.js
Outdated
describe('#tubes', function() { | ||
it('should exist', function() { | ||
// given | ||
/* const url1 = new Skill('url', 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quelques commentaires en trop ;)
@@ -61,7 +69,7 @@ function selectNextChallengeId(course, currentChallengeId, assessment) { | |||
} | |||
|
|||
if (course.isAdaptive) { | |||
return resolve(_selectNextInAdaptiveMode(assessment)); | |||
return resolve(_selectNextInAdaptiveMode(assessment, course)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
La fonction selectNextChallengeId
pourrait être renommée en _selectNextChallengeId
car elle n'est utilisée qu'ici et n'est pas publique.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
const Answer = require('../../cat/answer'); | ||
const Assessment = require('../../cat/assessment'); | ||
|
||
function getAdaptedAssessment(assessmentPix, answersPix, challengesPix) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Le code est un peu dense ici.
On pourrait ajouter des sauts de ligne et/ou découper certaines portions en fonctions privées ?
Par exemple, ligne 10 à 22 semble être un ensemble cohérent, une fonction privée qui explique ce que ça fait serait super cool pour la lecture.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
}]; | ||
|
||
beforeEach(function(done) { | ||
knex('assessments').delete().then(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On essaye de ne plus faire des imbrications de promises comme ça.
Tu peux t'inspirer de assessment-controller-get-solutions_test.js pour simplifier tout ça.
D'autant que si tu supprimes après chaque test, les phases de delete()
sont inutiles dans le beforeEach() ;)
it('should return the third challenge if the first answer is incorrect', function(done) { | ||
|
||
const options = { method: 'GET', url: '/api/assessments/' + insertedAssessmentId + '/next/w_first_challenge' }; | ||
server.inject(options, (response) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
De même, au lieu de inject()
et de done
, on essaye de faire via des promises.
Le fichier assessment-controller-get-solutions_test.js est un bon exemple.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
L'avantage est de faire remonter la cause des erreurs bien plus explicitement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
le inject est la façon de faire des tests haut-niveau avec Hapi. difficile de s'en passer.
ok pour le done
.
I've deployed this PR to http://improve-adaptive-tests.pix.beta.gouv.fr. Please check it out |
I've deployed this PR to http://improve-adaptive-tests.pix.beta.gouv.fr. Please check it out |
I've deployed this PR to http://improve-adaptive-tests.pix.beta.gouv.fr. Please check it out |
I've deployed this PR to http://improve-adaptive-tests.pix.beta.gouv.fr. Please check it out |
en attente de la validation fonctionnelle par Benjamin |
Pardon, il manque un dernier détail dont on avait déjà parlé avec @Akhilian et @hypernikao : le fait d'ajouter un test pour garantir qu'une évaluation ne dépasse jamais 20 questions. Je fais ça pour jeudi 17. |
On pourrait faire ça dans une autre PR mais je pense que c'est suffisamment minimal (genre ajout d'un if et d'un test) pour faire partie de cette PR. Et ce sera relativement transparent pour la validation fonctionnelle de Benjamin, et on est couverts par les tests. |
I've deployed this PR to http://improve-adaptive-tests.pix.beta.gouv.fr. Please check it out |
Why coverage fail :'( |
I've deployed this PR to http://improve-adaptive-tests.pix.beta.gouv.fr. Please check it out |
…n (front) (US-618). (#492) * Add snapshot route and controller * Register snapshot route to general routes container * Add unit test to snapshot index route * Add snapshots migration * Add model snapshot and test * Remove unused test in snapshot model * Add snapshot repository * Add new tested error : InvalidAuthorizationHeaders * Add test for snapshot repository * Update snapshot migration with constraint on organisationId * Update snapshot model with constraint on organisationId * Add new method isOrganizationIdExist to check organization id existence * Add new error * Add a tested snapshot service to format snapshot raw * Add test on organization repository * Add test on snapshot-repository * Fix spelling error on feedback-panel * delete useless snapshot unit test * Add new error * Refacto snapshot controller * Add knex delete to snapshot repository * Fix bug OrganizationRepository return a promise * isOrganizationIdExist should return a promise with a boolean * test after refacto * Add "success notification" view to share-profile modal + lots of component refactor * Fix test error * Complete share-profile modal behaviour (from here, missing call to API and styles) * Add user id field to snapshot migration * Refacto snapshot repository with unit test * Add relation with users in snapshot model * Add deserialization attributes on snapshot controller * Refacto snapshot repository wirh logicless * Add logic to snapshot-service,return an snapshot id * Remove useless const * Add new serialization package * Add snapshot serializer * Little refacto snapsho controller * Refacto snapshot service to extract user id from serialized profile * Add acceptance test to snapshot controller * Add Snapshot model in Ember (and Mirage) * Improve acceptance test by making an assertion on the store/db call * [CLEANUP] Ajout d'un nouveau package jsonapi-serializer et refactoring de la sérialisation de l'authentificaiton (#490) * Add new package jsonapi-serializer module * Refacto authentication serializer * Refacto snapshot controller * Refacto snapshot service * Fix snapshot repository from code review * fix lint * [#465] [FEATURE] Amélioration de la gestion des tests adaptatifs (US-604). (#465) * Add CAT from pix-the-cat * Remove scenarios * Handle end of test case * Make eslint happy * Make eslint happy II * Add AssessmentAdapter * Take into account code review remarks * Add tests for Set #union and #difference methods + rename *.spec.js files into *_test.js * Flattenized (via #reduce instead of forEach) CAT assessment model getters * Remove useless params * Make function less compact * Refactor API acceptance tests * Add two tests, 20-question limit * Remove useless file * refacto snapshot service, delete comments and use fatarrow * Add snapshot route and controller * Register snapshot route to general routes container * Add unit test to snapshot index route * Add snapshots migration * Add model snapshot and test * Remove unused test in snapshot model * Add snapshot repository * Add new tested error : InvalidAuthorizationHeaders * Add test for snapshot repository * Update snapshot migration with constraint on organisationId * Update snapshot model with constraint on organisationId * Add new method isOrganizationIdExist to check organization id existence * Add new error * Add a tested snapshot service to format snapshot raw * Add test on organization repository * Add test on snapshot-repository * delete useless snapshot unit test * Add new error * Refacto snapshot controller * Add knex delete to snapshot repository * Fix bug OrganizationRepository return a promise * isOrganizationIdExist should return a promise with a boolean * test after refacto * Fix test error * Add user id field to snapshot migration * Refacto snapshot repository with unit test * Add relation with users in snapshot model * Add deserialization attributes on snapshot controller * Refacto snapshot repository wirh logicless * Add logic to snapshot-service,return an snapshot id * Remove useless const * Add new serialization package * Add snapshot serializer * Little refacto snapsho controller * Refacto snapshot service to extract user id from serialized profile * Add acceptance test to snapshot controller * Refacto snapshot controller * Refacto snapshot service * Fix snapshot repository from code review * fix lint * refacto snapshot service, delete comments and use fatarrow * Fix spelling error on feedback-panel * Add "success notification" view to share-profile modal + lots of component refactor * Complete share-profile modal behaviour (from here, missing call to API and styles) * Add Snapshot model in Ember (and Mirage) * Improve acceptance test by making an assertion on the store/db call * Fix bug when connecting back and front * Add CSS styles * Fix tests * Refactor pix-modal CSS styles (mobile part first) * Add tablet and desktop support * Fix snapshot model test by adding organization model relation * fix test bug by replacing modal close button class * Update modale interligne * Fix skipped unit tests * Reduce margin in desktop * Take into account code remarks * Add a unit test on compte#shareProfileSnapshot
scenarios