2022-06-19 00:25:21 +00:00
|
|
|
import {expect} from "chai";
|
2017-07-24 06:01:25 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
import Msg from "../../server/models/msg";
|
|
|
|
import User from "../../server/models/user";
|
2024-04-17 18:20:47 +00:00
|
|
|
import {LinkPreview} from "../../shared/types/msg";
|
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 () {
|
2021-07-21 07:30:07 +00:00
|
|
|
const prefixLookup = {modeToSymbol: {a: "&", o: "@"}};
|
2019-07-17 09:33:59 +00:00
|
|
|
const user = new User(
|
|
|
|
{
|
|
|
|
modes: ["o"],
|
|
|
|
nick: "foo",
|
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
prefixLookup as any
|
2019-07-17 09:33:59 +00:00
|
|
|
);
|
2017-11-29 06:22:03 +00:00
|
|
|
const msg = new Msg({[prop]: user});
|
|
|
|
|
|
|
|
// Mutating the user
|
2022-06-19 00:25:21 +00:00
|
|
|
user.setModes(["a"], prefixLookup as any);
|
2017-11-29 06:22:03 +00:00
|
|
|
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,
|
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
] as LinkPreview[],
|
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 () {
|
2022-06-19 00:25:21 +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
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|