UNPKG

@sprucelabs/spruce-cli

Version:

Command line interface for building Spruce skills.

165 lines • 7.35 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_skill_utils_1 = require("@sprucelabs/spruce-skill-utils"); const test_utils_1 = require("@sprucelabs/test-utils"); const ActionFactory_1 = __importDefault(require("../../../features/ActionFactory")); const SyncAction_1 = __importDefault(require("../../../features/permission/actions/SyncAction")); const test_utility_1 = __importDefault(require("../../../tests/utilities/test.utility")); const AbstractPermissionsTest_1 = __importDefault(require("./support/AbstractPermissionsTest")); const generateShortAlphaId_1 = __importDefault(require("./support/generateShortAlphaId")); const sortPermissionContracts_1 = require("./support/sortPermissionContracts"); class SyncingPermissionsTest extends AbstractPermissionsTest_1.default { static syncAction; static contractId1; static contractId2; static async beforeAll() { await super.beforeAll(); this.contractId1 = (0, generateShortAlphaId_1.default)(); this.contractId2 = (0, generateShortAlphaId_1.default)(); } static async beforeEach() { await super.beforeEach(); this.syncAction = this.Action('permission', 'sync'); mercury_client_1.MercuryClientFactory.setIsTestMode(true); ExecuteTrackingAction.wasExecuteInvoked = false; await this.eventFaker.fakeListPermissionContracts(); } static async generatesExpectedTypesFile() { const results = await this.sync(); const expected = this.resolveHashSprucePath(`permissions/permissions.types.ts`); test_utility_1.default.assertFileByPathInGeneratedFiles(expected, results.files); } static async syncsNewPermissionsWhenMade() { await this.createPermissionContract(this.contractId1); await this.writeTestFileAndAssertValid(`testing-permissions.${this.contractId1}`); } static async upgradingSyncsPermissions() { this.beginTrackingExecute(); await this.emitDidExecuteUpgrade(); test_utils_1.assert.isTrue(ExecuteTrackingAction.wasExecuteInvoked); } static async doesNotSyncIfNotInstalled() { this.beginTrackingExecute(); this.featureInstaller.isInstalled = async (code) => code === 'node'; await this.emitDidExecuteUpgrade(); test_utils_1.assert.isFalse(ExecuteTrackingAction.wasExecuteInvoked); } static async generatesCombinedFile() { test_utils_1.assert.isTrue(spruce_skill_utils_1.diskUtil.doesFileExist(this.getCombinedPath())); } static async combinedFileImportsAllPermissions() { await this.createPermissionContract(this.contractId2); const imported = await this.Service('import').importDefault(this.getCombinedPath()); test_utils_1.assert.isEqualDeep(imported.sort(sortPermissionContracts_1.sortPermissionContracts), [ { id: this.contractId1, name: this.contractId1, description: '', requireAllPermissions: false, permissions: [ { id: 'can-high-five', name: 'Can give high five', description: 'Will this person be allowed to high five?', defaults: { skill: false }, requireAllStatuses: false, }, ], }, { id: this.contractId2, name: this.contractId2, description: '', requireAllPermissions: false, permissions: [ { id: 'can-high-five', name: 'Can give high five', description: 'Will this person be allowed to high five?', defaults: { skill: false }, requireAllStatuses: false, }, ], }, ].sort(sortPermissionContracts_1.sortPermissionContracts)); } static async canSyncCorePermissions() { let wasHit = false; let passedTarget; await this.eventFaker.fakeListPermissionContracts((targetAndPayload) => { passedTarget = targetAndPayload.target; wasHit = true; }); await this.sync({ shouldSyncCorePermissions: true }); test_utils_1.assert.isTrue(wasHit); test_utils_1.assert.isUndefined(passedTarget); } static async syncingEventsSyncsPermissions() { this.beginTrackingExecute(); await this.emitter.emitAndFlattenResponses('feature.did-execute', { actionCode: 'sync', featureCode: 'event', results: {}, }); test_utils_1.assert.isTrue(ExecuteTrackingAction.wasExecuteInvoked); } static getCombinedPath() { return this.resolveHashSprucePath('permissions', 'permissions.ts'); } static beginTrackingExecute() { ActionFactory_1.default.setActionClass('permission', 'sync', ExecuteTrackingAction); } static async sync(options) { return await this.syncAction.execute(options); } static async emitDidExecuteUpgrade() { await this.emitter.emitAndFlattenResponses('feature.did-execute', { actionCode: 'upgrade', featureCode: 'node', results: {}, }); } } exports.default = SyncingPermissionsTest; __decorate([ (0, test_utils_1.test)() ], SyncingPermissionsTest, "generatesExpectedTypesFile", null); __decorate([ (0, test_utils_1.test)() ], SyncingPermissionsTest, "syncsNewPermissionsWhenMade", null); __decorate([ (0, test_utils_1.test)() ], SyncingPermissionsTest, "upgradingSyncsPermissions", null); __decorate([ (0, test_utils_1.test)() ], SyncingPermissionsTest, "doesNotSyncIfNotInstalled", null); __decorate([ (0, test_utils_1.test)() ], SyncingPermissionsTest, "generatesCombinedFile", null); __decorate([ (0, test_utils_1.test)() ], SyncingPermissionsTest, "combinedFileImportsAllPermissions", null); __decorate([ (0, test_utils_1.test)() ], SyncingPermissionsTest, "canSyncCorePermissions", null); __decorate([ (0, test_utils_1.test)() ], SyncingPermissionsTest, "syncingEventsSyncsPermissions", null); class ExecuteTrackingAction extends SyncAction_1.default { static wasExecuteInvoked = false; async execute() { ExecuteTrackingAction.wasExecuteInvoked = true; return {}; } } //# sourceMappingURL=SyncingPermissions.test.js.map