improve tests saveMessage

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

View File

@ -46,14 +46,14 @@ class registerMessageInApp {
} }
async init() { 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; isDm = () => nbMembers(this.envelope) == 2;
async isFromUs() { async isFromUs() {
if (!this.userId) this.userId = (await getUserIdOfMailbox(boxId))[0]?.user_id; if (!this.userId) this.userId = (await getUserIdOfMailbox(this.boxId))[0]?.user_id;
return this.ownerId = this.userId; return this.ownerId == this.userId;
} }
async initiateRoom(owner, roomType) { 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 { generateAttrs, generateUsers } = require("../test-utils/test-attrsUtils");
const { registerMessageInApp, roomType } = require("../../mails/saveMessage"); const { registerMessageInApp, roomType } = require("../../mails/saveMessage");
@ -8,18 +8,18 @@ jest.mock("../../db/mail");
describe("saveMessage", () => { describe("saveMessage", () => {
describe("is not a reply", () => { 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 users = generateUsers(2);
const attrs = generateAttrs({ from: [users[0].user], to: [users[1].user] }); 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); 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 const createOrRegisterOnExistence = jest
.spyOn(register, "createOrRegisterOnExistence") .spyOn(register, "createOrRegisterOnExistence")
.mockImplementation(() => undefined); .mockImplementation(() => undefined);
@ -28,9 +28,10 @@ describe("saveMessage", () => {
expect(createOrRegisterOnExistence).toHaveBeenCalledWith(users[1].id, roomType.DM); 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", () => {}); // it("first GROUP message should create a group", () => {});
}); });
describe("replies", () => { describe("replies", () => {

View File

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