2022-06-19 00:25:21 +00:00
|
|
|
// @ts-nocheck TODO re-enable
|
|
|
|
import {expect} from "chai";
|
|
|
|
import Client from "../../server/client";
|
2016-10-08 15:56:41 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
import Chan, {ChanType} from "../../server/models/chan";
|
|
|
|
import ModeCommand from "../../server/plugins/inputs/mode";
|
2016-10-08 15:56:41 +00:00
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
describe("Commands", function () {
|
|
|
|
describe("/mode", function () {
|
2016-10-08 15:56:41 +00:00
|
|
|
const channel = new Chan({
|
2017-11-15 06:35:15 +00:00
|
|
|
name: "#thelounge",
|
2016-10-08 15:56:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const lobby = new Chan({
|
|
|
|
name: "Network Lobby",
|
2022-06-19 00:25:21 +00:00
|
|
|
type: ChanType.LOBBY,
|
2016-10-08 15:56:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const testableNetwork = {
|
2021-07-06 18:15:37 +00:00
|
|
|
firstCommand: null,
|
2016-10-08 15:56:41 +00:00
|
|
|
lastCommand: null,
|
|
|
|
nick: "xPaw",
|
|
|
|
irc: {
|
2021-07-03 21:20:28 +00:00
|
|
|
network: {
|
2022-06-19 00:25:21 +00:00
|
|
|
supports(type: string) {
|
2021-07-03 21:20:28 +00:00
|
|
|
if (type.toUpperCase() === "MODES") {
|
|
|
|
return "4";
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
raw(...args: string[]) {
|
2021-07-06 18:15:37 +00:00
|
|
|
testableNetwork.firstCommand = testableNetwork.lastCommand;
|
2017-11-22 06:39:32 +00:00
|
|
|
testableNetwork.lastCommand = args.join(" ");
|
2017-11-15 06:35:15 +00:00
|
|
|
},
|
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
} as {
|
|
|
|
firstCommand: string | null;
|
|
|
|
lastCommand: string | null;
|
|
|
|
nick: string;
|
|
|
|
irc: {
|
|
|
|
network: {
|
|
|
|
supports(type: string): string;
|
|
|
|
};
|
|
|
|
raw(...args: string[]): void;
|
|
|
|
};
|
2016-10-08 15:56:41 +00:00
|
|
|
};
|
|
|
|
|
2021-07-04 01:01:45 +00:00
|
|
|
const testableNetworkNoSupports = Object.assign({}, testableNetwork, {
|
|
|
|
irc: {
|
|
|
|
network: {
|
|
|
|
supports() {
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
raw(...args: string[]) {
|
2021-07-06 18:15:37 +00:00
|
|
|
testableNetworkNoSupports.firstCommand = testableNetworkNoSupports.lastCommand;
|
2021-07-04 01:01:45 +00:00
|
|
|
testableNetworkNoSupports.lastCommand = args.join(" ");
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
it("should not mess with the given target", function (this: CommandContext) {
|
|
|
|
const test = function (expected: string, args: string[]) {
|
2016-10-08 15:56:41 +00: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"]);
|
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should assume target if none given", function () {
|
2016-10-08 15:56:41 +00: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");
|
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should support shorthand commands", function () {
|
2016-10-08 15:56:41 +00: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");
|
2021-07-04 01:01:45 +00:00
|
|
|
});
|
2016-10-08 15:56:41 +00:00
|
|
|
|
2021-07-04 01:01:45 +00:00
|
|
|
it("should use ISUPPORT MODES on shorthand commands", function () {
|
2021-07-03 21:20:28 +00: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",
|
|
|
|
]);
|
2021-07-06 18:15:37 +00:00
|
|
|
expect(testableNetwork.firstCommand).to.equal(
|
|
|
|
"MODE #thelounge -vvvv xPaw Max-P hey idk"
|
|
|
|
);
|
2021-07-03 21:20:28 +00:00
|
|
|
expect(testableNetwork.lastCommand).to.equal("MODE #thelounge -v thelounge");
|
2016-10-08 15:56:41 +00:00
|
|
|
});
|
2021-07-04 01:01:45 +00:00
|
|
|
|
2021-07-06 15:48:01 +00:00
|
|
|
it("should fallback to all modes at once for shorthand commands", function () {
|
2021-07-04 01:01:45 +00:00
|
|
|
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 15:48:01 +00:00
|
|
|
expect(testableNetworkNoSupports.lastCommand).to.equal(
|
|
|
|
"MODE #thelounge -vv xPaw Max-P"
|
|
|
|
);
|
2021-07-04 01:01:45 +00:00
|
|
|
});
|
2016-10-08 15:56:41 +00:00
|
|
|
});
|
|
|
|
});
|