mirror of
https://gitlab.com/mobicoop/v3/service/ad.git
synced 2026-03-25 03:45:51 +00:00
working version, with basic tests
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { MessagePublisher } from '@modules/health/infrastructure/message-publisher';
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { MessagePublisher } from '../../adapters/secondaries/message-publisher';
|
||||
import { MESSAGE_BROKER_PUBLISHER } from '../../../../app.constants';
|
||||
import { MESSAGE_BROKER_PUBLISHER } from '@src/app.constants';
|
||||
|
||||
const mockMessageBrokerPublisher = {
|
||||
publish: jest.fn().mockImplementation(),
|
||||
|
||||
@@ -1,19 +1,25 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { HealthCheckError, HealthIndicatorResult } from '@nestjs/terminus';
|
||||
import { RepositoriesHealthIndicatorUseCase } from '../../domain/usecases/repositories.health-indicator.usecase';
|
||||
import { AdsRepository } from '../../../ad/adapters/secondaries/ads.repository';
|
||||
import { RepositoriesHealthIndicatorUseCase } from '../../core/usecases/repositories.health-indicator.usecase';
|
||||
import { AD_REPOSITORY } from '@modules/health/health.di-tokens';
|
||||
import { MESSAGE_PUBLISHER } from '@src/app.constants';
|
||||
import { DatabaseErrorException } from '@libs/exceptions';
|
||||
|
||||
const mockAdsRepository = {
|
||||
const mockAdRepository = {
|
||||
healthCheck: jest
|
||||
.fn()
|
||||
.mockImplementationOnce(() => {
|
||||
return Promise.resolve(true);
|
||||
})
|
||||
.mockImplementation(() => {
|
||||
throw new Error('an error occured in the repository');
|
||||
throw new DatabaseErrorException('an error occured in the database');
|
||||
}),
|
||||
};
|
||||
|
||||
const mockMessagePublisher = {
|
||||
publish: jest.fn().mockImplementation(),
|
||||
};
|
||||
|
||||
describe('RepositoriesHealthIndicatorUseCase', () => {
|
||||
let repositoriesHealthIndicatorUseCase: RepositoriesHealthIndicatorUseCase;
|
||||
|
||||
@@ -22,8 +28,12 @@ describe('RepositoriesHealthIndicatorUseCase', () => {
|
||||
providers: [
|
||||
RepositoriesHealthIndicatorUseCase,
|
||||
{
|
||||
provide: AdsRepository,
|
||||
useValue: mockAdsRepository,
|
||||
provide: AD_REPOSITORY,
|
||||
useValue: mockAdRepository,
|
||||
},
|
||||
{
|
||||
provide: MESSAGE_PUBLISHER,
|
||||
useValue: mockMessagePublisher,
|
||||
},
|
||||
],
|
||||
}).compile();
|
||||
@@ -42,7 +52,6 @@ describe('RepositoriesHealthIndicatorUseCase', () => {
|
||||
it('should check health successfully', async () => {
|
||||
const healthIndicatorResult: HealthIndicatorResult =
|
||||
await repositoriesHealthIndicatorUseCase.isHealthy('repositories');
|
||||
|
||||
expect(healthIndicatorResult['repositories'].status).toBe('up');
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user