improve tests saveMessage
This commit is contained in:
parent
1a63b3154a
commit
e2bd0bafea
@ -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) {
|
||||
|
@ -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", () => {
|
||||
|
@ -1,206 +1,206 @@
|
||||
const names = [
|
||||
"James",
|
||||
"Mary",
|
||||
"Robert",
|
||||
"Patricia",
|
||||
"John",
|
||||
"Jennifer",
|
||||
"Michael",
|
||||
"Linda",
|
||||
"David",
|
||||
"Elizabeth",
|
||||
"William",
|
||||
"Barbara",
|
||||
"Richard",
|
||||
"Susan",
|
||||
"Joseph",
|
||||
"Jessica",
|
||||
"Thomas",
|
||||
"Sarah",
|
||||
"Charles",
|
||||
"Karen",
|
||||
"Christopher",
|
||||
"Lisa",
|
||||
"Daniel",
|
||||
"Nancy",
|
||||
"Matthew",
|
||||
"Betty",
|
||||
"Anthony",
|
||||
"Margaret",
|
||||
"Mark",
|
||||
"Sandra",
|
||||
"Donald",
|
||||
"Ashley",
|
||||
"Steven",
|
||||
"Kimberly",
|
||||
"Paul",
|
||||
"Emily",
|
||||
"Andrew",
|
||||
"Donna",
|
||||
"Joshua",
|
||||
"Michelle",
|
||||
"Kenneth",
|
||||
"Carol",
|
||||
"Kevin",
|
||||
"Amanda",
|
||||
"Brian",
|
||||
"Dorothy",
|
||||
"George",
|
||||
"Melissa",
|
||||
"Timothy",
|
||||
"Deborah",
|
||||
"Ronald",
|
||||
"Stephanie",
|
||||
"Edward",
|
||||
"Rebecca",
|
||||
"Jason",
|
||||
"Sharon",
|
||||
"Jeffrey",
|
||||
"Laura",
|
||||
"Ryan",
|
||||
"Cynthia",
|
||||
"Jacob",
|
||||
"Kathleen",
|
||||
"Gary",
|
||||
"Amy",
|
||||
"Nicholas",
|
||||
"Angela",
|
||||
"Eric",
|
||||
"Shirley",
|
||||
"Jonathan",
|
||||
"Anna",
|
||||
"Stephen",
|
||||
"Brenda",
|
||||
"Larry",
|
||||
"Pamela",
|
||||
"Justin",
|
||||
"Emma",
|
||||
"Scott",
|
||||
"Nicole",
|
||||
"Brandon",
|
||||
"Helen",
|
||||
"Benjamin",
|
||||
"Samantha",
|
||||
"Samuel",
|
||||
"Katherine",
|
||||
"Gregory",
|
||||
"Christine",
|
||||
"Alexander",
|
||||
"Debra",
|
||||
"Frank",
|
||||
"Rachel",
|
||||
"Patrick",
|
||||
"Carolyn",
|
||||
"Raymond",
|
||||
"Janet",
|
||||
"Jack",
|
||||
"Catherine",
|
||||
"Dennis",
|
||||
"Maria",
|
||||
"Jerry",
|
||||
"Heather",
|
||||
"Tyler",
|
||||
"Diane",
|
||||
"Aaron",
|
||||
"Ruth",
|
||||
"Jose",
|
||||
"Julie",
|
||||
"Adam",
|
||||
"Olivia",
|
||||
"Nathan",
|
||||
"Joyce",
|
||||
"Henry",
|
||||
"Virginia",
|
||||
"Douglas",
|
||||
"Victoria",
|
||||
"Zachary",
|
||||
"Kelly",
|
||||
"Peter",
|
||||
"Lauren",
|
||||
"Kyle",
|
||||
"Christina",
|
||||
"Ethan",
|
||||
"Joan",
|
||||
"Walter",
|
||||
"Evelyn",
|
||||
"Noah",
|
||||
"Judith",
|
||||
"Jeremy",
|
||||
"Megan",
|
||||
"Christian",
|
||||
"Andrea",
|
||||
"Keith",
|
||||
"Cheryl",
|
||||
"Roger",
|
||||
"Hannah",
|
||||
"Terry",
|
||||
"Jacqueline",
|
||||
"Gerald",
|
||||
"Martha",
|
||||
"Harold",
|
||||
"Gloria",
|
||||
"Sean",
|
||||
"Teresa",
|
||||
"Austin",
|
||||
"Ann",
|
||||
"Carl",
|
||||
"Sara",
|
||||
"Arthur",
|
||||
"Madison",
|
||||
"Lawrence",
|
||||
"Frances",
|
||||
"Dylan",
|
||||
"Kathryn",
|
||||
"Jesse",
|
||||
"Janice",
|
||||
"Jordan",
|
||||
"Jean",
|
||||
"Bryan",
|
||||
"Abigail",
|
||||
"Billy",
|
||||
"Alice",
|
||||
"Joe",
|
||||
"Julia",
|
||||
"Bruce",
|
||||
"Judy",
|
||||
"Gabriel",
|
||||
"Sophia",
|
||||
"Logan",
|
||||
"Grace",
|
||||
"Albert",
|
||||
"Denise",
|
||||
"Willie",
|
||||
"Amber",
|
||||
"Alan",
|
||||
"Doris",
|
||||
"Juan",
|
||||
"Marilyn",
|
||||
"Wayne",
|
||||
"Danielle",
|
||||
"Elijah",
|
||||
"Beverly",
|
||||
"Randy",
|
||||
"Isabella",
|
||||
"Roy",
|
||||
"Theresa",
|
||||
"Vincent",
|
||||
"Diana",
|
||||
"Ralph",
|
||||
"Natalie",
|
||||
"Eugene",
|
||||
"Brittany",
|
||||
"Russell",
|
||||
"Charlotte",
|
||||
"Bobby",
|
||||
"Marie",
|
||||
"Mason",
|
||||
"Kayla",
|
||||
"Philip",
|
||||
"Alexis",
|
||||
"Louis",
|
||||
"Lori"
|
||||
"James",
|
||||
"Mary",
|
||||
"Robert",
|
||||
"Patricia",
|
||||
"John",
|
||||
"Jennifer",
|
||||
"Michael",
|
||||
"Linda",
|
||||
"David",
|
||||
"Elizabeth",
|
||||
"William",
|
||||
"Barbara",
|
||||
"Richard",
|
||||
"Susan",
|
||||
"Joseph",
|
||||
"Jessica",
|
||||
"Thomas",
|
||||
"Sarah",
|
||||
"Charles",
|
||||
"Karen",
|
||||
"Christopher",
|
||||
"Lisa",
|
||||
"Daniel",
|
||||
"Nancy",
|
||||
"Matthew",
|
||||
"Betty",
|
||||
"Anthony",
|
||||
"Margaret",
|
||||
"Mark",
|
||||
"Sandra",
|
||||
"Donald",
|
||||
"Ashley",
|
||||
"Steven",
|
||||
"Kimberly",
|
||||
"Paul",
|
||||
"Emily",
|
||||
"Andrew",
|
||||
"Donna",
|
||||
"Joshua",
|
||||
"Michelle",
|
||||
"Kenneth",
|
||||
"Carol",
|
||||
"Kevin",
|
||||
"Amanda",
|
||||
"Brian",
|
||||
"Dorothy",
|
||||
"George",
|
||||
"Melissa",
|
||||
"Timothy",
|
||||
"Deborah",
|
||||
"Ronald",
|
||||
"Stephanie",
|
||||
"Edward",
|
||||
"Rebecca",
|
||||
"Jason",
|
||||
"Sharon",
|
||||
"Jeffrey",
|
||||
"Laura",
|
||||
"Ryan",
|
||||
"Cynthia",
|
||||
"Jacob",
|
||||
"Kathleen",
|
||||
"Gary",
|
||||
"Amy",
|
||||
"Nicholas",
|
||||
"Angela",
|
||||
"Eric",
|
||||
"Shirley",
|
||||
"Jonathan",
|
||||
"Anna",
|
||||
"Stephen",
|
||||
"Brenda",
|
||||
"Larry",
|
||||
"Pamela",
|
||||
"Justin",
|
||||
"Emma",
|
||||
"Scott",
|
||||
"Nicole",
|
||||
"Brandon",
|
||||
"Helen",
|
||||
"Benjamin",
|
||||
"Samantha",
|
||||
"Samuel",
|
||||
"Katherine",
|
||||
"Gregory",
|
||||
"Christine",
|
||||
"Alexander",
|
||||
"Debra",
|
||||
"Frank",
|
||||
"Rachel",
|
||||
"Patrick",
|
||||
"Carolyn",
|
||||
"Raymond",
|
||||
"Janet",
|
||||
"Jack",
|
||||
"Catherine",
|
||||
"Dennis",
|
||||
"Maria",
|
||||
"Jerry",
|
||||
"Heather",
|
||||
"Tyler",
|
||||
"Diane",
|
||||
"Aaron",
|
||||
"Ruth",
|
||||
"Jose",
|
||||
"Julie",
|
||||
"Adam",
|
||||
"Olivia",
|
||||
"Nathan",
|
||||
"Joyce",
|
||||
"Henry",
|
||||
"Virginia",
|
||||
"Douglas",
|
||||
"Victoria",
|
||||
"Zachary",
|
||||
"Kelly",
|
||||
"Peter",
|
||||
"Lauren",
|
||||
"Kyle",
|
||||
"Christina",
|
||||
"Ethan",
|
||||
"Joan",
|
||||
"Walter",
|
||||
"Evelyn",
|
||||
"Noah",
|
||||
"Judith",
|
||||
"Jeremy",
|
||||
"Megan",
|
||||
"Christian",
|
||||
"Andrea",
|
||||
"Keith",
|
||||
"Cheryl",
|
||||
"Roger",
|
||||
"Hannah",
|
||||
"Terry",
|
||||
"Jacqueline",
|
||||
"Gerald",
|
||||
"Martha",
|
||||
"Harold",
|
||||
"Gloria",
|
||||
"Sean",
|
||||
"Teresa",
|
||||
"Austin",
|
||||
"Ann",
|
||||
"Carl",
|
||||
"Sara",
|
||||
"Arthur",
|
||||
"Madison",
|
||||
"Lawrence",
|
||||
"Frances",
|
||||
"Dylan",
|
||||
"Kathryn",
|
||||
"Jesse",
|
||||
"Janice",
|
||||
"Jordan",
|
||||
"Jean",
|
||||
"Bryan",
|
||||
"Abigail",
|
||||
"Billy",
|
||||
"Alice",
|
||||
"Joe",
|
||||
"Julia",
|
||||
"Bruce",
|
||||
"Judy",
|
||||
"Gabriel",
|
||||
"Sophia",
|
||||
"Logan",
|
||||
"Grace",
|
||||
"Albert",
|
||||
"Denise",
|
||||
"Willie",
|
||||
"Amber",
|
||||
"Alan",
|
||||
"Doris",
|
||||
"Juan",
|
||||
"Marilyn",
|
||||
"Wayne",
|
||||
"Danielle",
|
||||
"Elijah",
|
||||
"Beverly",
|
||||
"Randy",
|
||||
"Isabella",
|
||||
"Roy",
|
||||
"Theresa",
|
||||
"Vincent",
|
||||
"Diana",
|
||||
"Ralph",
|
||||
"Natalie",
|
||||
"Eugene",
|
||||
"Brittany",
|
||||
"Russell",
|
||||
"Charlotte",
|
||||
"Bobby",
|
||||
"Marie",
|
||||
"Mason",
|
||||
"Kayla",
|
||||
"Philip",
|
||||
"Alexis",
|
||||
"Louis",
|
||||
"Lori",
|
||||
];
|
||||
|
||||
module.exports = {
|
||||
names
|
||||
}
|
||||
names,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user