@sprucelabs/spruce-cli
Version:
Command line interface for building Spruce skills.
143 lines • 5.72 kB
JavaScript
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const mercury_client_1 = require("@sprucelabs/mercury-client");
const test_utils_1 = require("@sprucelabs/test-utils");
const AbstractCliTest_1 = __importDefault(require("../../../tests/AbstractCliTest"));
class UnregisteringASkillTest extends AbstractCliTest_1.default {
static action;
static lastListSkillsPayload;
static fakedSkills = [];
static executePromise;
static lastUnregisterSkillTarget;
static async beforeEach() {
await super.beforeEach();
mercury_client_1.MercuryClientFactory.setIsTestMode(true);
mercury_client_1.MercuryTestClient.setShouldRequireLocalListeners(true);
this.action = this.Action('global', 'unregisterSkill');
delete this.lastListSkillsPayload;
delete this.lastUnregisterSkillTarget;
this.fakedSkills = [];
await this.eventFaker.fakeListSkills(({ payload }) => {
this.lastListSkillsPayload = payload;
return this.fakedSkills;
});
await this.eventFaker.fakeUnregisterSkill(({ target }) => {
this.lastUnregisterSkillTarget = target;
});
}
static async hasAction() {
test_utils_1.assert.isFunction(this.action.execute, 'Action not found');
}
static async firstThingListsSkills() {
await this.execute();
await this.waitUntilFinished();
test_utils_1.assert.isEqualDeep(this.lastListSkillsPayload, {
shouldOnlyShowMine: true,
});
}
static async presentsAnOptionForOnlySkillReturned() {
this.pushFakedSkill();
await this.executeAndWaitForInput();
this.assertProptsForAllSkills();
await this.selectSkill(0);
await this.pressEnter();
}
static async presentsOptionsForMultipleSkills() {
this.pushFakedSkill();
this.pushFakedSkill();
this.pushFakedSkill();
await this.executeAndWaitForInput();
this.assertProptsForAllSkills();
await this.selectSkill(1);
await this.pressEnter();
}
static async passesSelectedSkillToUnregister(idx) {
this.pushFakedSkill();
this.pushFakedSkill();
await this.executeAndWaitForInput();
await this.selectSkill(idx);
await this.pressEnter();
await this.waitUntilFinished();
test_utils_1.assert.isEqualDeep(this.lastUnregisterSkillTarget, {
skillId: this.fakedSkills[idx].id,
}, 'Skill ID not passed to unregister skill');
}
static async doesNotUnRegisterIfNotConfirmed() {
this.pushFakedSkill();
await this.executeAndWaitForInput();
await this.selectSkill(0);
await this.ui.sendInput('n');
await this.waitUntilFinished();
test_utils_1.assert.isFalsy(this.lastUnregisterSkillTarget, 'Unregister skill was called unexpectedly');
}
static async executeAndWaitForInput() {
await this.execute();
await this.waitForInput();
}
static async selectSkill(idx) {
await this.ui.sendInput(this.fakedSkills[idx].id);
}
static assertProptsForAllSkills() {
const prompt = this.ui.getLastInvocation();
test_utils_1.assert.isEqualDeep(prompt.options, {
type: 'select',
isRequired: true,
options: {
choices: this.generateExpectedSkillChoices(),
},
});
}
static async pressEnter() {
await this.ui.sendInput('\n');
}
static generateExpectedSkillChoices() {
return this.fakedSkills.map((skill) => ({
value: skill.id,
label: `${skill.slug}: ${skill.name}`,
}));
}
static pushFakedSkill() {
this.fakedSkills.push({
id: (0, test_utils_1.generateId)(),
dateCreated: Date.now(),
slug: (0, test_utils_1.generateId)(),
name: (0, test_utils_1.generateId)(),
});
}
static async waitUntilFinished() {
await this.executePromise;
}
static async execute() {
this.executePromise = this.action.execute();
}
}
exports.default = UnregisteringASkillTest;
__decorate([
(0, test_utils_1.test)()
], UnregisteringASkillTest, "hasAction", null);
__decorate([
(0, test_utils_1.test)()
], UnregisteringASkillTest, "firstThingListsSkills", null);
__decorate([
(0, test_utils_1.test)()
], UnregisteringASkillTest, "presentsAnOptionForOnlySkillReturned", null);
__decorate([
(0, test_utils_1.test)()
], UnregisteringASkillTest, "presentsOptionsForMultipleSkills", null);
__decorate([
(0, test_utils_1.test)('can unregister first skill', 0),
(0, test_utils_1.test)('can unregister second skill', 1)
], UnregisteringASkillTest, "passesSelectedSkillToUnregister", null);
__decorate([
(0, test_utils_1.test)()
], UnregisteringASkillTest, "doesNotUnRegisterIfNotConfirmed", null);
//# sourceMappingURL=UnregisteringASkill.test.js.map