Add tests for editing network
This commit is contained in:
parent
f86d73972d
commit
c1406adcb2
@ -5,6 +5,7 @@ const Chan = require("../../src/models/chan");
|
||||
const Msg = require("../../src/models/msg");
|
||||
const User = require("../../src/models/user");
|
||||
const Network = require("../../src/models/network");
|
||||
const Helper = require("../../src/helper");
|
||||
|
||||
describe("Network", function() {
|
||||
describe("#export()", function() {
|
||||
@ -49,6 +50,102 @@ describe("Network", function() {
|
||||
});
|
||||
});
|
||||
|
||||
it("validate should set correct defaults", function() {
|
||||
const network = new Network({
|
||||
host: "localhost",
|
||||
});
|
||||
|
||||
expect(network.validate()).to.be.true;
|
||||
expect(network.nick).to.equal("thelounge");
|
||||
expect(network.username).to.equal("thelounge");
|
||||
expect(network.realname).to.equal("The Lounge User");
|
||||
expect(network.port).to.equal(6667);
|
||||
|
||||
const network2 = new Network({
|
||||
host: "localhost",
|
||||
nick: "@Invalid Nick?",
|
||||
});
|
||||
expect(network2.validate()).to.be.true;
|
||||
expect(network2.username).to.equal("InvalidNick");
|
||||
});
|
||||
|
||||
it("lockNetwork should be enforced when validating", function() {
|
||||
Helper.config.lockNetwork = true;
|
||||
Helper.config.public = false;
|
||||
|
||||
const network = new Network({
|
||||
host: "",
|
||||
port: 1337,
|
||||
tls: false,
|
||||
rejectUnauthorized: false,
|
||||
});
|
||||
expect(network.validate()).to.be.true;
|
||||
expect(network.host).to.equal("chat.freenode.net");
|
||||
expect(network.port).to.equal(6697);
|
||||
expect(network.tls).to.be.true;
|
||||
expect(network.rejectUnauthorized).to.be.true;
|
||||
|
||||
Helper.config.public = true;
|
||||
|
||||
const network2 = new Network({
|
||||
host: "some.fake.tld",
|
||||
});
|
||||
expect(network2.validate()).to.be.true;
|
||||
expect(network2.host).to.equal("chat.freenode.net");
|
||||
|
||||
Helper.config.lockNetwork = false;
|
||||
Helper.config.public = false;
|
||||
});
|
||||
|
||||
it("editing a network should enforce correct types", function() {
|
||||
let saveCalled = false;
|
||||
|
||||
const network = new Network();
|
||||
network.edit({
|
||||
save() {
|
||||
saveCalled = true;
|
||||
},
|
||||
}, {
|
||||
nick: "newNick",
|
||||
host: "new.tld",
|
||||
name: "Lounge Test Network",
|
||||
port: "1337",
|
||||
tls: undefined,
|
||||
rejectUnauthorized: undefined,
|
||||
username: 1234,
|
||||
password: 4567,
|
||||
realname: 8901,
|
||||
commands: "/command 1 2 3\r\n/ping HELLO\r\r\r\r/whois test\r\n\r\n",
|
||||
ip: "newIp",
|
||||
hostname: "newHostname",
|
||||
id: 1000000,
|
||||
guid: "newGuid",
|
||||
});
|
||||
|
||||
expect(saveCalled).to.be.true;
|
||||
expect(network.id).to.not.equal(1000000);
|
||||
expect(network.guid).to.not.equal("newGuid");
|
||||
expect(network.ip).to.be.null;
|
||||
expect(network.hostname).to.be.null;
|
||||
|
||||
expect(network.name).to.equal("Lounge Test Network");
|
||||
expect(network.channels[0].name).to.equal("Lounge Test Network");
|
||||
|
||||
expect(network.nick).to.equal("newNick");
|
||||
expect(network.host).to.equal("new.tld");
|
||||
expect(network.port).to.equal(1337);
|
||||
expect(network.tls).to.be.false;
|
||||
expect(network.rejectUnauthorized).to.be.false;
|
||||
expect(network.username).to.equal("1234");
|
||||
expect(network.password).to.equal("4567");
|
||||
expect(network.realname).to.equal("8901");
|
||||
expect(network.commands).to.deep.equal([
|
||||
"/command 1 2 3",
|
||||
"/ping HELLO",
|
||||
"/whois test",
|
||||
]);
|
||||
});
|
||||
|
||||
it("should generate uuid (v4) for each network", function() {
|
||||
const network1 = new Network();
|
||||
const network2 = new Network();
|
||||
|
Loading…
Reference in New Issue
Block a user