mirror of
https://gitlab.com/mobicoop/v3/service/auth.git
synced 2026-03-24 11:05:49 +00:00
use health package
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
export const AUTH_MESSAGE_PUBLISHER = Symbol('AUTH_MESSAGE_PUBLISHER');
|
||||
export const AUTHENTICATION_REPOSITORY = Symbol('AUTHENTICATION_REPOSITORY');
|
||||
export const USERNAME_REPOSITORY = Symbol('USERNAME_REPOSITORY');
|
||||
|
||||
@@ -3,6 +3,7 @@ import { CreateAuthenticationGrpcController } from './interface/grpc-controllers
|
||||
import { CreateAuthenticationService } from './core/application/commands/create-authentication/create-authentication.service';
|
||||
import { AuthenticationMapper } from './authentication.mapper';
|
||||
import {
|
||||
AUTH_MESSAGE_PUBLISHER,
|
||||
AUTHENTICATION_REPOSITORY,
|
||||
USERNAME_REPOSITORY,
|
||||
} from './authentication.di-tokens';
|
||||
@@ -11,7 +12,6 @@ import { PrismaService } from './infrastructure/prisma.service';
|
||||
import { CqrsModule } from '@nestjs/cqrs';
|
||||
import { DeleteAuthenticationGrpcController } from './interface/grpc-controllers/delete-authentication.grpc.controller';
|
||||
import { DeleteAuthenticationService } from './core/application/commands/delete-authentication/delete-authentication.service';
|
||||
import { MESSAGE_PUBLISHER } from '@src/app.di-tokens';
|
||||
import { MessageBrokerPublisher } from '@mobicoop/message-broker-module';
|
||||
import { UsernameRepository } from './infrastructure/username.repository';
|
||||
import { UsernameMapper } from './username.mapper';
|
||||
@@ -64,10 +64,10 @@ const repositories: Provider[] = [
|
||||
},
|
||||
];
|
||||
|
||||
const messageBrokers: Provider[] = [
|
||||
const messagePublishers: Provider[] = [
|
||||
{
|
||||
provide: MESSAGE_PUBLISHER,
|
||||
useClass: MessageBrokerPublisher,
|
||||
provide: AUTH_MESSAGE_PUBLISHER,
|
||||
useExisting: MessageBrokerPublisher,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -82,7 +82,7 @@ const orms: Provider[] = [PrismaService];
|
||||
...queryHandlers,
|
||||
...mappers,
|
||||
...repositories,
|
||||
...messageBrokers,
|
||||
...messagePublishers,
|
||||
...orms,
|
||||
],
|
||||
exports: [
|
||||
|
||||
@@ -9,7 +9,7 @@ import { AuthenticationEntity } from '../core/domain/authentication.entity';
|
||||
import { AuthenticationRepositoryPort } from '../core/application/ports/authentication.repository.port';
|
||||
import { PrismaService } from './prisma.service';
|
||||
import { AuthenticationMapper } from '../authentication.mapper';
|
||||
import { MESSAGE_PUBLISHER } from '@src/app.di-tokens';
|
||||
import { AUTH_MESSAGE_PUBLISHER } from '../authentication.di-tokens';
|
||||
|
||||
type AuthenticationBaseModel = {
|
||||
uuid: string;
|
||||
@@ -49,7 +49,7 @@ export class AuthenticationRepository
|
||||
prisma: PrismaService,
|
||||
mapper: AuthenticationMapper,
|
||||
eventEmitter: EventEmitter2,
|
||||
@Inject(MESSAGE_PUBLISHER)
|
||||
@Inject(AUTH_MESSAGE_PUBLISHER)
|
||||
protected readonly messagePublisher: MessagePublisherPort,
|
||||
) {
|
||||
super(
|
||||
|
||||
@@ -6,11 +6,11 @@ import {
|
||||
PrismaRepositoryBase,
|
||||
} from '@mobicoop/ddd-library';
|
||||
import { PrismaService } from './prisma.service';
|
||||
import { MESSAGE_PUBLISHER } from '@src/app.di-tokens';
|
||||
import { UsernameEntity } from '../core/domain/username.entity';
|
||||
import { UsernameRepositoryPort } from '../core/application/ports/username.repository.port';
|
||||
import { UsernameMapper } from '../username.mapper';
|
||||
import { Type } from '../core/domain/username.types';
|
||||
import { AUTH_MESSAGE_PUBLISHER } from '../authentication.di-tokens';
|
||||
|
||||
type UsernameBaseModel = {
|
||||
username: string;
|
||||
@@ -41,7 +41,7 @@ export class UsernameRepository
|
||||
prisma: PrismaService,
|
||||
mapper: UsernameMapper,
|
||||
eventEmitter: EventEmitter2,
|
||||
@Inject(MESSAGE_PUBLISHER)
|
||||
@Inject(AUTH_MESSAGE_PUBLISHER)
|
||||
protected readonly messagePublisher: MessagePublisherPort,
|
||||
) {
|
||||
super(
|
||||
|
||||
@@ -5,7 +5,6 @@ import { PrismaService } from '@modules/authentication/infrastructure/prisma.ser
|
||||
import { AuthenticationRepository } from '@modules/authentication/infrastructure/authentication.repository';
|
||||
import { AuthenticationMapper } from '@modules/authentication/authentication.mapper';
|
||||
import { EventEmitterModule } from '@nestjs/event-emitter';
|
||||
import { MESSAGE_PUBLISHER } from '@src/app.di-tokens';
|
||||
import {
|
||||
DatabaseErrorException,
|
||||
NotFoundException,
|
||||
@@ -14,6 +13,7 @@ import {
|
||||
import { AuthenticationEntity } from '@modules/authentication/core/domain/authentication.entity';
|
||||
import { Type } from '@modules/authentication/core/domain/username.types';
|
||||
import { CreateAuthenticationProps } from '@modules/authentication/core/domain/authentication.types';
|
||||
import { AUTH_MESSAGE_PUBLISHER } from '@modules/authentication/authentication.di-tokens';
|
||||
|
||||
const uuid = '165192d4-398a-4469-a16b-98c02cc6f531';
|
||||
|
||||
@@ -42,17 +42,6 @@ describe('AuthenticationRepository', () => {
|
||||
let prismaService: PrismaService;
|
||||
let authenticationRepository: AuthenticationRepository;
|
||||
|
||||
// const createAuthentications = async (nbToCreate = 10) => {
|
||||
// for (let i = 0; i < nbToCreate; i++) {
|
||||
// await prismaService.auth.create({
|
||||
// data: {
|
||||
// uuid: v4(),
|
||||
// password: bcrypt.hashSync(`password-${i}`, 10),
|
||||
// },
|
||||
// });
|
||||
// }
|
||||
// };
|
||||
|
||||
beforeAll(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
imports: [EventEmitterModule.forRoot()],
|
||||
@@ -61,7 +50,7 @@ describe('AuthenticationRepository', () => {
|
||||
PrismaService,
|
||||
AuthenticationMapper,
|
||||
{
|
||||
provide: MESSAGE_PUBLISHER,
|
||||
provide: AUTH_MESSAGE_PUBLISHER,
|
||||
useValue: mockMessagePublisher,
|
||||
},
|
||||
],
|
||||
@@ -84,30 +73,6 @@ describe('AuthenticationRepository', () => {
|
||||
await prismaService.auth.deleteMany();
|
||||
});
|
||||
|
||||
// describe('findAll', () => {
|
||||
// it('should return an empty data array', async () => {
|
||||
// const res = await authenticationRepository.findAll();
|
||||
// expect(res).toEqual({
|
||||
// data: [],
|
||||
// total: 0,
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('should return a data array with 8 auths', async () => {
|
||||
// await createAuthentications(8);
|
||||
// const auths = await authenticationRepository.findAll();
|
||||
// expect(auths.data.length).toBe(8);
|
||||
// expect(auths.total).toBe(8);
|
||||
// });
|
||||
|
||||
// it('should return a data array limited to 10 authentications', async () => {
|
||||
// await createAuthentications(20);
|
||||
// const auths = await authenticationRepository.findAll();
|
||||
// expect(auths.data.length).toBe(10);
|
||||
// expect(auths.total).toBe(20);
|
||||
// });
|
||||
// });
|
||||
|
||||
describe('findOneById', () => {
|
||||
it('should return an authentication', async () => {
|
||||
const authToFind = await prismaService.auth.create({
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { TestingModule, Test } from '@nestjs/testing';
|
||||
import { PrismaService } from '@modules/authentication/infrastructure/prisma.service';
|
||||
import { EventEmitterModule } from '@nestjs/event-emitter';
|
||||
import { MESSAGE_PUBLISHER } from '@src/app.di-tokens';
|
||||
import {
|
||||
DatabaseErrorException,
|
||||
NotFoundException,
|
||||
@@ -15,6 +14,7 @@ import { UsernameRepository } from '@modules/authentication/infrastructure/usern
|
||||
import { UsernameMapper } from '@modules/authentication/username.mapper';
|
||||
import * as bcrypt from 'bcrypt';
|
||||
import { UsernameEntity } from '@modules/authentication/core/domain/username.entity';
|
||||
import { AUTH_MESSAGE_PUBLISHER } from '@modules/authentication/authentication.di-tokens';
|
||||
|
||||
const authUuid = 'a4524d22-7be3-46cd-8444-3145470476dc';
|
||||
|
||||
@@ -46,7 +46,7 @@ describe('UsernameRepository', () => {
|
||||
PrismaService,
|
||||
UsernameMapper,
|
||||
{
|
||||
provide: MESSAGE_PUBLISHER,
|
||||
provide: AUTH_MESSAGE_PUBLISHER,
|
||||
useValue: mockMessagePublisher,
|
||||
},
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user