UNPKG

@sprucelabs/spruce-cli

Version:

Command line interface for building Spruce skills.

86 lines 4.42 kB
"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 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")); class RegisteringASkillTest extends AbstractCliTest_1.default { static async hasRegisterAction() { test_utils_1.assert.isFunction(this.Action('skill', 'register').execute); } static async cantRegisterWithoutBeingLoggedIn() { await this.FeatureFixture().installCachedFeatures('skills'); const results = await this.Action('skill', 'register').execute({ nameReadable: 'My great skill', nameKebab: 'my-great-skill', }); test_utils_1.assert.isTruthy(results.errors); test_utils_2.errorAssert.assertError(results.errors[0], 'MERCURY_RESPONSE_ERROR'); test_utils_2.errorAssert.assertError(results.errors[0].options.responseErrors[0], 'UNAUTHORIZED_ACCESS'); } static async returnsErrorWhenRegistrationFails() { mercury_client_1.MercuryClientFactory.setIsTestMode(true); await this.eventFaker.fakeRequestPin(); await this.eventFaker.fakeConfirmPin(); await this.people.loginAsDemoPerson(); await this.FeatureFixture().installCachedFeatures('skills'); const slug = `my-new-skill-${new Date().getTime()}`; const client = await this.connectToApi(); await client.on('register-skill::v2020_12_25', (() => { test_utils_1.assert.fail('what the!!??'); })); const results = await this.Action('skill', 'register').execute({ nameReadable: 'My great skill', nameKebab: slug, }); test_utils_1.assert.isTruthy(results.errors); test_utils_1.assert.doesInclude(results.errors[0].message, 'what the!!??'); } static async canRegisterSkill() { await this.FeatureFixture().installCachedFeatures('skills'); await this.people.loginAsDemoPerson(); const slug = `my-new-skill-${new Date().getTime()}`; const results = await this.Action('skill', 'register').execute({ nameReadable: 'my new skill', nameKebab: slug, }); test_utils_1.assert.isFalsy(results.errors); const skill = results.meta?.skill; test_utils_1.assert.isTruthy(skill); const client = await this.connectToApi(); const getSkillResults = await client.emit('get-skill::v2020_12_25', { target: { skillId: skill.id }, }); const { skill: getSkill } = spruce_event_utils_1.eventResponseUtil.getFirstResponseOrThrow(getSkillResults); test_utils_1.assert.isEqual(skill.id, getSkill.id); const auth = this.Service('auth'); const currentSkill = auth.getCurrentSkill(); test_utils_1.assert.isTruthy(currentSkill); test_utils_1.assert.isEqual(currentSkill.name, 'my new skill'); test_utils_1.assert.isEqual(currentSkill.slug, slug); } } exports.default = RegisteringASkillTest; __decorate([ (0, test_utils_1.test)() ], RegisteringASkillTest, "hasRegisterAction", null); __decorate([ (0, test_utils_1.test)() ], RegisteringASkillTest, "cantRegisterWithoutBeingLoggedIn", null); __decorate([ (0, test_utils_1.test)() ], RegisteringASkillTest, "returnsErrorWhenRegistrationFails", null); __decorate([ (0, test_utils_1.test)() ], RegisteringASkillTest, "canRegisterSkill", null); //# sourceMappingURL=RegisteringASkill.test.js.map