2017-07-24 06:01:25 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const expect = require("chai").expect;
|
|
|
|
|
|
|
|
const Msg = require("../../src/models/msg");
|
2017-11-29 06:22:03 +00:00
|
|
|
const User = require("../../src/models/user");
|
2017-07-24 06:01:25 +00:00
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
describe("Msg", function () {
|
2017-11-29 06:22:03 +00:00
|
|
|
["from", "target"].forEach((prop) => {
|
2020-03-21 20:55:36 +00:00
|
|
|
it(`should keep a copy of the original user in the \`${prop}\` property`, function () {
|
2017-11-29 06:22:03 +00:00
|
|
|
const prefixLookup = {a: "&", o: "@"};
|
2019-07-17 09:33:59 +00:00
|
|
|
const user = new User(
|
|
|
|
{
|
|
|
|
modes: ["o"],
|
|
|
|
nick: "foo",
|
|
|
|
},
|
|
|
|
prefixLookup
|
|
|
|
);
|
2017-11-29 06:22:03 +00:00
|
|
|
const msg = new Msg({[prop]: user});
|
|
|
|
|
|
|
|
// Mutating the user
|
|
|
|
user.setModes(["a"], prefixLookup);
|
|
|
|
user.nick = "bar";
|
|
|
|
|
|
|
|
// Message's `.from`/etc. should still refer to the original user
|
|
|
|
expect(msg[prop]).to.deep.equal({mode: "@", nick: "foo"});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
describe("#findPreview(link)", function () {
|
2017-07-24 06:01:25 +00:00
|
|
|
const msg = new Msg({
|
2019-07-17 09:33:59 +00:00
|
|
|
previews: [
|
|
|
|
{
|
|
|
|
body: "",
|
|
|
|
head: "Example Domain",
|
|
|
|
link: "https://example.org/",
|
|
|
|
thumb: "",
|
|
|
|
type: "link",
|
|
|
|
shown: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
body: "",
|
|
|
|
head: "The Lounge",
|
|
|
|
link: "https://thelounge.chat/",
|
|
|
|
thumb: "",
|
|
|
|
type: "link",
|
|
|
|
shown: true,
|
|
|
|
},
|
|
|
|
],
|
2017-07-24 06:01:25 +00:00
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should find a preview given an existing link", function () {
|
2019-07-17 09:33:59 +00:00
|
|
|
expect(msg.findPreview("https://thelounge.chat/").head).to.equal("The Lounge");
|
2017-07-24 06:01:25 +00:00
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should not find a preview that does not exist", function () {
|
2019-07-17 09:33:59 +00:00
|
|
|
expect(msg.findPreview("https://github.com/thelounge/thelounge")).to.be.undefined;
|
2017-07-24 06:01:25 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|