35 lines
1.0 KiB
TypeScript
35 lines
1.0 KiB
TypeScript
import { INestApplication } from '@nestjs/common';
|
|
import { Test, TestingModule } from '@nestjs/testing';
|
|
import request, { Response } from 'supertest';
|
|
import { AppModule } from '../src/app.module';
|
|
import { HealthStatus } from '../src/modules/health/health.service';
|
|
|
|
describe('HealthController (e2e)', () => {
|
|
let app: INestApplication;
|
|
|
|
beforeAll(async () => {
|
|
const moduleFixture: TestingModule = await Test.createTestingModule({
|
|
imports: [AppModule],
|
|
}).compile();
|
|
|
|
app = moduleFixture.createNestApplication();
|
|
await app.init();
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await app.close();
|
|
});
|
|
|
|
it('GET /health retorna 200 com status da API e do banco', () => {
|
|
return request(app.getHttpServer() as Parameters<typeof request>[0])
|
|
.get('/health')
|
|
.expect(200)
|
|
.expect((res: Response) => {
|
|
const body = res.body as HealthStatus;
|
|
expect(body.status).toBeDefined();
|
|
expect(body.database).toBeDefined();
|
|
expect(body.timestamp).toBeDefined();
|
|
});
|
|
});
|
|
});
|