improve tests saveMessage

This commit is contained in:
grimhilt 2023-03-30 09:16:10 +02:00
parent 1a63b3154a
commit e2bd0bafea
3 changed files with 215 additions and 214 deletions

View File

@ -46,14 +46,14 @@ class registerMessageInApp {
}
async init() {
this.ownerId = await getAddresseId(createAddress(this.envelope.sender[0])); // todo use sender or from ?
this.ownerId = await getAddresseId(createAddress(this.envelope.from[0])); // todo use sender or from ?
}
isDm = () => nbMembers(this.envelope) == 2;
async isFromUs() {
if (!this.userId) this.userId = (await getUserIdOfMailbox(boxId))[0]?.user_id;
return this.ownerId = this.userId;
if (!this.userId) this.userId = (await getUserIdOfMailbox(this.boxId))[0]?.user_id;
return this.ownerId == this.userId;
}
async initiateRoom(owner, roomType) {

View File

@ -1,4 +1,4 @@
const { getAddresseId } = require("../../db/mail");
const { getAddresseId, getUserIdOfMailbox } = require("../../db/mail");
const { generateAttrs, generateUsers } = require("../test-utils/test-attrsUtils");
const { registerMessageInApp, roomType } = require("../../mails/saveMessage");
@ -8,17 +8,17 @@ jest.mock("../../db/mail");
describe("saveMessage", () => {
describe("is not a reply", () => {
it("first DM from user should create a DM room", async () => {
it("DM from user should be assigned to other user", async () => {
const users = generateUsers(2);
const attrs = generateAttrs({ from: [users[0].user], to: [users[1].user] });
getAddresseId.mockReturnValue(users[1].id);
getUserIdOfMailbox.mockReturnValue([{ user_id: users[0].id }]);
getAddresseId.mockImplementation((email) => {
const match = users.find((user) => user.user.mailbox + "@" + user.user.host == email);
return match.id;
});
const register = new registerMessageInApp(1, attrs, 1);
register.ownerId = users[0].id;
jest.spyOn(register, "isFromUs").mockReturnValue(true);
jest.spyOn(register, "init").mockReturnValue("");
const createOrRegisterOnExistence = jest
.spyOn(register, "createOrRegisterOnExistence")
@ -28,9 +28,10 @@ describe("saveMessage", () => {
expect(createOrRegisterOnExistence).toHaveBeenCalledWith(users[1].id, roomType.DM);
});
// it("DM message from user should be added to DM room", async () => {
// });
it("DM message from user should be added to DM room", async () => {
// todo multiple messages
});
// it("first GROUP message should create a group", () => {});
});
describe("replies", () => {

View File

@ -198,9 +198,9 @@ const names = [
"Philip",
"Alexis",
"Louis",
"Lori"
"Lori",
];
module.exports = {
names
}
names,
};