working version, with basic tests

This commit is contained in:
sbriat
2023-06-21 11:50:36 +02:00
parent e1989c0a52
commit b232247c93
43 changed files with 217 additions and 1060 deletions

View File

@@ -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(),

View File

@@ -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');
});