Compare commits
4 Commits
v1.8.0
...
46ffdd809c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
46ffdd809c
|
||
|
|
2dcd277347
|
||
|
|
9486803aeb
|
||
|
|
1e0bb03182
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@memegoat/backend",
|
||||
"version": "1.8.0",
|
||||
"version": "1.8.1",
|
||||
"description": "",
|
||||
"author": "",
|
||||
"private": true,
|
||||
|
||||
@@ -76,7 +76,9 @@ describe("CommentsService", () => {
|
||||
|
||||
it("should throw ForbiddenException if not owner and not admin", async () => {
|
||||
mockCommentsRepository.findOne.mockResolvedValue({ userId: "u1" });
|
||||
await expect(service.remove("other", "c1")).rejects.toThrow(ForbiddenException);
|
||||
await expect(service.remove("other", "c1")).rejects.toThrow(
|
||||
ForbiddenException,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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>(MessagesService);
|
||||
repository = module.get<MessagesRepository>(MessagesRepository);
|
||||
eventsGateway = module.get<EventsGateway>(EventsGateway);
|
||||
_repository = module.get<MessagesRepository>(MessagesRepository);
|
||||
_eventsGateway = module.get<EventsGateway>(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,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { ConfigService } from "@nestjs/config";
|
||||
import { Test, TestingModule } from "@nestjs/testing";
|
||||
import { Server } from "socket.io";
|
||||
import { JwtService } from "../crypto/services/jwt.service";
|
||||
import { EventsGateway } from "./events.gateway";
|
||||
|
||||
describe("EventsGateway", () => {
|
||||
let gateway: EventsGateway;
|
||||
let jwtService: JwtService;
|
||||
let _jwtService: JwtService;
|
||||
|
||||
const mockJwtService = {
|
||||
verifyJwt: jest.fn(),
|
||||
@@ -26,7 +25,7 @@ describe("EventsGateway", () => {
|
||||
}).compile();
|
||||
|
||||
gateway = module.get<EventsGateway>(EventsGateway);
|
||||
jwtService = module.get<JwtService>(JwtService);
|
||||
_jwtService = module.get<JwtService>(JwtService);
|
||||
gateway.server = {
|
||||
to: jest.fn().mockReturnThis(),
|
||||
emit: jest.fn(),
|
||||
@@ -46,7 +45,10 @@ describe("EventsGateway", () => {
|
||||
gateway.sendToUser(userId, event, data);
|
||||
|
||||
expect(gateway.server.to).toHaveBeenCalledWith(`user:${userId}`);
|
||||
expect(gateway.server.to(`user:${userId}`).emit).toHaveBeenCalledWith(event, data);
|
||||
expect(gateway.server.to(`user:${userId}`).emit).toHaveBeenCalledWith(
|
||||
event,
|
||||
data,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@memegoat/frontend",
|
||||
"version": "1.8.0",
|
||||
"version": "1.8.1",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@memegoat/source",
|
||||
"version": "1.8.0",
|
||||
"version": "1.8.1",
|
||||
"description": "",
|
||||
"scripts": {
|
||||
"version:get": "cmake -P version.cmake GET",
|
||||
|
||||
Reference in New Issue
Block a user