From 096b848da951669306f91ce28139b6c542597037 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Peveri?= Date: Sat, 18 Jan 2025 16:37:56 +0100 Subject: [PATCH] Modify AddLikeTermCommandHandler to use IdentityProvider #181 --- .../term/command/addLikeTermCommandHandler.ts | 7 ++++++- src/languages/domain/term/term.ts | 3 +-- .../term/command/addLikeTermCommandHandler.test.ts | 9 ++++++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/languages/application/term/command/addLikeTermCommandHandler.ts b/src/languages/application/term/command/addLikeTermCommandHandler.ts index a5934c4..c2d95ee 100644 --- a/src/languages/application/term/command/addLikeTermCommandHandler.ts +++ b/src/languages/application/term/command/addLikeTermCommandHandler.ts @@ -12,12 +12,14 @@ import CollaboratorRepository, { import CollaboratorId from '@src/languages/domain/collaborator/collaboratorId'; import Collaborator from '@src/languages/domain/collaborator/collaborator'; import CollaboratorDoesNotExistsException from '@src/languages/domain/collaborator/collaboratorDoesNotExistsException'; +import { IDENTITY_PROVIDER, IdentityProvider } from '@src/shared/domain/services/IdentityProvider'; @CommandHandler(AddLikeTermCommand) export default class AddLikeTermCommandHandler implements ICommandHandler { constructor( @Inject(TERM_REPOSITORY) private readonly termRepository: TermRepository, @Inject(COLLABORATOR_REPOSITORY) private readonly collaboratorRepository: CollaboratorRepository, + @Inject(IDENTITY_PROVIDER) private readonly identityProvider: IdentityProvider, @Inject(ASYNC_EVENT_BUS) private readonly eventBus: EventBus, ) {} @@ -25,7 +27,10 @@ export default class AddLikeTermCommandHandler implements ICommandHandler { let termRepository: TermRepositoryMock; let collaboratorRepository: CollaboratorRepositoryMock; let eventBus: EventBusMock; + let identityProvider: IdentityProviderMock; let handler: AddLikeTermCommandHandler; const COLLABORATOR_ID = '0a8008d5-ab68-4c10-8476-668b5b540e0f'; @@ -30,11 +32,12 @@ describe('Given a AddLikeTermCommandHandler to handle', () => { const prepareDependencies = () => { termRepository = new TermRepositoryMock(); collaboratorRepository = new CollaboratorRepositoryMock(); + identityProvider = new IdentityProviderMock(); eventBus = new EventBusMock(); }; const initHandler = () => { - handler = new AddLikeTermCommandHandler(termRepository, collaboratorRepository, eventBus); + handler = new AddLikeTermCommandHandler(termRepository, collaboratorRepository, identityProvider, eventBus); jest.useFakeTimers(); }; @@ -42,6 +45,7 @@ describe('Given a AddLikeTermCommandHandler to handle', () => { const clean = () => { termRepository.clean(); collaboratorRepository.clean(); + identityProvider.clean(); eventBus.clean(); }; @@ -174,6 +178,7 @@ describe('Given a AddLikeTermCommandHandler to handle', () => { function startScenario() { command = AddLikeTermCommandMother.random({ termId: TERM_ID, userId: COLLABORATOR_ID }); + term = WordMother.random({ id: TermIdMother.random(TERM_ID), likes: [ @@ -188,6 +193,7 @@ describe('Given a AddLikeTermCommandHandler to handle', () => { }); const collaborator = CollaboratorMother.random({ id: CollaboratorIdMother.random(COLLABORATOR_ID) }); + identityProvider.add(TERM_LIKE_ID); termRepository.add(term); collaboratorRepository.add(collaborator); } @@ -229,6 +235,7 @@ describe('Given a AddLikeTermCommandHandler to handle', () => { photo: PHOTO, }); + identityProvider.add(TERM_LIKE_ID); termRepository.add(term); collaboratorRepository.add(user); }