mirror of
https://gitlab.com/mobicoop/v3/service/ad.git
synced 2026-03-25 03:45:51 +00:00
fixed queryRaw for healthcheck, added health grpc controller test
This commit is contained in:
72
src/modules/health/tests/unit/health.grpc.controller.spec.ts
Normal file
72
src/modules/health/tests/unit/health.grpc.controller.spec.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
import { RepositoriesHealthIndicatorUseCase } from '@modules/health/core/usecases/repositories.health-indicator.usecase';
|
||||
import {
|
||||
HealthGrpcController,
|
||||
ServingStatus,
|
||||
} from '@modules/health/interface/grpc-controllers/health.grpc.controller';
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
|
||||
const mockRepositoriesHealthIndicatorUseCase = {
|
||||
isHealthy: jest
|
||||
.fn()
|
||||
.mockImplementationOnce(() => ({
|
||||
repositories: {
|
||||
status: 'up',
|
||||
},
|
||||
}))
|
||||
.mockImplementationOnce(() => ({
|
||||
repositories: {
|
||||
status: 'down',
|
||||
},
|
||||
})),
|
||||
};
|
||||
|
||||
describe('Health Grpc Controller', () => {
|
||||
let healthGrpcController: HealthGrpcController;
|
||||
|
||||
beforeAll(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [
|
||||
{
|
||||
provide: RepositoriesHealthIndicatorUseCase,
|
||||
useValue: mockRepositoriesHealthIndicatorUseCase,
|
||||
},
|
||||
HealthGrpcController,
|
||||
],
|
||||
}).compile();
|
||||
|
||||
healthGrpcController =
|
||||
module.get<HealthGrpcController>(HealthGrpcController);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(healthGrpcController).toBeDefined();
|
||||
});
|
||||
|
||||
it('should return a Serving status ', async () => {
|
||||
jest.spyOn(mockRepositoriesHealthIndicatorUseCase, 'isHealthy');
|
||||
const servingStatus: { status: ServingStatus } =
|
||||
await healthGrpcController.check();
|
||||
expect(servingStatus).toEqual({
|
||||
status: ServingStatus.SERVING,
|
||||
});
|
||||
expect(
|
||||
mockRepositoriesHealthIndicatorUseCase.isHealthy,
|
||||
).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should return a Not Serving status ', async () => {
|
||||
jest.spyOn(mockRepositoriesHealthIndicatorUseCase, 'isHealthy');
|
||||
const servingStatus: { status: ServingStatus } =
|
||||
await healthGrpcController.check();
|
||||
expect(servingStatus).toEqual({
|
||||
status: ServingStatus.NOT_SERVING,
|
||||
});
|
||||
expect(
|
||||
mockRepositoriesHealthIndicatorUseCase.isHealthy,
|
||||
).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user