improve saveMessage (switch to class) and started to test
This commit is contained in:
@@ -1,52 +1,40 @@
|
||||
process.env["NODE_DEV"] = "TEST";
|
||||
const { saveFromParsedData } = require("../../mails/storeMessage");
|
||||
const { TestDb } = require("../sql/test-utilsDb");
|
||||
const MYSQL = require("../../db/config.json").MYSQL;
|
||||
const { getAddresseId } = require("../../db/mail");
|
||||
const { generateAttrs, generateUsers } = require("../test-utils/test-attrsUtils");
|
||||
const { registerMessageInApp, roomType } = require("../../mails/saveMessage");
|
||||
|
||||
let db;
|
||||
beforeAll(async () => {
|
||||
const options = {
|
||||
databaseOptions: {
|
||||
host: "localhost",
|
||||
port: 3306,
|
||||
user: MYSQL.user,
|
||||
password: MYSQL.pwd,
|
||||
database: "mail_test",
|
||||
},
|
||||
dbSchema: "../../sql/structureV2.sql",
|
||||
};
|
||||
db = new TestDb(options);
|
||||
await db.init();
|
||||
});
|
||||
jest.mock("../../db/mail");
|
||||
|
||||
afterAll(async () => {
|
||||
db.cleanTables();
|
||||
});
|
||||
// todo mock db
|
||||
|
||||
describe("saveMessage", async () => {
|
||||
describe("rooms", async () => {
|
||||
it("messages not related and from same sender should be in the same room", async () => {
|
||||
await saveFromParsedData(
|
||||
{
|
||||
to: { value: [{ address: "address1@email.com" }] },
|
||||
from: { value: [{ address: "address2@email.com" }] },
|
||||
messageId: "<messageId1>",
|
||||
},
|
||||
1,
|
||||
);
|
||||
await saveFromParsedData(
|
||||
{
|
||||
to: { value: [{ address: "address1@email.com" }] },
|
||||
from: { value: [{ address: "address2@email.com" }] },
|
||||
messageId: "<messageId2>",
|
||||
},
|
||||
2,
|
||||
);
|
||||
// todo call parser
|
||||
const query = ""
|
||||
db.execQueryAsync().then((res) => {
|
||||
expect(res.length).toBe(2);
|
||||
})
|
||||
describe("saveMessage", () => {
|
||||
describe("is not a reply", () => {
|
||||
it("first DM from user should create a DM room", async () => {
|
||||
const users = generateUsers(2);
|
||||
const attrs = generateAttrs({ from: [users[0].user], to: [users[1].user] });
|
||||
|
||||
getAddresseId.mockReturnValue(users[1].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")
|
||||
.mockImplementation(() => undefined);
|
||||
|
||||
await register.save();
|
||||
|
||||
expect(createOrRegisterOnExistence).toHaveBeenCalledWith(users[1].id, roomType.DM);
|
||||
});
|
||||
// it("DM message from user should be added to DM room", async () => {
|
||||
|
||||
// });
|
||||
// it("first GROUP message should create a group", () => {});
|
||||
});
|
||||
describe("replies", () => {
|
||||
it("", () => {});
|
||||
});
|
||||
describe("", () => {});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user