@sprucelabs/spruce-cli
Version:
Command line interface for building Spruce skills.
123 lines • 6.02 kB
JavaScript
;
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 spruce_event_utils_1 = require("@sprucelabs/spruce-event-utils");
const test_utils_1 = require("@sprucelabs/test-utils");
const test_utils_2 = require("@sprucelabs/test-utils");
const AbstractCliTest_1 = __importDefault(require("../../../tests/AbstractCliTest"));
const constants_1 = require("../../../tests/constants");
class InstallingASkillAtAnOrgTest extends AbstractCliTest_1.default {
static async beforeEach() {
await super.beforeEach();
await this.login();
await this.getOrganizationFixture().clearAllOrgs();
}
static async hasInstallAction() {
await this.Cli();
test_utils_1.assert.isFunction(this.Action('organization', 'install').execute);
}
static async cantInstallWithoutBeingLoggedIn() {
const org = await this.getOrganizationFixture().seedDemoOrg({
name: 'new org',
});
await this.FeatureFixture().installCachedFeatures('organizations');
await this.getSkillFixture().registerCurrentSkill({
name: 'my amazing skill',
});
await this.people.logout();
await this.Cli();
const anonResults = await this.Action('organization', 'install').execute({
organizationId: org.id,
});
test_utils_1.assert.isTruthy(anonResults.errors);
spruce_event_utils_1.eventAssertUtil.assertError(anonResults.errors[0], 'UNAUTHORIZED_ACCESS');
}
static async cantInstallWithoutAnyOrgs() {
await this.FeatureFixture().installCachedFeatures('organizations');
await this.getSkillFixture().registerCurrentSkill({
name: 'my amazing skill',
});
const anonResults = await this.Action('organization', 'install').execute({});
test_utils_1.assert.isTruthy(anonResults.errors);
test_utils_2.errorAssert.assertError(anonResults.errors[0], 'NO_ORGANIZATIONS_FOUND');
}
static async cantInstallWithoutBeingRegistered() {
await this.FeatureFixture().installCachedFeatures('organizations');
await this.getOrganizationFixture().seedDemoOrg({
name: 'My great org',
});
const anonResults = await this.Action('organization', 'install').execute({});
test_utils_1.assert.isTruthy(anonResults.errors);
test_utils_2.errorAssert.assertError(anonResults.errors[0], 'SKILL_NOT_REGISTERED');
}
static async canInstallSkillAtOrg() {
await this.FeatureFixture().installCachedFeatures('organizations');
const org = await this.getOrganizationFixture().seedDemoOrg({
name: 'My great org',
});
const skill = await this.getSkillFixture().registerCurrentSkill({
name: 'my amazing skill',
});
const promise = this.Action('organization', 'install').execute({});
await this.waitForInput();
test_utils_1.assert.doesInclude(this.ui.getLastInvocation().command, 'confirm', `ui didn't get back a confirm, got back \n\n${test_utils_1.assertUtil.stringify(this.ui.getLastInvocation())}`);
await this.ui.sendInput('');
const results = await promise;
test_utils_1.assert.isFalsy(results.errors);
const isInstalled = await this.Store('organization').isSkillInstalledAtOrg(skill.id, org.id);
test_utils_1.assert.isTruthy(isInstalled);
}
static async asksYouToSelectOrgWithMoreThanOne() {
await this.FeatureFixture().installCachedFeatures('organizations');
await this.getOrganizationFixture().seedDemoOrg({
name: 'My great org',
});
const org2 = await this.getOrganizationFixture().seedDemoOrg({
name: 'My great org',
});
const skill = await this.getSkillFixture().registerCurrentSkill({
name: 'my amazing skill',
});
const promise = this.Action('organization', 'install').execute({});
await this.waitForInput();
test_utils_1.assert.doesInclude(this.ui.getLastInvocation().options, {
type: 'select',
});
await this.ui.sendInput(org2.id);
const results = await promise;
test_utils_1.assert.isFalsy(results.errors);
const isInstalled = await this.Store('organization').isSkillInstalledAtOrg(skill.id, org2.id);
test_utils_1.assert.isTruthy(isInstalled);
}
static async login() {
await this.people.loginAsDemoPerson(constants_1.DEMO_NUMBER_INSTALL_SKILL);
}
}
exports.default = InstallingASkillAtAnOrgTest;
__decorate([
(0, test_utils_1.test)()
], InstallingASkillAtAnOrgTest, "hasInstallAction", null);
__decorate([
(0, test_utils_1.test)()
], InstallingASkillAtAnOrgTest, "cantInstallWithoutBeingLoggedIn", null);
__decorate([
(0, test_utils_1.test)()
], InstallingASkillAtAnOrgTest, "cantInstallWithoutAnyOrgs", null);
__decorate([
(0, test_utils_1.test)()
], InstallingASkillAtAnOrgTest, "cantInstallWithoutBeingRegistered", null);
__decorate([
(0, test_utils_1.test)()
], InstallingASkillAtAnOrgTest, "canInstallSkillAtOrg", null);
__decorate([
(0, test_utils_1.test)()
], InstallingASkillAtAnOrgTest, "asksYouToSelectOrgWithMoreThanOne", null);
//# sourceMappingURL=InstallingASkillAtAnOrg.test.js.map