@averagehelper/corde
Version:
A simple library for Discord bot tests. (Republished fork to demonstrate a bugfix)
65 lines (64 loc) • 2.69 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.toRemoveReaction = void 0;
const testReport_1 = require("../../interfaces/testReport");
const utils_1 = __importDefault(require("../../../utils/utils"));
function toRemoveReaction(commandName, isNot, cordeBot, removedReactions, messageData) {
return __awaiter(this, void 0, void 0, function* () {
let expectation = "";
let output = "";
let testSuccessfully = false;
expectation = removedReactions.join();
try {
yield cordeBot.sendTextMessage(commandName);
yield utils_1.default.wait(utils_1.default.delayValue);
const message = yield cordeBot.findMessage(messageData);
if (message) {
const reactions = yield cordeBot.waitForRemovedReactions(message, removedReactions.length);
testSuccessfully = reactionsExistsIn(reactions, removedReactions);
output = reactions.map((v) => v.emoji.name).join();
}
if (isNot) {
testSuccessfully = !testSuccessfully;
}
}
catch (error) {
testSuccessfully = false;
if (error instanceof Error) {
output = error.message;
}
else {
output = error;
}
}
return new testReport_1.TestReport({
commandName,
expectation,
output,
hasPassed: testSuccessfully,
isNot,
showExpectAndOutputValue: false,
});
});
}
exports.toRemoveReaction = toRemoveReaction;
function reactionsExistsIn(reactions, expectation) {
for (const expect of expectation) {
if (!reactions.find((r) => r.emoji.name === expect)) {
return false;
}
}
return true;
}