2016-03-15 05:40:48 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var expect = require("chai").expect;
|
|
|
|
|
|
|
|
var Chan = require("../../src/models/chan");
|
2017-07-24 06:01:25 +00:00
|
|
|
var Msg = require("../../src/models/msg");
|
2016-03-15 05:40:48 +00:00
|
|
|
var User = require("../../src/models/user");
|
|
|
|
|
|
|
|
describe("Chan", function() {
|
2017-07-24 06:01:25 +00:00
|
|
|
describe("#findMessage(id)", function() {
|
|
|
|
const chan = new Chan({
|
|
|
|
messages: [
|
|
|
|
new Msg(),
|
|
|
|
new Msg({
|
2017-11-15 06:35:15 +00:00
|
|
|
text: "Message to be found",
|
2017-07-24 06:01:25 +00:00
|
|
|
}),
|
2017-11-15 06:35:15 +00:00
|
|
|
new Msg(),
|
|
|
|
],
|
2017-07-24 06:01:25 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should find a message in the list of messages", function() {
|
|
|
|
expect(chan.findMessage(1).text).to.equal("Message to be found");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should not find a message that does not exist", function() {
|
|
|
|
expect(chan.findMessage(42)).to.be.undefined;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-03-18 04:52:17 +00:00
|
|
|
describe("#sortUsers(irc)", function() {
|
2016-09-24 16:34:35 +00:00
|
|
|
var network = {
|
|
|
|
network: {
|
|
|
|
options: {
|
|
|
|
PREFIX: [
|
|
|
|
{symbol: "~", mode: "q"},
|
|
|
|
{symbol: "&", mode: "a"},
|
|
|
|
{symbol: "@", mode: "o"},
|
|
|
|
{symbol: "%", mode: "h"},
|
2017-11-15 06:35:15 +00:00
|
|
|
{symbol: "+", mode: "v"},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2016-09-24 16:34:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var prefixLookup = {};
|
|
|
|
|
2017-04-08 12:34:31 +00:00
|
|
|
network.network.options.PREFIX.forEach((mode) => {
|
2016-09-24 16:34:35 +00:00
|
|
|
prefixLookup[mode.mode] = mode.symbol;
|
|
|
|
});
|
|
|
|
|
|
|
|
var makeUser = function(nick) {
|
|
|
|
return new User({nick: nick}, prefixLookup);
|
|
|
|
};
|
|
|
|
|
|
|
|
var getUserNames = function(chan) {
|
2017-04-08 12:34:31 +00:00
|
|
|
return chan.users.map((u) => u.nick);
|
2016-09-24 16:34:35 +00:00
|
|
|
};
|
2016-03-15 05:40:48 +00:00
|
|
|
|
|
|
|
it("should sort a simple user list", function() {
|
|
|
|
var chan = new Chan({users: [
|
2017-11-15 06:35:15 +00:00
|
|
|
"JocelynD", "YaManicKill", "astorije", "xPaw", "Max-P",
|
2016-03-15 05:40:48 +00:00
|
|
|
].map(makeUser)});
|
2016-09-24 16:34:35 +00:00
|
|
|
chan.sortUsers(network);
|
2016-03-15 05:40:48 +00:00
|
|
|
|
|
|
|
expect(getUserNames(chan)).to.deep.equal([
|
2017-11-15 06:35:15 +00:00
|
|
|
"astorije", "JocelynD", "Max-P", "xPaw", "YaManicKill",
|
2016-03-15 05:40:48 +00:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should group users by modes", function() {
|
|
|
|
var chan = new Chan({users: [
|
2016-09-24 16:34:35 +00:00
|
|
|
new User({nick: "JocelynD", modes: ["a", "o"]}, prefixLookup),
|
|
|
|
new User({nick: "YaManicKill", modes: ["v"]}, prefixLookup),
|
|
|
|
new User({nick: "astorije", modes: ["h"]}, prefixLookup),
|
|
|
|
new User({nick: "xPaw", modes: ["q"]}, prefixLookup),
|
|
|
|
new User({nick: "Max-P", modes: ["o"]}, prefixLookup),
|
2016-03-15 05:40:48 +00:00
|
|
|
]});
|
2016-09-24 16:34:35 +00:00
|
|
|
chan.sortUsers(network);
|
2016-03-15 05:40:48 +00:00
|
|
|
|
|
|
|
expect(getUserNames(chan)).to.deep.equal([
|
2017-11-15 06:35:15 +00:00
|
|
|
"xPaw", "JocelynD", "Max-P", "astorije", "YaManicKill",
|
2016-03-15 05:40:48 +00:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should sort a mix of users and modes", function() {
|
|
|
|
var chan = new Chan({users: [
|
2016-09-24 16:34:35 +00:00
|
|
|
new User({nick: "JocelynD"}, prefixLookup),
|
|
|
|
new User({nick: "YaManicKill", modes: ["o"]}, prefixLookup),
|
|
|
|
new User({nick: "astorije"}, prefixLookup),
|
|
|
|
new User({nick: "xPaw"}, prefixLookup),
|
|
|
|
new User({nick: "Max-P", modes: ["o"]}, prefixLookup),
|
2016-03-15 05:40:48 +00:00
|
|
|
]});
|
2016-09-24 16:34:35 +00:00
|
|
|
chan.sortUsers(network);
|
2016-03-15 05:40:48 +00:00
|
|
|
|
|
|
|
expect(getUserNames(chan)).to.deep.equal(
|
|
|
|
["Max-P", "YaManicKill", "astorije", "JocelynD", "xPaw"]
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should be case-insensitive", function() {
|
|
|
|
var chan = new Chan({users: ["aB", "Ad", "AA", "ac"].map(makeUser)});
|
2016-09-24 16:34:35 +00:00
|
|
|
chan.sortUsers(network);
|
2016-03-15 05:40:48 +00:00
|
|
|
|
|
|
|
expect(getUserNames(chan)).to.deep.equal(["AA", "aB", "ac", "Ad"]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should parse special characters successfully", function() {
|
|
|
|
var chan = new Chan({users: [
|
|
|
|
"[foo", "]foo", "(foo)", "{foo}", "<foo>", "_foo", "@foo", "^foo",
|
2017-11-15 06:35:15 +00:00
|
|
|
"&foo", "!foo", "+foo", "Foo",
|
2016-03-15 05:40:48 +00:00
|
|
|
].map(makeUser)});
|
2016-09-24 16:34:35 +00:00
|
|
|
chan.sortUsers(network);
|
2016-03-15 05:40:48 +00:00
|
|
|
|
|
|
|
expect(getUserNames(chan)).to.deep.equal([
|
|
|
|
"!foo", "&foo", "(foo)", "+foo", "<foo>", "@foo", "[foo", "]foo",
|
2017-11-15 06:35:15 +00:00
|
|
|
"^foo", "_foo", "Foo", "{foo}",
|
2016-03-15 05:40:48 +00:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|