diff --git a/backend/src/messages/messages.service.spec.ts b/backend/src/messages/messages.service.spec.ts index 7ea9a00..e357295 100644 --- a/backend/src/messages/messages.service.spec.ts +++ b/backend/src/messages/messages.service.spec.ts @@ -6,8 +6,8 @@ import { MessagesRepository } from "./repositories/messages.repository"; describe("MessagesService", () => { let service: MessagesService; - let repository: MessagesRepository; - let eventsGateway: EventsGateway; + let _repository: MessagesRepository; + let _eventsGateway: EventsGateway; const mockMessagesRepository = { findConversationBetweenUsers: jest.fn(), @@ -33,28 +33,39 @@ describe("MessagesService", () => { }).compile(); service = module.get(MessagesService); - repository = module.get(MessagesRepository); - eventsGateway = module.get(EventsGateway); + _repository = module.get(MessagesRepository); + _eventsGateway = module.get(EventsGateway); }); describe("sendMessage", () => { it("should send message to existing conversation", async () => { const senderId = "s1"; const dto = { recipientId: "r1", text: "hello" }; - mockMessagesRepository.findConversationBetweenUsers.mockResolvedValue({ id: "conv1" }); - mockMessagesRepository.createMessage.mockResolvedValue({ id: "m1", text: "hello" }); + mockMessagesRepository.findConversationBetweenUsers.mockResolvedValue({ + id: "conv1", + }); + mockMessagesRepository.createMessage.mockResolvedValue({ + id: "m1", + text: "hello", + }); const result = await service.sendMessage(senderId, dto); expect(result.id).toBe("m1"); - expect(mockEventsGateway.sendToUser).toHaveBeenCalledWith("r1", "new_message", expect.anything()); + expect(mockEventsGateway.sendToUser).toHaveBeenCalledWith( + "r1", + "new_message", + expect.anything(), + ); }); it("should create new conversation if not exists", async () => { const senderId = "s1"; const dto = { recipientId: "r1", text: "hello" }; mockMessagesRepository.findConversationBetweenUsers.mockResolvedValue(null); - mockMessagesRepository.createConversation.mockResolvedValue({ id: "new_conv" }); + mockMessagesRepository.createConversation.mockResolvedValue({ + id: "new_conv", + }); mockMessagesRepository.createMessage.mockResolvedValue({ id: "m1" }); await service.sendMessage(senderId, dto); @@ -67,7 +78,9 @@ describe("MessagesService", () => { describe("getMessages", () => { it("should return messages if user is participant", async () => { mockMessagesRepository.isParticipant.mockResolvedValue(true); - mockMessagesRepository.findMessagesByConversationId.mockResolvedValue([{ id: "m1" }]); + mockMessagesRepository.findMessagesByConversationId.mockResolvedValue([ + { id: "m1" }, + ]); const result = await service.getMessages("u1", "conv1"); expect(result).toHaveLength(1); @@ -75,7 +88,9 @@ describe("MessagesService", () => { it("should throw ForbiddenException if user is not participant", async () => { mockMessagesRepository.isParticipant.mockResolvedValue(false); - await expect(service.getMessages("u1", "conv1")).rejects.toThrow(ForbiddenException); + await expect(service.getMessages("u1", "conv1")).rejects.toThrow( + ForbiddenException, + ); }); }); });