diff --git a/backend/src/modules/chat/chat.module.ts b/backend/src/modules/chat/chat.module.ts index 88ee0b2..e21bc66 100644 --- a/backend/src/modules/chat/chat.module.ts +++ b/backend/src/modules/chat/chat.module.ts @@ -30,6 +30,6 @@ import { User, UserSchema } from '../user/user.schema'; { provide: 'IChatRepository', useExisting: ChatRepositoryMongodb }, { provide: 'IMessageRepository', useExisting: MessageRepositoryMongodb }, ], - exports: [ChatService], + exports: [ChatService, 'IChatRepository'], }) export class ChatModule {} \ No newline at end of file diff --git a/backend/src/modules/chat/domain/chat.repository.ts b/backend/src/modules/chat/domain/chat.repository.ts index b1113ed..2aa976f 100644 --- a/backend/src/modules/chat/domain/chat.repository.ts +++ b/backend/src/modules/chat/domain/chat.repository.ts @@ -7,14 +7,9 @@ export interface IChatRepository { agentId: string; groupId: string; }): Promise; - findById(id: string): Promise; - findByParticipant(userId: string): Promise; - findByTicketId(ticketId: string): Promise; - updateStatus(id: string, status: ChatStatus): Promise; - updateAgent(ticketId: string, agentId: string | null): Promise; -} +} \ No newline at end of file diff --git a/backend/src/modules/chat/infra/chat.repository.mongodb.ts b/backend/src/modules/chat/infra/chat.repository.mongodb.ts index d980d36..3e12625 100644 --- a/backend/src/modules/chat/infra/chat.repository.mongodb.ts +++ b/backend/src/modules/chat/infra/chat.repository.mongodb.ts @@ -39,7 +39,7 @@ export class ChatRepositoryMongodb implements IChatRepository { async findById(id: string): Promise { const chatDoc = await this.chatModel.findById(id).exec(); - + if (!chatDoc) return null; return { id: chatDoc._id as string, @@ -53,7 +53,7 @@ export class ChatRepositoryMongodb implements IChatRepository { async findByTicketId(ticketId: string): Promise { const chatDoc = await this.chatModel.findOne({ ticketId }).exec(); - + if (!chatDoc) return null; return { id: chatDoc._id as string, @@ -93,4 +93,4 @@ export class ChatRepositoryMongodb implements IChatRepository { if (!doc) return null; return this.toDetails(doc); } -} +} \ No newline at end of file diff --git a/backend/src/modules/ticket/application/useCases/newAgent/newAgent.usecase.spec.ts b/backend/src/modules/ticket/application/useCases/newAgent/newAgent.usecase.spec.ts index ff346f5..d6eb2cf 100644 --- a/backend/src/modules/ticket/application/useCases/newAgent/newAgent.usecase.spec.ts +++ b/backend/src/modules/ticket/application/useCases/newAgent/newAgent.usecase.spec.ts @@ -1,10 +1,7 @@ /* eslint-disable @typescript-eslint/unbound-method */ import { randomUUID } from 'crypto'; import { ITicketRepository } from '../../../domain/repository/ticket.repository.interface'; -import { - Ticket, - TicketStatus, -} from '../../../domain/entities/ticket.entity'; +import { Ticket, TicketStatus } from '../../../domain/entities/ticket.entity'; import { NewAgentTicketUseCase } from './newAgent.usecase'; import { ChatService } from '../../../../chat/application/chat.service'; @@ -34,14 +31,13 @@ describe('NewAgentTicketUseCase', () => { useCase = new NewAgentTicketUseCase(repository, chatService); }); - it('should assing a new agent to a ticket successfully', async () => { + it('should assign a new agent to a ticket successfully', async () => { const input = { id: ticket.id, agentId: randomUUID(), }; repository.readById.mockResolvedValue(ticket); - ticket.assignToAgent(input.agentId); repository.save.mockResolvedValue(ticket); @@ -54,12 +50,13 @@ describe('NewAgentTicketUseCase', () => { expect(repository.readById).toHaveBeenCalledTimes(1); expect(repository.readById).toHaveBeenCalledWith(input.id); - expect(repository.save).toHaveBeenCalledTimes(1); expect(repository.save).toHaveBeenCalledWith(ticket); + expect(chatService.updateAgentByTicketId).toHaveBeenCalledTimes(1); + expect(chatService.updateAgentByTicketId).toHaveBeenCalledWith(ticket.id, input.agentId); expect(output).not.toHaveProperty('toPrimitives'); expect(output).not.toHaveProperty('escalate'); expect(output).not.toHaveProperty('assignToAgent'); }); -}); +}); \ No newline at end of file diff --git a/backend/src/modules/ticket/application/useCases/newAgent/newAgent.usecase.ts b/backend/src/modules/ticket/application/useCases/newAgent/newAgent.usecase.ts index 8f80b46..e5380a6 100644 --- a/backend/src/modules/ticket/application/useCases/newAgent/newAgent.usecase.ts +++ b/backend/src/modules/ticket/application/useCases/newAgent/newAgent.usecase.ts @@ -27,7 +27,7 @@ export class NewAgentTicketUseCase { if (!foundedTicket) { throw new Error('Ticket not found.'); } - + foundedTicket.assignToAgent(input.agentId); const updatedTicket = await this.repository.save(foundedTicket); @@ -39,7 +39,6 @@ export class NewAgentTicketUseCase { try { await this.chatService.updateAgentByTicketId(updatedTicket.id, updatedTicket.agentId); } catch (e) { - // Ignora se o chat não existir, pois os módulos estão fracamente acoplados console.warn('Chat não pôde ser atualizado ou não existe:', e); } @@ -49,4 +48,4 @@ export class NewAgentTicketUseCase { status: updatedTicket.status, }; } -} +} \ No newline at end of file