53 lines
1.5 KiB
TypeScript
53 lines
1.5 KiB
TypeScript
import { Test, TestingModule } from '@nestjs/testing';
|
|
import { INestApplication } from '@nestjs/common';
|
|
import * as request from 'supertest';
|
|
import { AppModule } from '../../src/app.module';
|
|
|
|
describe('Health API (E2E)', () => {
|
|
let app: INestApplication;
|
|
|
|
beforeAll(async () => {
|
|
const moduleFixture: TestingModule = await Test.createTestingModule({
|
|
imports: [AppModule],
|
|
}).compile();
|
|
|
|
app = moduleFixture.createNestApplication();
|
|
app.setGlobalPrefix('api/v1');
|
|
|
|
await app.init();
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await app.close();
|
|
});
|
|
|
|
describe('GET /api/v1/health', () => {
|
|
it('should return health status', async () => {
|
|
const response = await request(app.getHttpServer())
|
|
.get('/api/v1/health')
|
|
.expect(200);
|
|
|
|
expect(response.body).toHaveProperty('status');
|
|
expect(response.body.status).toBe('ok');
|
|
});
|
|
|
|
it('should return service name', async () => {
|
|
const response = await request(app.getHttpServer())
|
|
.get('/api/v1/health')
|
|
.expect(200);
|
|
|
|
expect(response.body).toHaveProperty('service');
|
|
expect(response.body.service).toBe('presence-service');
|
|
});
|
|
|
|
it('should return timestamp', async () => {
|
|
const response = await request(app.getHttpServer())
|
|
.get('/api/v1/health')
|
|
.expect(200);
|
|
|
|
expect(response.body).toHaveProperty('timestamp');
|
|
expect(new Date(response.body.timestamp).getTime()).not.toBeNaN();
|
|
});
|
|
});
|
|
});
|