Skip to content

Commit

Permalink
Appelles la nouvelle API de compétences fortes
Browse files Browse the repository at this point in the history
  • Loading branch information
etienneCharignon authored and mdomine committed Mar 1, 2021
1 parent 1ba9751 commit 85b7595
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/situations/accueil/modeles/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function creeStore (registreUtilisateur, fetch = window.fetch) {
});
},
synchroniseCompetencesFortes ({ commit }) {
return fetch(registreUtilisateur.urlEvaluation())
return fetch(registreUtilisateur.urlEvaluation('competences_fortes'))
.then((reponse) => {
if (reponse.status === 404) {
commit('deconnecte');
Expand Down
5 changes: 3 additions & 2 deletions src/situations/commun/infra/registre_utilisateur.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ export default class RegistreUtilisateur extends EventEmitter {
});
}

urlEvaluation () {
return `${this.urlServeur}/api/evaluations/${this.idEvaluation()}.json`;
urlEvaluation (element = '') {
if (element.length > 0) { element = `/${element}`; }
return `${this.urlServeur}/api/evaluations/${this.idEvaluation()}${element}.json`;
}

estConnecte () {
Expand Down
9 changes: 6 additions & 3 deletions tests/situations/accueil/modeles/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe("Le store de l'accueil", function () {
const fetch = (url) => Promise.resolve({
json: () => {
const situation = { nom_technique: 'nom_technique', libelle: 'libelle' };
return { situations: [situation], competences_fortes: [] };
return { situations: [situation] };
}
});
const store = creeStore(registreUtilisateur, fetch);
Expand Down Expand Up @@ -117,10 +117,13 @@ describe("Le store de l'accueil", function () {
});

it('sait récupérer les deux compétences fortes depuis le serveur', function () {
registreUtilisateur.urlEvaluation = () => '/evaluation/1';
registreUtilisateur.urlEvaluation = (element) => {
expect(element).to.eql('competences_fortes');
return '/evaluation/1/competences_fortes.json';
};
const fetch = (url) => Promise.resolve({
json: () => {
return { situations: [], competences_fortes: ['comprehension_consigne', 'rapidite', 'tri'] };
return { competences_fortes: ['comprehension_consigne', 'rapidite', 'tri'] };
}
});
const store = creeStore(registreUtilisateur, fetch);
Expand Down
8 changes: 8 additions & 0 deletions tests/situations/commun/infra/registre_utilisateur.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,12 @@ describe('le registre utilisateur', function () {
expect(registre.urlEvaluation()).to.eql('http://localhost/api/evaluations/1.json');
});
});

it("retourne l'url d'un élément d'une évaluation", function () {
const registre = unRegistre(1, 'test', 'http://localhost');
return registre.inscris('test').then(() => {
expect(registre.urlEvaluation('competences_fortes'))
.to.eql('http://localhost/api/evaluations/1/competences_fortes.json');
});
});
});

0 comments on commit 85b7595

Please sign in to comment.