advancements in tests

This commit is contained in:
grimhilt
2023-04-04 18:00:27 +02:00
parent 5a71e104cd
commit 9fc31f8686
5 changed files with 132 additions and 36 deletions

View File

@@ -6,25 +6,50 @@ mysql.createConnection.mockImplementation(() => {
});
import saveMessageDatabase from "../test-utils/db/test-saveMessage";
import { generateAttrs, generateUsers } from "../test-utils/test-attrsUtils";
import registerMessageInApp, { RoomType } from "../../mails/saveMessage";
import { jest, describe, it, expect } from "@jest/globals";
import { mocked } from "jest-mock";
const db = new saveMessageDatabase(generateUsers(5));
import registerMessageInApp, { RoomType } from "../../mails/saveMessage";
const db = new saveMessageDatabase(generateUsers(5));
const ownUser = db.users[0];
const messageId = 1;
const boxId = 1;
jest.mock("../../db/utils/mail", () => {
return {
getAddresseId: jest.fn(),
getUserIdOfMailbox: jest.fn(),
};
});
jest.mock("../../db/saveMessage-db", () => {
return {
createRoom: jest.fn(),
registerMessageInRoom: jest.fn(),
isRoomGroup: jest.fn(),
findRoomsFromMessage: jest.fn(),
hasSameMembersAsParent: jest.fn(),
registerThread: jest.fn(),
registerMember: jest.fn(),
getAllMembers: jest.fn(),
getThreadInfo: jest.fn(),
incrementNotSeenRoom: jest.fn(),
};
});
import { getAddresseId, getUserIdOfMailbox } from "../../db/utils/mail";
import {
createRoom,
registerMessageInRoom,
isRoomGroup,
findRoomsFromMessage,
hasSameMembersAsParent,
registerThread,
registerMember,
getAllMembers,
getThreadInfo,
incrementNotSeenRoom,
} from "../../db/saveMessage-db";
// todo esbuild
// new message from us
// to multiple people -> room
@@ -45,6 +70,17 @@ beforeAll(async () => {
db.clear();
mocked(getAddresseId).mockImplementation(db.getAddresseId);
mocked(getUserIdOfMailbox).mockImplementation(db.getUserIdOfMailbox);
mocked(createRoom).mockImplementation(db.createRoom);
mocked(registerMessageInRoom).mockImplementation(db.registerMessageInRoom);
mocked(isRoomGroup).mockImplementation(db.isRoomGroup);
mocked(findRoomsFromMessage).mockImplementation(db.findRoomsFromMessage);
mocked(hasSameMembersAsParent).mockImplementation(db.hasSameMembersAsParent);
mocked(registerThread).mockImplementation(db.registerThread);
mocked(registerMember).mockImplementation(db.registerMember);
mocked(getAllMembers).mockImplementation(db.getAllMembers);
mocked(getThreadInfo).mockImplementation(db.getThreadInfo);
mocked(incrementNotSeenRoom).mockImplementation(db.incrementNotSeenRoom);
});
describe("saveMessage", () => {
@@ -67,7 +103,7 @@ describe("saveMessage", () => {
});
describe("implementation", () => {
describe("new first message from us", () => {
it("new first message from us to one recipient should create a DM", async () => {
it("should create a DM when there is a new first message from us to one recipient", async () => {
const attrs = generateAttrs({ from: [ownUser.user], to: [db.users[1].user] });
const register = new registerMessageInApp(messageId, attrs, boxId);
@@ -82,7 +118,7 @@ describe("saveMessage", () => {
expect(createOrRegisterOnExistence).toHaveBeenCalledWith(db.users[1].id, RoomType.DM);
});
it("new first message from us to multiple recipients should create a ROOM", async () => {
it("should create a ROOM when there is a new first message from us to multiple recipients", async () => {
const attrs = generateAttrs({ from: [ownUser.user], to: [db.users[1].user, db.users[2].user] });
const register = new registerMessageInApp(messageId, attrs, boxId);
@@ -95,11 +131,15 @@ describe("saveMessage", () => {
expect(initiateRoom).toHaveBeenCalledWith(ownUser.id, RoomType.ROOM);
});
// it("response to new first message to multiple recipients with same members should change room type to GROUP", () => {});
// it("response to new first message to multiple recipients with different members should change room type to CHANNEL", () => {});
// it("response to new first message to multiple recipients with same members should change room type to GROUP", () => {
// });
// it("response to new first message to multiple recipients with different members should change room type to CHANNEL", () => {
// });
});
describe("new first message from other", () => {
it("new first message from other to me only should create a room", async () => {
it("should create a ROOM when there is a new first message from other to me only", async () => {
const attrs = generateAttrs({ from: [db.users[1].user], to: [ownUser.user] });
const register = new registerMessageInApp(messageId, attrs, boxId);
@@ -115,9 +155,25 @@ describe("saveMessage", () => {
expect(createOrRegisterOnExistence).toHaveBeenCalledWith(db.users[1].id, RoomType.ROOM);
});
});
// describe("replies", () => {
// it("", () => {});
// });
describe("unseen behavior", () => {});
describe("replies", () => {
it("", () => {});
});
});
describe("unseen behavior", () => {
it("should add unseen in room when a message creates a room", () => {
});
it("should add unseen in room when a message joins a room", () => {
});
it("should add unseen in root room and thread when new message creates a thread", () => {
});
it("should add unseen in root room and thread when new message joins in thread", () => {
});
});
});