UNPKG

@sprucelabs/spruce-cli

Version:

Command line interface for building Spruce skills.

91 lines 4.75 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 spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils"); const test_utils_1 = require("@sprucelabs/test-utils"); const dotenv_1 = __importDefault(require("dotenv")); const AbstractSkillTest_1 = __importDefault(require("../../../tests/AbstractSkillTest")); const constants_1 = require("../../../tests/constants"); const test_utility_1 = __importDefault(require("../../../tests/utilities/test.utility")); dotenv_1.default.config(); const stamp = new Date().getTime(); const EVENT_NAME_READABLE = 'did book appointment'; const EVENT_NAME = `test-register-skill-views${stamp}`; const EVENT_CAMEL = `testRegisterSkillViews${stamp}`; class RegisteringGlobalEventsTest extends AbstractSkillTest_1.default { static skillCacheKey = 'events'; static skill; static async beforeAll() { await super.beforeAll(); await this.people.loginAsDemoPerson(constants_1.DEMO_NUMBER_GLOBAL_EVENTS); const orgFixture = this.getOrganizationFixture(); const skillFixture = this.getSkillFixture(); const org = await orgFixture.seedDemoOrg({ name: 'my org' }); this.skill = await skillFixture.registerCurrentSkill({ name: 'heartwood test', }); await orgFixture.installSkillAtOrganization(this.skill.id, org.id); } static async afterAll() { await super.afterAll(); } static async canCreateGlobalEvent() { const results = await this.Action('event', 'create').execute({ isGlobal: true, nameReadable: EVENT_NAME_READABLE, nameKebab: EVENT_NAME, nameCamel: EVENT_CAMEL, }); test_utils_1.assert.isFalsy(results.errors); const optionsFile = test_utility_1.default.assertFileByNameInGeneratedFiles('event.options.ts', results.files); const importedOptions = await this.Service('import').importDefault(optionsFile); test_utils_1.assert.isEqualDeep(importedOptions, { isGlobal: true, }); const version = spruce_skill_utils_1.versionUtil.generateVersion().dirValue; const contractFile = test_utility_1.default.assertFileByNameInGeneratedFiles(`${EVENT_CAMEL}.${version}.contract.ts`, results.files); const importedContract = await this.Service('import').importDefault(contractFile); const sig = importedContract.eventSignatures[`${this.skill.slug}.${EVENT_NAME}::${version}`]; test_utils_1.assert.isTrue(sig.isGlobal); test_utils_1.assert.isTruthy(sig.emitPayloadSchema); } static async registersGloballyOnBoot() { const boot = await this.Action('skill', 'boot').execute({ local: true }); const client = await this.connectToApi({ skillId: this.skill.id, apiKey: this.skill.apiKey, }); const contractResults = await this.Store('event', { apiClientFactory: async () => client, }).fetchEventContracts(); const contracts = contractResults.contracts; boot.meta?.kill(); const version = spruce_skill_utils_1.versionUtil.generateVersion().constValue; const eventName = `${this.skill.slug}.${EVENT_NAME}::${version}`; test_utils_1.assert.isTruthy(contracts[1].eventSignatures[eventName]); } static async canSyncGlobalEvents() { const results = await this.Action('event', 'sync').execute({}); test_utils_1.assert.isFalsy(results.errors); await this.Service('typeChecker').check(this.resolveHashSprucePath('events/events.contract.ts')); } } exports.default = RegisteringGlobalEventsTest; __decorate([ (0, test_utils_1.test)() ], RegisteringGlobalEventsTest, "canCreateGlobalEvent", null); __decorate([ (0, test_utils_1.test)() ], RegisteringGlobalEventsTest, "registersGloballyOnBoot", null); __decorate([ (0, test_utils_1.test)() ], RegisteringGlobalEventsTest, "canSyncGlobalEvents", null); //# sourceMappingURL=RegisteringGlobalEvents.test.js.map