Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/src/modules/chat/chat.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
7 changes: 1 addition & 6 deletions backend/src/modules/chat/domain/chat.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@ export interface IChatRepository {
agentId: string;
groupId: string;
}): Promise<ChatDetails>;

findById(id: string): Promise<ChatDetails | null>;

findByParticipant(userId: string): Promise<ChatDetails[]>;

findByTicketId(ticketId: string): Promise<ChatDetails | null>;

updateStatus(id: string, status: ChatStatus): Promise<ChatDetails | null>;

updateAgent(ticketId: string, agentId: string | null): Promise<ChatDetails | null>;
}
}
6 changes: 3 additions & 3 deletions backend/src/modules/chat/infra/chat.repository.mongodb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class ChatRepositoryMongodb implements IChatRepository {

async findById(id: string): Promise<ChatDetails | null> {
const chatDoc = await this.chatModel.findById(id).exec();

if (!chatDoc) return null;
return {
id: chatDoc._id as string,
Expand All @@ -53,7 +53,7 @@ export class ChatRepositoryMongodb implements IChatRepository {

async findByTicketId(ticketId: string): Promise<ChatDetails | null> {
const chatDoc = await this.chatModel.findOne({ ticketId }).exec();

if (!chatDoc) return null;
return {
id: chatDoc._id as string,
Expand Down Expand Up @@ -93,4 +93,4 @@ export class ChatRepositoryMongodb implements IChatRepository {
if (!doc) return null;
return this.toDetails(doc);
}
}
}
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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);

Expand All @@ -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');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}

Expand All @@ -49,4 +48,4 @@ export class NewAgentTicketUseCase {
status: updatedTicket.status,
};
}
}
}
Loading