thelounge/test/commands/mode.js

138 lines
4.6 KiB
JavaScript
Raw Normal View History

2016-10-08 17:56:41 +02:00
"use strict";
2018-01-11 12:33:36 +01:00
const expect = require("chai").expect;
2016-10-08 17:56:41 +02:00
2018-01-11 12:33:36 +01:00
const Chan = require("../../src/models/chan");
const ModeCommand = require("../../src/plugins/inputs/mode");
2016-10-08 17:56:41 +02:00
describe("Commands", function () {
describe("/mode", function () {
2016-10-08 17:56:41 +02:00
const channel = new Chan({
name: "#thelounge",
2016-10-08 17:56:41 +02:00
});
const lobby = new Chan({
name: "Network Lobby",
type: Chan.Type.LOBBY,
2016-10-08 17:56:41 +02:00
});
const testableNetwork = {
firstCommand: null,
2016-10-08 17:56:41 +02:00
lastCommand: null,
nick: "xPaw",
irc: {
2021-07-03 23:20:28 +02:00
network: {
supports(type) {
if (type.toUpperCase() === "MODES") {
return "4";
}
},
},
raw(...args) {
testableNetwork.firstCommand = testableNetwork.lastCommand;
testableNetwork.lastCommand = args.join(" ");
},
},
2016-10-08 17:56:41 +02:00
};
const testableNetworkNoSupports = Object.assign({}, testableNetwork, {
irc: {
network: {
supports() {
return null;
},
},
raw(...args) {
testableNetworkNoSupports.firstCommand = testableNetworkNoSupports.lastCommand;
testableNetworkNoSupports.lastCommand = args.join(" ");
},
},
});
it("should not mess with the given target", function () {
const test = function (expected, args) {
2016-10-08 17:56:41 +02:00
ModeCommand.input(testableNetwork, channel, "mode", Array.from(args));
expect(testableNetwork.lastCommand).to.equal(expected);
ModeCommand.input(testableNetwork, lobby, "mode", Array.from(args));
expect(testableNetwork.lastCommand).to.equal(expected);
};
test("MODE xPaw +i", ["xPaw", "+i"]);
test("MODE xPaw -w", ["xPaw", "-w"]);
test("MODE #thelounge +o xPaw", ["#thelounge", "+o", "xPaw"]);
test("MODE #thelounge -v xPaw", ["#thelounge", "-v", "xPaw"]);
test("MODE #thelounge +o-o xPaw Max-P", ["#thelounge", "+o-o", "xPaw", "Max-P"]);
test("MODE #thelounge", ["#thelounge"]);
});
it("should assume target if none given", function () {
2016-10-08 17:56:41 +02:00
ModeCommand.input(testableNetwork, channel, "mode", []);
expect(testableNetwork.lastCommand).to.equal("MODE #thelounge");
ModeCommand.input(testableNetwork, lobby, "mode", []);
expect(testableNetwork.lastCommand).to.equal("MODE xPaw");
ModeCommand.input(testableNetwork, channel, "mode", ["+b"]);
expect(testableNetwork.lastCommand).to.equal("MODE #thelounge +b");
ModeCommand.input(testableNetwork, lobby, "mode", ["+b"]);
expect(testableNetwork.lastCommand).to.equal("MODE xPaw +b");
ModeCommand.input(testableNetwork, channel, "mode", ["-o", "hey"]);
expect(testableNetwork.lastCommand).to.equal("MODE #thelounge -o hey");
ModeCommand.input(testableNetwork, lobby, "mode", ["-i", "idk"]);
expect(testableNetwork.lastCommand).to.equal("MODE xPaw -i idk");
});
it("should support shorthand commands", function () {
2016-10-08 17:56:41 +02:00
ModeCommand.input(testableNetwork, channel, "op", ["xPaw"]);
expect(testableNetwork.lastCommand).to.equal("MODE #thelounge +o xPaw");
ModeCommand.input(testableNetwork, channel, "deop", ["xPaw"]);
expect(testableNetwork.lastCommand).to.equal("MODE #thelounge -o xPaw");
ModeCommand.input(testableNetwork, channel, "hop", ["xPaw"]);
expect(testableNetwork.lastCommand).to.equal("MODE #thelounge +h xPaw");
ModeCommand.input(testableNetwork, channel, "dehop", ["xPaw"]);
expect(testableNetwork.lastCommand).to.equal("MODE #thelounge -h xPaw");
ModeCommand.input(testableNetwork, channel, "voice", ["xPaw"]);
expect(testableNetwork.lastCommand).to.equal("MODE #thelounge +v xPaw");
ModeCommand.input(testableNetwork, channel, "devoice", ["xPaw"]);
expect(testableNetwork.lastCommand).to.equal("MODE #thelounge -v xPaw");
});
2016-10-08 17:56:41 +02:00
it("should use ISUPPORT MODES on shorthand commands", function () {
2021-07-03 23:20:28 +02:00
ModeCommand.input(testableNetwork, channel, "voice", ["xPaw", "Max-P"]);
expect(testableNetwork.lastCommand).to.equal("MODE #thelounge +vv xPaw Max-P");
// since the limit for modes on tests is 4, it should send two commands
ModeCommand.input(testableNetwork, channel, "devoice", [
"xPaw",
"Max-P",
"hey",
"idk",
"thelounge",
]);
expect(testableNetwork.firstCommand).to.equal(
"MODE #thelounge -vvvv xPaw Max-P hey idk"
);
2021-07-03 23:20:28 +02:00
expect(testableNetwork.lastCommand).to.equal("MODE #thelounge -v thelounge");
2016-10-08 17:56:41 +02:00
});
2021-07-06 17:48:01 +02:00
it("should fallback to all modes at once for shorthand commands", function () {
ModeCommand.input(testableNetworkNoSupports, channel, "voice", ["xPaw"]);
expect(testableNetworkNoSupports.lastCommand).to.equal("MODE #thelounge +v xPaw");
ModeCommand.input(testableNetworkNoSupports, channel, "devoice", ["xPaw", "Max-P"]);
2021-07-06 17:48:01 +02:00
expect(testableNetworkNoSupports.lastCommand).to.equal(
"MODE #thelounge -vv xPaw Max-P"
);
});
2016-10-08 17:56:41 +02:00
});
});