UNPKG

@sprucelabs/spruce-cli

Version:

Command line interface for building Spruce skills.

123 lines • 5.34 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 test_utils_1 = require("@sprucelabs/test-utils"); const test_utils_2 = require("@sprucelabs/test-utils"); const AbstractCliTest_1 = __importDefault(require("../../../tests/AbstractCliTest")); const PersonFixture_1 = require("../../../tests/fixtures/PersonFixture"); class LoggingInAsPersonTest extends AbstractCliTest_1.default { static async hasLoginAction() { await this.Cli(); test_utils_1.assert.isFunction(this.Action('person', 'login').execute); } static async asksForPinWithoutBeingInstalled() { await this.FeatureFixture().installCachedFeatures('skills'); void this.Action('person', 'login').execute({ phone: PersonFixture_1.DEMO_NUMBER, }); await this.waitForInput(); test_utils_1.assert.doesInclude(this.ui.invocations, { command: 'prompt', options: { type: 'text', }, }); this.ui.reset(); } static async badPinRendersWarningAndAsksForPinAgain() { await this.FeatureFixture().installCachedFeatures('skills'); void this.Action('person', 'login').execute({ phone: PersonFixture_1.DEMO_NUMBER, }); await this.waitForInput(); await this.ui.sendInput('0000'); await this.waitForInput(); test_utils_1.assert.doesInclude(this.ui.invocations, { command: 'renderWarning', }); await this.waitForInput(); test_utils_1.assert.doesInclude(this.ui.invocations, { command: 'prompt', options: { type: 'text', }, }); this.ui.reset(); } static async canLoginAsDemoPerson() { await this.installSkillAndLoginAsDemoPerson(); const person = this.Service('auth').getLoggedInPerson(); test_utils_1.assert.isTruthy(person); test_utils_1.assert.isString(person.id); test_utils_1.assert.isString(person.token); test_utils_1.assert.isTrue(person.isLoggedIn); } static async cantLogoutWithoutBeingLoggedIn() { await this.FeatureFixture().installCachedFeatures('skills'); const results = await this.Action('person', 'logout').execute({}); test_utils_1.assert.isTruthy(results.errors); test_utils_1.assert.isLength(results.errors, 1); test_utils_2.errorAssert.assertError(results.errors[0], 'NOT_LOGGED_IN'); } static async canLogOut() { await this.installSkillAndLoginAsDemoPerson(); const results = await this.Action('person', 'logout').execute({}); test_utils_1.assert.isFalsy(results.errors); const person = this.Service('auth').getLoggedInPerson(); test_utils_1.assert.isNull(person); } static async canLogInWithExpiredPinWithouHavingToLogOutFirst() { await this.FeatureFixture().installCachedFeatures('skills'); this.Service('auth').setLoggedInPerson({ token: '234', id: 'test', casualName: 'casual test', }); await this.loginAsPerson(); } static async installSkillAndLoginAsDemoPerson() { const cli = await this.FeatureFixture().installCachedFeatures('skills'); await this.loginAsPerson(); return cli; } static async loginAsPerson() { const promise = this.Action('person', 'login').execute({ phone: PersonFixture_1.DEMO_NUMBER, }); await this.waitForInput(); await this.ui.sendInput(PersonFixture_1.DEMO_NUMBER.substr(-4)); const results = await promise; test_utils_1.assert.isFalsy(results.errors); } } exports.default = LoggingInAsPersonTest; __decorate([ (0, test_utils_1.test)() ], LoggingInAsPersonTest, "hasLoginAction", null); __decorate([ (0, test_utils_1.test)() ], LoggingInAsPersonTest, "asksForPinWithoutBeingInstalled", null); __decorate([ test_utils_1.test.skip('enable when there are demo numbers that throw with bad pin') ], LoggingInAsPersonTest, "badPinRendersWarningAndAsksForPinAgain", null); __decorate([ (0, test_utils_1.test)() ], LoggingInAsPersonTest, "canLoginAsDemoPerson", null); __decorate([ (0, test_utils_1.test)() ], LoggingInAsPersonTest, "cantLogoutWithoutBeingLoggedIn", null); __decorate([ (0, test_utils_1.test)() ], LoggingInAsPersonTest, "canLogOut", null); __decorate([ (0, test_utils_1.test)() ], LoggingInAsPersonTest, "canLogInWithExpiredPinWithouHavingToLogOutFirst", null); //# sourceMappingURL=LoggingInAsPerson.test.js.map