@averagehelper/corde
Version:
A simple library for Discord bot tests. (Republished fork to demonstrate a bugfix)
123 lines (122 loc) • 5.12 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExpectMatchesWithNot = void 0;
const testCollector_1 = require("../common/testCollector");
const expectMatches_1 = require("./expectMatches");
const toEditMessage_1 = require("./expectMatches/message/toEditMessage");
const toPinMessage_1 = require("./expectMatches/message/toPinMessage");
const toRemoveReaction_1 = require("./expectMatches/message/toRemoveReaction");
const toUnpinMessage_1 = require("./expectMatches/message/toUnpinMessage");
const toSetRolePermission_1 = require("./expectMatches/role/toSetRolePermission");
class ExpectMatches {
constructor(commandName, isNot) {
this._commandName = commandName;
this._isNot = isNot;
}
toEditMessage(message, newValue) {
testCollector_1.testCollector.addTestFunction((cordeBot) => {
return this.operationFactory(toEditMessage_1.ToEditMessage, cordeBot, message, newValue);
});
}
toPin(message) {
let data;
if (typeof message === "string") {
data = { id: message };
}
else {
data = message;
}
testCollector_1.testCollector.addTestFunction((cordeBot) => {
return this.operationFactory(toPinMessage_1.ToPinMessage, cordeBot, data);
});
}
toUnPin(message) {
let data;
if (typeof message === "string") {
data = { id: message };
}
else {
data = message;
}
testCollector_1.testCollector.addTestFunction((cordeBot) => {
return this.operationFactory(toUnpinMessage_1.ToUnpinMessage, cordeBot, data);
});
}
toReturn(expect) {
testCollector_1.testCollector.addTestFunction((cordeBot) => expectMatches_1.toReturn(this._commandName, this._isNot, cordeBot, expect));
}
toAddReaction(...reaction) {
testCollector_1.testCollector.addTestFunction((cordeBot) => expectMatches_1.toAddReaction(this._commandName, this._isNot, cordeBot, reaction));
}
toRemoveReaction(reactions, message) {
testCollector_1.testCollector.addTestFunction((cordeBot) => {
if (Array.isArray(reactions)) {
return toRemoveReaction_1.toRemoveReaction(this._commandName, this._isNot, cordeBot, reactions, message);
}
return toRemoveReaction_1.toRemoveReaction(this._commandName, this._isNot, cordeBot, [reactions], message);
});
}
toSetRoleColor(color, role) {
const data = this.getRoleData(role);
testCollector_1.testCollector.addTestFunction((cordeBot) => {
return expectMatches_1.toSetRoleColor(this._commandName, this._isNot, cordeBot, color, data);
});
}
toDeleteRole(role) {
const data = this.getRoleData(role);
testCollector_1.testCollector.addTestFunction((cordeBot) => {
return expectMatches_1.toDeleteRole(this._commandName, this._isNot, cordeBot, data);
});
}
toSetRoleMentionable(mentionable, roleData) {
const data = this.getRoleData(roleData);
testCollector_1.testCollector.addTestFunction((cordeBot) => {
return this.operationFactory(expectMatches_1.ToSetRoleMentionable, cordeBot, mentionable, data);
});
}
toSetRoleHoist(hoist, roleData) {
const data = this.getRoleData(roleData);
testCollector_1.testCollector.addTestFunction((cordeBot) => {
return this.operationFactory(expectMatches_1.ToSetRoleHoist, cordeBot, hoist, data);
});
}
toRenameRole(newName, roleData) {
const data = this.getRoleData(roleData);
testCollector_1.testCollector.addTestFunction((cordeBot) => {
return this.operationFactory(expectMatches_1.ToRenameRole, cordeBot, newName, data);
});
}
toSetRolePosition(newPosition, roleData) {
const data = this.getRoleData(roleData);
testCollector_1.testCollector.addTestFunction((cordeBot) => {
return this.operationFactory(expectMatches_1.ToSetRolePosition, cordeBot, newPosition, data);
});
}
toSetRolePermission(roleData, ...permissions) {
const data = this.getRoleData(roleData);
testCollector_1.testCollector.addTestFunction((cordeBot) => {
return this.operationFactory(toSetRolePermission_1.ToSetRolePermission, cordeBot, permissions, data);
});
}
getRoleData(roleData) {
let data;
if (typeof roleData === "string") {
data = { id: roleData };
}
else {
data = roleData;
}
return data;
}
operationFactory(type, cordeBot, parameter1, parameter2, parameter3) {
const op = new type(cordeBot, this._commandName, this._isNot);
return op.action(parameter1, parameter2, parameter3);
}
}
class ExpectMatchesWithNot extends ExpectMatches {
constructor(commandName) {
super(commandName, false);
this.not = new ExpectMatches(commandName, true);
}
}
exports.ExpectMatchesWithNot = ExpectMatchesWithNot;