1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-04-01 01:18:10 +02:00

Add unit-test for /health route

This commit is contained in:
ivaosthu 2016-11-11 16:24:16 +01:00
parent 4f25533230
commit 5bdaf2cf91
3 changed files with 61 additions and 4 deletions

View File

@ -6,9 +6,7 @@ module.exports = function (app, config) {
app.get('/health', (req, res) => {
config.stores.db.select(1)
.from('features')
.then(() => {
res.json({ health: 'GOOD' });
})
.then(() => res.json({ health: 'GOOD' }))
.catch(err => {
logger.error('Could not select from features, error was: ', err);
res.status(500).json({ health: 'BAD' });

View File

@ -0,0 +1,49 @@
'use strict';
const store = require('./mocks/store');
const supertest = require('supertest');
const assert = require('assert');
const sinon = require('sinon');
let request;
let db;
describe('Unit: The health cheack api', () => {
beforeEach(done => {
const stores = store.createStores();
db = stores.db;
const app = require('../../../app')({
baseUriPath: '',
stores: stores,
});
request = supertest(app);
done();
});
it('should give 500 when db is failing', (done) => {
db.select = () => from = () => Promise.reject();
request
.get('/health')
.expect(500, done);
});
it('should give 200 when db is not failing', (done) => {
request
.get('/health')
.expect(200, done)
});
it('should give health=GOOD when db is not failing', (done) => {
request
.get('/health')
.expect(200)
.end((err, res) => {
assert.equal(res.status, 200)
assert.equal(res.body.health, 'GOOD');
done();
});
});
});

View File

@ -6,8 +6,18 @@ const clientInstanceStore = require('./fake-client-instance-store');
const featureToggleStore = require('./fake-feature-toggle-store');
const strategyStore = require('./fake-strategies-store');
module.exports = {
createStores: () => {
const db = {
select: () => {
return {
from: () => Promise.resolve()
}
}
}
clientMetricsStore.reset();
clientStrategyStore.reset();
clientInstanceStore.reset();
@ -15,7 +25,7 @@ module.exports = {
strategyStore.reset();
return {
db: sinon.stub(),
db,
clientMetricsStore,
clientStrategyStore,
clientInstanceStore,