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:
parent
4f25533230
commit
5bdaf2cf91
@ -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' });
|
||||
|
49
test/unit/routes/health-check.js
Normal file
49
test/unit/routes/health-check.js
Normal 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();
|
||||
});
|
||||
});
|
||||
});
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user