Skip to content

Commit

Permalink
Affiche statut récupération lorsque récupération terminée
Browse files Browse the repository at this point in the history
Co-authored-by: Emmanuel Gaillot <[email protected]>
  • Loading branch information
Fabinout and egaillot committed Sep 3, 2024
1 parent 3d8201b commit 1a9a712
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/depotDonnees.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ class DepotDonnees {
statutRecuperationDocument() {
return Promise.resolve(new StatutRecuperationDocument(this.donnees.statutRecuperationDocument));
}

termineRecuperationDocument() {
this.donnees.statutRecuperationDocument = StatutRecuperationDocument.TERMINE;
return Promise.resolve();
}
}

module.exports = DepotDonnees;
10 changes: 6 additions & 4 deletions src/modeles/statutRecuperationDocument.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
const STATUTS = {
EN_COURS: 'enCours',
INITIAL: 'initial',
TERMINE: 'termine',
};

class StatutRecuperationDocument {
constructor(statut) {
this.statut = statut || STATUTS.INITIAL;
}

deviensEnCours() {
this.statut = STATUTS.EN_COURS;
}

estEnCours() {
return this.statut === STATUTS.EN_COURS;
}

estInitial() {
return this.statut === STATUTS.INITIAL;
}

estTermine() {
return this.statut === STATUTS.TERMINE;
}
}

Object.assign(StatutRecuperationDocument, STATUTS);
StatutRecuperationDocument.enCours = () => new StatutRecuperationDocument(STATUTS.EN_COURS);
StatutRecuperationDocument.termine = () => new StatutRecuperationDocument(STATUTS.TERMINE);

module.exports = StatutRecuperationDocument;
9 changes: 9 additions & 0 deletions src/routes/routesOOTS.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ const routesOOTS = (config) => {
}
});

routes.post('/document', (requete, reponse) => {
if (adaptateurEnvironnement.avecOOTS()) {
depotDonnees.termineRecuperationDocument()
.then(() => reponse.send());
} else {
reponse.status(501).send('Not Implemented Yet!');
}
});

return routes;
};

Expand Down
2 changes: 2 additions & 0 deletions src/vues/accueil.pug
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ block page
a(href = '/oots/document') Récupérer un document par OOTS
if statut.estEnCours()
p Document en cours de récupération
if statut.estTermine()
p Document récupéré !
br

a(href = '/auth/fcplus/destructionSession') Déconnexion
Expand Down
11 changes: 11 additions & 0 deletions test/depotDonnees.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const DepotDonnees = require('../src/depotDonnees');
const StatutRecuperationDocument = require('../src/modeles/statutRecuperationDocument');

describe('Le dépôt de données', () => {
it('initialise le dépot de données avec un statut de récupération de document initial', () => {
Expand All @@ -13,4 +14,14 @@ describe('Le dépôt de données', () => {
.then(() => depot.statutRecuperationDocument())
.then((statut) => expect(statut.estEnCours()).toBe(true));
});

it('passe le statut de récupération de document à « terminé »', () => {
const depot = new DepotDonnees({
statutRecuperationDocument: StatutRecuperationDocument.EN_COURS,
});

return depot.termineRecuperationDocument()
.then(() => depot.statutRecuperationDocument())
.then((statut) => expect(statut.estTermine()).toBe(true));
});
});
12 changes: 12 additions & 0 deletions test/routes/routesBase.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ describe('Le serveur des routes `/`', () => {
})
.catch(leveErreur);
});

it('affiche lorsque le document a été récupéré', () => {
serveur.depotDonnees().statutRecuperationDocument = () => (
Promise.resolve(StatutRecuperationDocument.termine())
);

return axios.get(`http://localhost:${port}/`)
.then((reponse) => {
expect(reponse.data).toContain('Document récupéré !');
})
.catch(leveErreur);
});
});
});
});
25 changes: 25 additions & 0 deletions test/routes/routesOOTS.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,29 @@ describe('le serveur des routes `/oots/document`', () => {
});
});
});

describe('sur POST /oots/document', () => {
it('lève une erreur (501) not implemented si la fonctionnalité est désactivée', () => {
expect.assertions(2);
serveur.adaptateurEnvironnement().avecOOTS = () => false;

return axios.post(`http://localhost:${port}/oots/document`)
.catch(({ response }) => {
expect(response.status).toEqual(501);
expect(response.data).toEqual('Not Implemented Yet!');
});
});

it('met à jour le statut de récupération du document', () => {
let depotDonneesAppele = false;
serveur.depotDonnees().termineRecuperationDocument = () => {
depotDonneesAppele = true;
return Promise.resolve();
};

return axios.post(`http://localhost:${port}/oots/document`)
.then(() => expect(depotDonneesAppele).toBe(true))
.catch(leveErreur);
});
});
});
1 change: 1 addition & 0 deletions test/routes/serveurTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const serveurTest = () => {
depotDonnees = {
demarreRecuperationDocument: () => Promise.resolve(),
statutRecuperationDocument: () => Promise.resolve(new StatutRecuperationDocument()),
termineRecuperationDocument: () => Promise.resolve(),
};

fabriqueSessionFCPlus = {
Expand Down

0 comments on commit 1a9a712

Please sign in to comment.