1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/src/lib/routes/health-check.test.js
Christopher Kolstad 240c6a77a1
Feat/options need types (#794)
feat: options are now typed

- This makes it easier to know what to send to unleash.start / unleash.create
- Using a Partial to instantiate the config, then melding it with defaults to get a config object with all fields set either to their defaults or to whatever is passed in.


Co-authored-by: Fredrik Strand Oseberg <fredrik.no@gmail.com>
Co-authored-by: Ivar Conradi Østhus <ivarconr@gmail.com>
2021-04-22 10:07:10 +02:00

69 lines
1.7 KiB
JavaScript

'use strict';
import { createServices } from '../services';
import { createTestConfig } from '../../test/config/test-config';
const test = require('ava');
const supertest = require('supertest');
const { EventEmitter } = require('events');
const store = require('../../test/fixtures/store');
const getLogger = require('../../test/fixtures/no-logger');
const getApp = require('../app');
const eventBus = new EventEmitter();
function getSetup() {
const stores = store.createStores();
const { db } = stores;
const config = createTestConfig();
const app = getApp(
config,
stores,
createServices(stores, config),
eventBus,
);
return {
db,
request: supertest(app),
};
}
test.afterEach(() => {
getLogger.setMuteError(false);
});
test('should give 500 when db is failing', t => {
getLogger.setMuteError(true);
t.plan(2);
const { request, db } = getSetup();
db.raw = () => Promise.reject(new Error('db error'));
return request
.get('/health')
.expect(500)
.expect(res => {
t.true(res.status === 500);
t.true(res.body.health === 'BAD');
});
});
test('should give 200 when db is not failing', t => {
t.plan(0);
const { request, db } = getSetup();
db.raw = () => Promise.resolve();
return request.get('/health').expect(200);
});
test('should give health=GOOD when db is not failing', t => {
t.plan(2);
const { request, db } = getSetup();
db.raw = () => Promise.resolve();
return request
.get('/health')
.expect(200)
.expect(res => {
t.true(res.status === 200);
t.true(res.body.health === 'GOOD');
});
});