@sprucelabs/spruce-cli
Version:
Command line interface for building Spruce skills.
120 lines • 5.6 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 test_utils_1 = require("@sprucelabs/test-utils");
const test_utils_2 = require("@sprucelabs/test-utils");
const AbstractSkillTest_1 = __importDefault(require("../../../tests/AbstractSkillTest"));
const constants_1 = require("../../../tests/constants");
class LoggingInAsASkillTest extends AbstractSkillTest_1.default {
static skillCacheKey = 'skills';
static skill1;
static skill2;
static skill3;
static async beforeAll() {
await super.beforeAll();
this.Service('auth').logOutPerson();
await this.people.loginAsDemoPerson(constants_1.DEMO_NUMBER_LOGIN_AS_SKILL);
const skillFixture = this.getSkillFixture();
await skillFixture.clearAllSkills();
await this.people.logout();
}
static async hasLoginAction() {
test_utils_1.assert.isFunction(this.Action('skill', 'login').execute);
}
static async asksToLoginIfNotLoggedIn() {
void this.Action('skill', 'login').execute({});
await this.waitForInput();
test_utils_1.assert.doesInclude(this.ui.getLastInvocation().options.label, 'Phone');
this.ui.reset();
}
static async returnsErrorIfNoSkillHasEverBeenRegistered() {
await this.login();
const results = await this.Action('skill', 'login').execute({});
test_utils_1.assert.isTruthy(results.errors);
test_utils_1.assert.isLength(results.errors, 1);
test_utils_2.errorAssert.assertError(results.errors[0], 'NO_SKILLS_REGISTERED');
}
static async login() {
const person = await this.people.loginAsDemoPerson(constants_1.DEMO_NUMBER_LOGIN_AS_SKILL);
this.Service('auth').setLoggedInPerson(person);
}
static async logsInAsOnlySkillIfOnly1Registered() {
await this.login();
this.skill1 = await this.getSkillFixture().seedDemoSkill({
name: `login skill ${new Date().getTime()}`,
});
const results = await this.Action('skill', 'login').execute({});
test_utils_1.assert.isFalsy(results.errors);
const loggedIn = this.Service('auth').getCurrentSkill();
test_utils_1.assert.isEqual(loggedIn?.id, this.skill1.id);
}
static async letsYouSelectSkillIfMoreThan1IsRegistered() {
await this.login();
this.skill2 = await this.getSkillFixture().seedDemoSkill({
name: `login skill 2 ${new Date().getTime()}`,
});
const promise = this.Action('skill', 'login').execute({});
await this.waitForInput();
test_utils_1.assert.doesInclude(this.ui.getLastInvocation().command, 'prompt');
test_utils_1.assert.doesInclude(this.ui.getLastInvocation().options.type, 'select');
test_utils_1.assert.isEqualDeep(this.ui.getLastInvocation().options.options.choices, [this.skill1, this.skill2].map((s) => ({
label: s.name,
value: s.id,
})));
await this.ui.sendInput(this.skill2.id);
await promise;
const loggedIn = this.Service('auth').getCurrentSkill();
test_utils_1.assert.isEqual(loggedIn?.id, this.skill2.id);
}
static async cantLoginWithSlugYouDontOwn() {
await this.login();
const results = await this.Action('skill', 'login').execute({
skillSlug: 'never found',
});
test_utils_1.assert.isTruthy(results.errors);
test_utils_2.errorAssert.assertError(results.errors[0], 'SKILL_NOT_FOUND');
}
static async canLoginWithSlugYouOwn() {
await this.login();
this.skill3 = await this.getSkillFixture().seedDemoSkill({
name: `login skill 3 ${new Date().getTime()}`,
});
const results = await this.Action('skill', 'login').execute({
skillSlug: this.skill3.slug,
});
test_utils_1.assert.isFalsy(results.errors);
const loggedIn = this.Service('auth').getCurrentSkill();
test_utils_1.assert.isEqual(loggedIn?.id, this.skill3.id);
}
}
exports.default = LoggingInAsASkillTest;
__decorate([
(0, test_utils_1.test)()
], LoggingInAsASkillTest, "hasLoginAction", null);
__decorate([
(0, test_utils_1.test)()
], LoggingInAsASkillTest, "asksToLoginIfNotLoggedIn", null);
__decorate([
(0, test_utils_1.test)()
], LoggingInAsASkillTest, "returnsErrorIfNoSkillHasEverBeenRegistered", null);
__decorate([
(0, test_utils_1.test)()
], LoggingInAsASkillTest, "logsInAsOnlySkillIfOnly1Registered", null);
__decorate([
(0, test_utils_1.test)()
], LoggingInAsASkillTest, "letsYouSelectSkillIfMoreThan1IsRegistered", null);
__decorate([
(0, test_utils_1.test)()
], LoggingInAsASkillTest, "cantLoginWithSlugYouDontOwn", null);
__decorate([
(0, test_utils_1.test)()
], LoggingInAsASkillTest, "canLoginWithSlugYouOwn", null);
//# sourceMappingURL=LoggingInAsASkill.test.js.map