implement save of thread and members
This commit is contained in:
45
back/test/mail/utils/envelopeUtils-test.js
Normal file
45
back/test/mail/utils/envelopeUtils-test.js
Normal file
@@ -0,0 +1,45 @@
|
||||
const { nbMembers } = require("../../../mails/utils/envelopeUtils");
|
||||
const { generateUsers } = require("../../test-utils/test-attrsUtils");
|
||||
|
||||
describe("envelopeUtils", () => {
|
||||
const names = generateUsers(6);
|
||||
describe("nbMembers", () => {
|
||||
it("sender and from shouldn't be counted twice if there are the same", () => {
|
||||
const envelope = {
|
||||
from: [names[0].user],
|
||||
sender: [names[0].user],
|
||||
replyTo: null,
|
||||
to: null,
|
||||
cc: null,
|
||||
bcc: null,
|
||||
inReplyTo: null,
|
||||
};
|
||||
expect(nbMembers(envelope)).toBe(1);
|
||||
});
|
||||
it("sender and from shoud be counted twice if there are the same", () => {
|
||||
const envelope = {
|
||||
from: [names[0].user],
|
||||
sender: [names[1].user],
|
||||
replyTo: null,
|
||||
to: null,
|
||||
cc: null,
|
||||
bcc: null,
|
||||
inReplyTo: null,
|
||||
};
|
||||
expect(nbMembers(envelope)).toBe(2);
|
||||
});
|
||||
it("should count every members", () => {
|
||||
// todo should merge identic members
|
||||
const envelope = {
|
||||
from: [names[0].user],
|
||||
sender: [names[1].user],
|
||||
replyTo: [names[2].user],
|
||||
to: [names[3].user],
|
||||
cc: [names[4].user],
|
||||
bcc: [names[5].user],
|
||||
inReplyTo: null,
|
||||
};
|
||||
expect(nbMembers(envelope)).toBe(6);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,40 +0,0 @@
|
||||
const { nbMembers } = require("../../../mails/utils/statusUtils");
|
||||
|
||||
describe("statusUtils", () => {
|
||||
it("sender and from shouldn't be counted twice if there are the same", () => {
|
||||
const envelope = {
|
||||
from: [{ name: "", mailbox: "user_1", host: "provider.com" }],
|
||||
sender: [{ name: "", mailbox: "user_1", host: "provider.com" }],
|
||||
replyTo: [{ name: "", mailbox: "user_1", host: "provider.com" }],
|
||||
to: null,
|
||||
cc: null,
|
||||
bcc: null,
|
||||
inReplyTo: null,
|
||||
};
|
||||
expect(nbMembers(envelope)).toBe(1);
|
||||
});
|
||||
it("sender and from shoud be counted twice if there are the same", () => {
|
||||
const envelope = {
|
||||
from: [{ name: "", mailbox: "user_1", host: "provider.com" }],
|
||||
sender: [{ name: "", mailbox: "user_2", host: "provider.com" }],
|
||||
replyTo: [{ name: "", mailbox: "user_1", host: "provider.com" }],
|
||||
to: null,
|
||||
cc: null,
|
||||
bcc: null,
|
||||
inReplyTo: null,
|
||||
};
|
||||
expect(nbMembers(envelope)).toBe(2);
|
||||
});
|
||||
it("should count every members", () => {
|
||||
const envelope = {
|
||||
from: [{ name: "", mailbox: "user_1", host: "provider.com" }],
|
||||
sender: [{ name: "", mailbox: "user_2", host: "provider.com" }],
|
||||
replyTo: [{ name: "", mailbox: "user_1", host: "provider.com" }],
|
||||
to: [{ name: "", mailbox: "user_1", host: "provider.com" }],
|
||||
cc: [{ name: "", mailbox: "user_1", host: "provider.com" }],
|
||||
bcc: [{ name: "", mailbox: "user_1", host: "provider.com" }],
|
||||
inReplyTo: null,
|
||||
};
|
||||
expect(nbMembers(envelope)).toBe(5);
|
||||
});
|
||||
});
|
||||
@@ -1,19 +0,0 @@
|
||||
beforeAll(async () => {
|
||||
// const schema = fs.readFileSync('../../sql/structureV2.sql', 'utf8');
|
||||
// await setupDB(mysqlConfig, schema);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
global.db.query("DROP database mail_test");
|
||||
});
|
||||
|
||||
describe('saveMessageApp', async () => {
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
});
|
||||
|
||||
it("", () => {
|
||||
|
||||
});
|
||||
});
|
||||
61
back/test/test-utils/test-attrsUtils.js
Normal file
61
back/test/test-utils/test-attrsUtils.js
Normal file
@@ -0,0 +1,61 @@
|
||||
const { names } = require("./names");
|
||||
|
||||
function generateAttrs(options) {
|
||||
const attrs = {
|
||||
"size": 42,
|
||||
"envelope": {
|
||||
date: "2023-03-21T15:25:42.000Z",
|
||||
subject: options.subject ?? "subject" + randomString(10),
|
||||
from: options.from ?? null,
|
||||
sender: options.sender ?? null,
|
||||
replyTo: options.replyTo ?? null,
|
||||
to: options.to ?? null,
|
||||
cc: options.cc ?? null,
|
||||
bcc: options.bcc ?? null,
|
||||
inReplyTo: options.inReplyTo ?? null,
|
||||
messageId: options.messageId ?? randomString(10),
|
||||
},
|
||||
"date": options.date ?? new Date(),
|
||||
"flags": options.flags ?? [],
|
||||
"uid": options.uid ?? randomInt(3),
|
||||
"modseq": options.modseq ?? randomInt(7),
|
||||
"x-gm-labels": ["\\Inbox"],
|
||||
"x-gm-msgid": "1760991478422670209",
|
||||
"x-gm-thrid": "1760991478422670209",
|
||||
};
|
||||
return attrs;
|
||||
}
|
||||
|
||||
function generateUsers(nb) {
|
||||
const users = [];
|
||||
for (let i = 0; i < nb; i++) {
|
||||
users.push({
|
||||
user: {
|
||||
name: "",
|
||||
mailbox: names[i],
|
||||
host: "provider.com",
|
||||
},
|
||||
id: i,
|
||||
});
|
||||
}
|
||||
return users;
|
||||
}
|
||||
|
||||
function randomString(length) {
|
||||
let result = "";
|
||||
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
const charactersLength = characters.length;
|
||||
for (let i = 0; i < length; i++) {
|
||||
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function randomInt(length) {
|
||||
return (Math.random() * Math.pow(10, length)).toFixed();
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
generateAttrs,
|
||||
generateUsers,
|
||||
};
|
||||
Reference in New Issue
Block a user