This repository has been archived by the owner on Mar 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
On expose un nouvel endpoint avec les infos api sur /api (#375)
[#375] [FEATURE] On expose un nouvel endpoint avec les infos api sur /api (US-453).
- Loading branch information
1 parent
fe295b4
commit 547d19a
Showing
5 changed files
with
97 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const packageJSON = require('../../../package.json'); | ||
module.exports = { | ||
|
||
get(request, reply) { | ||
|
||
reply({ | ||
'name': packageJSON.name, | ||
'version': packageJSON.version, | ||
'description': packageJSON.description | ||
}); | ||
} | ||
|
||
|
||
}; | ||
|
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,18 @@ | ||
const healthcheckController = require('./healthcheck-controller'); | ||
exports.register = function (server, options, next) { | ||
|
||
server.route([ | ||
{ | ||
method: 'GET', | ||
path: '/api', | ||
config: {handler: healthcheckController.get, tags: ['api']} | ||
}, | ||
]); | ||
|
||
return next(); | ||
}; | ||
|
||
exports.register.attributes = { | ||
name: 'healthcheck-api', | ||
version: '1.0.0' | ||
}; |
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
26 changes: 26 additions & 0 deletions
26
api/tests/unit/application/healthcheck/healthcheck-controller_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,26 @@ | ||
const {describe, it, expect, sinon} = require('../../../test-helper'); | ||
|
||
const healthcheckController = require('../../../../lib/application/healthcheck/healthcheck-controller'); | ||
|
||
describe('Unit | Controller | healthcheckController', () => { | ||
|
||
describe('#get', () => { | ||
it('should provide get method', () => { | ||
expect(healthcheckController.get).to.exist; | ||
}); | ||
|
||
it('should reply with the API description', function () { | ||
// given | ||
const replySpy = sinon.spy(); | ||
|
||
// when | ||
healthcheckController.get(null, replySpy); | ||
|
||
// then | ||
const arguments = replySpy.firstCall.args[0]; | ||
expect(arguments).to.include.keys('name', 'version', 'description'); | ||
expect(arguments['name']).to.equal('pix-api'); | ||
expect(arguments['description']).to.equal('Plateforme d\'évaluation et de certification des compétences numériques à l\'usage de tous les citoyens francophones'); | ||
}); | ||
}); | ||
}); |
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,37 @@ | ||
const {describe, it, expect, before, beforeEach, after, sinon} = require('../../../test-helper'); | ||
const Hapi = require('hapi'); | ||
const healthcheckController = require('../../../../lib/application/healthcheck/healthcheck-controller'); | ||
|
||
describe('Unit | Router | HealthcheckRouter', function () { | ||
|
||
let server; | ||
|
||
beforeEach(function () { | ||
server = this.server = new Hapi.Server(); | ||
server.connection({port: null}); | ||
server.register({register: require('../../../../lib/application/healthcheck')}); | ||
}); | ||
|
||
function expectRouteToExist(routeOptions, done) { | ||
server.inject(routeOptions, (res) => { | ||
expect(res.statusCode).to.equal(200); | ||
done(); | ||
}); | ||
} | ||
|
||
describe('GET /api', function () { | ||
|
||
before(function () { | ||
sinon.stub(healthcheckController, 'get', (request, reply) => reply('ok')); | ||
}); | ||
|
||
after(function () { | ||
healthcheckController.get.restore(); | ||
}); | ||
|
||
it('should exist', function (done) { | ||
return expectRouteToExist({method: 'GET', url: '/api'}, done); | ||
}); | ||
}); | ||
|
||
}); |