2016-03-16 05:41:19 +00:00
|
|
|
"use strict";
|
|
|
|
|
2017-11-30 21:46:55 +00:00
|
|
|
const expect = require("chai").expect;
|
|
|
|
const Chan = require("../../src/models/chan");
|
|
|
|
const Msg = require("../../src/models/msg");
|
|
|
|
const User = require("../../src/models/user");
|
|
|
|
const Network = require("../../src/models/network");
|
2016-03-16 05:41:19 +00:00
|
|
|
|
|
|
|
describe("Network", function() {
|
|
|
|
describe("#export()", function() {
|
|
|
|
it("should produce an valid object", function() {
|
2018-01-11 11:33:36 +00:00
|
|
|
const network = new Network({
|
2016-12-18 09:24:50 +00:00
|
|
|
awayMessage: "I am away",
|
2016-10-02 07:37:37 +00:00
|
|
|
name: "networkName",
|
|
|
|
channels: [
|
2017-04-01 08:33:17 +00:00
|
|
|
new Chan({name: "#thelounge", key: ""}),
|
|
|
|
new Chan({name: "&foobar", key: ""}),
|
|
|
|
new Chan({name: "#secret", key: "foo"}),
|
|
|
|
new Chan({name: "&secure", key: "bar"}),
|
2016-10-02 07:37:37 +00:00
|
|
|
new Chan({name: "Channel List", type: Chan.Type.SPECIAL}),
|
|
|
|
new Chan({name: "PrivateChat", type: Chan.Type.QUERY}),
|
2017-11-15 06:35:15 +00:00
|
|
|
],
|
2016-10-02 07:37:37 +00:00
|
|
|
});
|
2016-05-12 11:30:23 +00:00
|
|
|
network.setNick("chillin`");
|
2016-03-16 05:41:19 +00:00
|
|
|
|
|
|
|
expect(network.export()).to.deep.equal({
|
2016-12-18 09:24:50 +00:00
|
|
|
awayMessage: "I am away",
|
2016-03-16 05:41:19 +00:00
|
|
|
name: "networkName",
|
|
|
|
host: "",
|
|
|
|
port: 6667,
|
|
|
|
tls: false,
|
|
|
|
password: "",
|
|
|
|
username: "",
|
|
|
|
realname: "",
|
|
|
|
commands: [],
|
2016-05-12 11:30:23 +00:00
|
|
|
nick: "chillin`",
|
2016-04-03 05:12:49 +00:00
|
|
|
ip: null,
|
2016-06-19 17:12:42 +00:00
|
|
|
hostname: null,
|
|
|
|
channels: [
|
2017-04-01 08:33:17 +00:00
|
|
|
{name: "#thelounge", key: ""},
|
|
|
|
{name: "&foobar", key: ""},
|
|
|
|
{name: "#secret", key: "foo"},
|
|
|
|
{name: "&secure", key: "bar"},
|
2018-01-30 16:46:34 +00:00
|
|
|
{name: "PrivateChat", type: "query"},
|
2017-11-15 06:35:15 +00:00
|
|
|
],
|
2016-03-16 05:41:19 +00:00
|
|
|
});
|
|
|
|
});
|
2016-10-02 07:37:37 +00:00
|
|
|
|
|
|
|
it("lobby should be at the top", function() {
|
2018-01-11 11:33:36 +00:00
|
|
|
const network = new Network({
|
2016-10-02 07:37:37 +00:00
|
|
|
name: "Super Nice Network",
|
|
|
|
channels: [
|
|
|
|
new Chan({name: "AAAA!", type: Chan.Type.QUERY}),
|
|
|
|
new Chan({name: "#thelounge"}),
|
|
|
|
new Chan({name: "&foobar"}),
|
2017-11-15 06:35:15 +00:00
|
|
|
],
|
2016-10-02 07:37:37 +00:00
|
|
|
});
|
|
|
|
network.channels.push(new Chan({name: "#swag"}));
|
|
|
|
|
|
|
|
expect(network.channels[0].name).to.equal("Super Nice Network");
|
|
|
|
expect(network.channels[0].type).to.equal(Chan.Type.LOBBY);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should maintain channel reference", function() {
|
2018-01-11 11:33:36 +00:00
|
|
|
const chan = new Chan({
|
2016-10-02 07:37:37 +00:00
|
|
|
name: "#506-bug-fix",
|
|
|
|
messages: [
|
|
|
|
new Msg({
|
2017-11-15 06:35:15 +00:00
|
|
|
text: "message in constructor",
|
|
|
|
}),
|
|
|
|
],
|
2016-10-02 07:37:37 +00:00
|
|
|
});
|
|
|
|
|
2018-01-11 11:33:36 +00:00
|
|
|
const network = new Network({
|
2016-10-02 07:37:37 +00:00
|
|
|
name: "networkName",
|
|
|
|
channels: [
|
2017-11-15 06:35:15 +00:00
|
|
|
chan,
|
|
|
|
],
|
2016-10-02 07:37:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
chan.messages.push(new Msg({
|
2017-11-15 06:35:15 +00:00
|
|
|
text: "message in original instance",
|
2016-10-02 07:37:37 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
network.channels[1].messages.push(new Msg({
|
2017-11-15 06:35:15 +00:00
|
|
|
text: "message after network creation",
|
2016-10-02 07:37:37 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
expect(network.channels[1].messages).to.have.lengthOf(3);
|
|
|
|
expect(network.channels[1].messages[0].text).to.equal("message in constructor");
|
|
|
|
expect(network.channels[1].messages[1].text).to.equal("message in original instance");
|
|
|
|
expect(network.channels[1].messages[2].text).to.equal("message after network creation");
|
|
|
|
});
|
2016-03-16 05:41:19 +00:00
|
|
|
});
|
2017-11-30 21:46:55 +00:00
|
|
|
|
|
|
|
describe("#getFilteredClone(lastActiveChannel, lastMessage)", function() {
|
|
|
|
it("should filter channels", function() {
|
|
|
|
const chan = new Chan();
|
|
|
|
chan.setUser(new User({nick: "test"}));
|
|
|
|
|
|
|
|
const network = new Network({
|
|
|
|
channels: [
|
|
|
|
chan,
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(network.channels[0].users).to.be.empty;
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should keep necessary properties", function() {
|
|
|
|
const network = new Network();
|
|
|
|
|
|
|
|
expect(network.getFilteredClone()).to.be.an("object").that.has.all.keys(
|
|
|
|
"channels",
|
|
|
|
"commands",
|
|
|
|
"host",
|
|
|
|
"hostname",
|
|
|
|
"id",
|
|
|
|
"ip",
|
|
|
|
"name",
|
|
|
|
"port",
|
|
|
|
"realname",
|
|
|
|
"serverOptions",
|
|
|
|
"tls",
|
|
|
|
"username"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2016-03-16 05:41:19 +00:00
|
|
|
});
|