Add tests for getFilteredClone methods

This commit is contained in:
Pavel Djundik 2017-11-30 23:46:55 +02:00
parent 552f3da67e
commit fe1c7612f5
2 changed files with 126 additions and 5 deletions

View File

@ -145,4 +145,91 @@ describe("Chan", function() {
]); ]);
}); });
}); });
describe("#getFilteredClone(lastActiveChannel, lastMessage)", function() {
it("should send empty user list", function() {
const chan = new Chan();
chan.setUser(new User({nick: "test"}));
expect(chan.getFilteredClone().users).to.be.empty;
});
it("should keep necessary properties", function() {
const chan = new Chan();
expect(chan.getFilteredClone()).to.be.an("object").that.has.all.keys(
"firstUnread",
"highlight",
"id",
"key",
"messages",
"name",
"topic",
"type",
"unread",
"users"
);
});
it("should send only last message for non active channel", function() {
const chan = new Chan({
id: 1337,
messages: [
new Msg({id: 10}),
new Msg({id: 11}),
new Msg({id: 12}),
new Msg({id: 13}),
],
});
expect(chan.id).to.equal(1337);
const messages = chan.getFilteredClone(999).messages;
expect(messages).to.have.lengthOf(1);
expect(messages[0].id).to.equal(13);
});
it("should send more messages for active channel", function() {
const chan = new Chan({
id: 1337,
messages: [
new Msg({id: 10}),
new Msg({id: 11}),
new Msg({id: 12}),
new Msg({id: 13}),
],
});
expect(chan.id).to.equal(1337);
const messages = chan.getFilteredClone(1337).messages;
expect(messages).to.have.lengthOf(4);
expect(messages[0].id).to.equal(10);
expect(messages[3].id).to.equal(13);
});
it("should only send new messages", function() {
const chan = new Chan({
id: 1337,
messages: [
new Msg({id: 10}),
new Msg({id: 11}),
new Msg({id: 12}),
new Msg({id: 13}),
new Msg({id: 14}),
new Msg({id: 15}),
],
});
expect(chan.id).to.equal(1337);
const messages = chan.getFilteredClone(1337, 12).messages;
expect(messages).to.have.lengthOf(3);
expect(messages[0].id).to.equal(13);
expect(messages[2].id).to.equal(15);
});
});
}); });

View File

@ -1,10 +1,10 @@
"use strict"; "use strict";
var expect = require("chai").expect; const expect = require("chai").expect;
const Chan = require("../../src/models/chan");
var Chan = require("../../src/models/chan"); const Msg = require("../../src/models/msg");
var Msg = require("../../src/models/msg"); const User = require("../../src/models/user");
var Network = require("../../src/models/network"); const Network = require("../../src/models/network");
describe("Network", function() { describe("Network", function() {
describe("#export()", function() { describe("#export()", function() {
@ -91,4 +91,38 @@ describe("Network", function() {
expect(network.channels[1].messages[2].text).to.equal("message after network creation"); expect(network.channels[1].messages[2].text).to.equal("message after network creation");
}); });
}); });
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"
);
});
});
}); });