Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

Commit

Permalink
On expose un nouvel endpoint avec les infos api sur /api (#375)
Browse files Browse the repository at this point in the history
[#375] [FEATURE] On expose un nouvel endpoint avec les infos api sur /api (US-453).
  • Loading branch information
florianEnoh authored Apr 19, 2017
1 parent fe295b4 commit 547d19a
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 0 deletions.
15 changes: 15 additions & 0 deletions api/lib/application/healthcheck/healthcheck-controller.js
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
});
}


};

18 changes: 18 additions & 0 deletions api/lib/application/healthcheck/index.js
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'
};
1 change: 1 addition & 0 deletions api/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ server.register([
require('./lib/application/users'),
require('./lib/application/followers'),
require('./lib/application/feedbacks'),
require('./lib/application/healthcheck'),

/* Hapi plugins */
require('inert'),
Expand Down
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');
});
});
});
37 changes: 37 additions & 0 deletions api/tests/unit/application/healthcheck/index_test.js
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);
});
});

});

0 comments on commit 547d19a

Please sign in to comment.