UNPKG

corde

Version:

A simple library for Discord bot tests

81 lines (67 loc) 1.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true, }); exports.ExpectTest = void 0; const utils_1 = require("../../utils"); class ExpectTest { constructor({ isNot, command, cordeBot, timeout, testName, isCascade, guildId, channelId, channelIdToSendCommand, }) { this.isNot = isNot; this.command = command; this.cordeBot = cordeBot; this.hasPassed = false; this.timeout = timeout; this.testName = testName; this.isCascade = isCascade ?? false; this.guildId = guildId; this.channelIdToSendCommand = channelIdToSendCommand; this.channelId = channelId; } invertHasPassedIfIsNot() { if (this.isNot) { this.hasPassed = !this.hasPassed; } } sendCommandMessage(forceSend) { if (!this.isCascade || forceSend) { return this.cordeBot.sendTextMessage(this.command, this.channelIdToSendCommand); } return Promise.resolve(); } createFailedTest(...messages) { const report = this.createReport(...messages); report.pass = false; return report; } createPassTest() { return { pass: true, testName: this.testName, }; } createReport(...messages) { let message = ""; if (messages.length) { message = (0, utils_1.buildReportMessage)(...messages); } return { testName: this.testName, pass: this.hasPassed, message, }; } toString() { return this.testName ?? "ExpectTest"; } } exports.ExpectTest = ExpectTest;