UNPKG

corde

Version:

A simple library for Discord bot tests

85 lines (62 loc) 2.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true, }); exports.ToDeleteRole = void 0; const roleUtils_1 = require("../../roleUtils"); const expectTest_1 = require("../expectTest"); class ToDeleteRole extends expectTest_1.ExpectTest { constructor(params) { super({ ...params, testName: "toDeleteRole" }); } async action(roleIdentifier) { const identifier = roleUtils_1.roleUtils.getRoleData(roleIdentifier); const roleOrFailObject = await this.getRoleOrInvalidMessage(identifier); if (roleOrFailObject.message) { return roleOrFailObject; } const role = roleOrFailObject; try { await this.sendCommandMessage(); } catch (error) { return this.createFailedTest(error.message); } try { await this.cordeBot.events.onceRoleDelete(identifier, this.timeout, this.guildId); } catch { if (this.isNot) { return this.createPassTest(); } return this.createReport( `timeout: role ${role.id} wasn't deleted in the expected time (${this.timeout})`, ); } const deletedRole = await this.cordeBot.fetchRole(role.id); if (!deletedRole || deletedRole.deleted) { this.hasPassed = true; } this.invertHasPassedIfIsNot(); if (this.hasPassed) { return this.createPassTest(); } return this.createReport(`expected: role ${role.id} to ${this.isNot ? "not " : ""}be deleted`); } async getRoleOrInvalidMessage(roleIdentifier) { const error = roleUtils_1.roleUtils.getErrorForUndefinedRoleData(roleIdentifier); if (error) { return this.createFailedTest(error); } const role = await this.cordeBot.findRole(roleIdentifier); if (!role) { return this.createFailedTest(roleUtils_1.roleUtils.validateRole(role, roleIdentifier)); } if (role.deleted) { return this.createFailedTest( `expected: role ${role.id} not deleted\n`, `received: role was deleted before call the command '${this.command}'`, ); } return role; } } exports.ToDeleteRole = ToDeleteRole;