diff --git a/src/lib/routes/health-check.test.ts b/src/lib/routes/health-check.test.ts index 93a3c44a21..8378da8083 100644 --- a/src/lib/routes/health-check.test.ts +++ b/src/lib/routes/health-check.test.ts @@ -5,7 +5,6 @@ import { createTestConfig } from '../../test/config/test-config'; import createStores from '../../test/fixtures/store'; import getLogger from '../../test/fixtures/no-logger'; import getApp from '../app'; -import { IUnleashStores } from '../types'; async function getSetup() { const stores = createStores(); @@ -25,12 +24,10 @@ async function getSetup() { } let request; let destroy; -let stores; beforeEach(async () => { const setup = await getSetup(); request = setup.request; destroy = setup.destroy; - stores = setup.stores; }); afterEach(() => { @@ -38,45 +35,13 @@ afterEach(() => { getLogger.setMuteError(false); }); -test('should give 500 when db is failing', async () => { - jest.spyOn(global.console, 'error').mockImplementation(() => jest.fn()); - const config = createTestConfig(); - const failingStores: Partial = { - // @ts-ignore - featureTypeStore: { - getAll: () => Promise.reject(new Error('db error')), - }, - clientMetricsStore: { - // @ts-ignore - on: () => {}, - }, - }; - // @ts-ignore - const services = createServices(failingStores, config); - // @ts-ignore - const app = await getApp(createTestConfig(), failingStores, services); - request = supertest(app); - getLogger.setMuteError(true); - expect.assertions(2); - stores.featureToggleStore.getAll = () => - Promise.reject(new Error('db error')); - return request - .get('/health') - .expect(500) - .expect((res) => { - expect(res.status).toBe(500); - expect(res.body.health).toBe('BAD'); - }); +test('should give 200 when ready', async () => { + await request.get('/health').expect(200); }); -test('should give 200 when db is not failing', () => { - expect.assertions(0); - return request.get('/health').expect(200); -}); - -test('should give health=GOOD when db is not failing', () => { +test('should give health=GOOD when ready', async () => { expect.assertions(2); - return request + await request .get('/health') .expect(200) .expect((res) => { diff --git a/src/lib/routes/health-check.ts b/src/lib/routes/health-check.ts index b6be7da184..1ff41c6201 100644 --- a/src/lib/routes/health-check.ts +++ b/src/lib/routes/health-check.ts @@ -2,7 +2,6 @@ import { Request, Response } from 'express'; import { IUnleashConfig } from '../types/option'; import { IUnleashServices } from '../types/services'; import { Logger } from '../logger'; -import HealthService from '../services/health-service'; import { OpenApiService } from '../services/openapi-service'; import Controller from './controller'; @@ -15,19 +14,13 @@ export class HealthCheckController extends Controller { private openApiService: OpenApiService; - private healthService: HealthService; - constructor( config: IUnleashConfig, - { - healthService, - openApiService, - }: Pick, + { openApiService }: Pick, ) { super(config); this.logger = config.getLogger('health-check.js'); this.openApiService = openApiService; - this.healthService = healthService; this.route({ method: 'get', @@ -51,12 +44,6 @@ export class HealthCheckController extends Controller { _: Request, res: Response, ): Promise { - try { - await this.healthService.dbIsUp(); - res.status(200).json({ health: 'GOOD' }); - } catch (e) { - this.logger.error('Could not select from features, error was: ', e); - res.status(500).json({ health: 'BAD' }); - } + res.status(200).json({ health: 'GOOD' }); } }