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(); + }); + }); +});