From e123f190c6788b5bdf3ae6eaf69b5d580d86a531 Mon Sep 17 00:00:00 2001 From: sbriat Date: Fri, 7 Jul 2023 10:11:15 +0200 Subject: [PATCH] delete authentication service tests --- .../delete-authentication.service.spec.ts | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/modules/authentication/tests/unit/core/delete-authentication.service.spec.ts diff --git a/src/modules/authentication/tests/unit/core/delete-authentication.service.spec.ts b/src/modules/authentication/tests/unit/core/delete-authentication.service.spec.ts new file mode 100644 index 0000000..5c8824c --- /dev/null +++ b/src/modules/authentication/tests/unit/core/delete-authentication.service.spec.ts @@ -0,0 +1,54 @@ +import { AUTHENTICATION_REPOSITORY } from '@modules/authentication/authentication.di-tokens'; +import { DeleteAuthenticationCommand } from '@modules/authentication/core/application/commands/delete-authentication/delete-authentication.command'; +import { DeleteAuthenticationService } from '@modules/authentication/core/application/commands/delete-authentication/delete-authentication.service'; +import { DeleteAuthenticationRequestDto } from '@modules/authentication/interface/grpc-controllers/dtos/delete-authentication.request.dto'; +import { Test, TestingModule } from '@nestjs/testing'; + +const deleteAuthenticationRequest: DeleteAuthenticationRequestDto = { + userId: '165192d4-398a-4469-a16b-98c02cc6f531', +}; + +const mockAuthenticationEntity = { + delete: jest.fn(), +}; + +const mockAuthenticationRepository = { + findOneById: jest.fn().mockImplementation(() => mockAuthenticationEntity), + delete: jest.fn().mockImplementationOnce(() => true), +}; + +describe('Delete Authentication Service', () => { + let deleteAuthenticationService: DeleteAuthenticationService; + + beforeAll(async () => { + const module: TestingModule = await Test.createTestingModule({ + providers: [ + { + provide: AUTHENTICATION_REPOSITORY, + useValue: mockAuthenticationRepository, + }, + DeleteAuthenticationService, + ], + }).compile(); + + deleteAuthenticationService = module.get( + DeleteAuthenticationService, + ); + }); + + it('should be defined', () => { + expect(deleteAuthenticationService).toBeDefined(); + }); + + describe('execution', () => { + const deleteAuthenticationCommand = new DeleteAuthenticationCommand( + deleteAuthenticationRequest, + ); + it('should delete an authentication', async () => { + const result: boolean = await deleteAuthenticationService.execute( + deleteAuthenticationCommand, + ); + expect(result).toBeTruthy(); + }); + }); +});