Skip to content

Commit

Permalink
Affiche lien pour consulter document
Browse files Browse the repository at this point in the history
  • Loading branch information
egaillot committed Nov 2, 2024
1 parent 834db5d commit d3e4e26
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 4 deletions.
2 changes: 2 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"dependencies": {
"axios": "^1.7.4",
"body-parser": "^1.20.3",
"cookie-session": "^2.1.0",
"diary": "^0.4.5",
"express": "^4.21.0",
Expand Down
8 changes: 8 additions & 0 deletions src/api/documentRecu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const documentRecu = (depotDonnees, reponse) => depotDonnees
.documentRecu()
.then((document) => {
reponse.set({ 'content-type': 'application/pdf; charset=utf-8' });
reponse.send(document);
});

module.exports = documentRecu;
7 changes: 6 additions & 1 deletion src/depotDonnees.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class DepotDonnees {
return Promise.resolve();
}

documentRecu() {
return Promise.resolve(this.donnees.document);
}

reinitialiseRecuperationDocument() {
this.donnees.statutRecuperationDocument = StatutRecuperationDocument.INITIAL;
return Promise.resolve();
Expand All @@ -20,7 +24,8 @@ class DepotDonnees {
return Promise.resolve(new StatutRecuperationDocument(this.donnees.statutRecuperationDocument));
}

termineRecuperationDocument() {
termineRecuperationDocument(document) {
this.donnees.document = document;
this.donnees.statutRecuperationDocument = StatutRecuperationDocument.TERMINE;
return Promise.resolve();
}
Expand Down
4 changes: 4 additions & 0 deletions src/routes/routesBase.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const express = require('express');

const documentRecu = require('../api/documentRecu');

const routesBase = (config) => {
const {
adaptateurEnvironnement,
Expand All @@ -23,6 +25,8 @@ const routesBase = (config) => {
},
);

routes.get('/documentRecu', (requete, reponse) => documentRecu(depotDonnees, reponse));

return routes;
};

Expand Down
2 changes: 1 addition & 1 deletion src/routes/routesOOTS.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const routesOOTS = (config) => {

routes.post('/document', (requete, reponse) => {
if (adaptateurEnvironnement.avecOOTS()) {
depotDonnees.termineRecuperationDocument()
depotDonnees.termineRecuperationDocument(Buffer.from(requete.body.document))
.then(() => reponse.send());
} else {
reponse.status(501).send('Not Implemented Yet!');
Expand Down
3 changes: 3 additions & 0 deletions src/siteVitrine.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const bodyParser = require('body-parser');
const cookieSession = require('cookie-session');
const express = require('express');

Expand All @@ -18,6 +19,8 @@ const creeServeur = (config) => {
let serveur;
const app = express();

app.use(bodyParser.json());

app.set('trust proxy', 1);

app.set('views', './src/vues');
Expand Down
2 changes: 1 addition & 1 deletion src/vues/accueil.pug
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ block page
if statut.estEnCours()
p Document en cours de récupération
if statut.estTermine()
p Document récupéré !
p Document récupéré ! #[a(href = '/documentRecu') (consulter le document)]
br

a(href = '/auth/fcplus/destructionSession') Déconnexion
Expand Down
32 changes: 32 additions & 0 deletions test/api/documentRecu.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const documentRecu = require('../../src/api/documentRecu');

describe('Le requêteur du document reçu', () => {
const depotDonnees = {};
const reponse = {};

beforeEach(() => {
depotDonnees.documentRecu = () => Promise.resolve(Buffer.from(''));
reponse.set = () => {};
reponse.send = () => {};
});

it('demande le document au dépôt de donnés', () => {
let depotDonneesAppele = false;
depotDonnees.documentRecu = () => {
depotDonneesAppele = true;
return Promise.resolve(Buffer.from(''));
};

return documentRecu(depotDonnees, reponse)
.then(() => expect(depotDonneesAppele).toBe(true));
});

it('renvoie le document reçu', () => {
expect.assertions(1);

depotDonnees.documentRecu = () => Promise.resolve(Buffer.from('Un document'));
reponse.send = (document) => expect(document.toString()).toBe('Un document');

return documentRecu(depotDonnees, reponse);
});
});
10 changes: 10 additions & 0 deletions test/depotDonnees.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ describe('Le dépôt de données', () => {
.then((statut) => expect(statut.estTermine()).toBe(true));
});

it('conserve le document reçu', () => {
const depot = new DepotDonnees({
statutRecuperationDocument: StatutRecuperationDocument.EN_COURS,
});

return depot.termineRecuperationDocument(Buffer.from('Un document'))
.then(() => depot.documentRecu())
.then((buffer) => expect(buffer.toString()).toBe('Un document'));
});

it('repasse le statut de récupération de document à « initial »', () => {
const depot = new DepotDonnees({
statutRecuperationDocument: StatutRecuperationDocument.EN_COURS,
Expand Down
12 changes: 11 additions & 1 deletion test/routes/routesOOTS.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,20 @@ describe('le serveur des routes `/oots/document`', () => {
return Promise.resolve();
};

return axios.post(`http://localhost:${port}/oots/document`)
return axios.post(`http://localhost:${port}/oots/document`, { document: Buffer.from('') })
.then(() => expect(depotDonneesAppele).toBe(true))
.catch(leveErreur);
});

it('conserve le document reçu', () => {
serveur.depotDonnees().termineRecuperationDocument = (document) => {
expect(document.toString()).toBe('Un document');
return Promise.resolve();
};

return axios.post(`http://localhost:${port}/oots/document`, { document: Buffer.from('Un document') })
.catch(leveErreur);
});
});

describe('sur GET /oots/callback', () => {
Expand Down

0 comments on commit d3e4e26

Please sign in to comment.