UNPKG

@sprucelabs/spruce-cli

Version:

Command line interface for building Spruce skills.

105 lines 5.17 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 AbstractSkillTest_1 = __importDefault(require("../../../tests/AbstractSkillTest")); const test_utility_1 = __importDefault(require("../../../tests/utilities/test.utility")); class EventsWithFeedTemplatesTest extends AbstractSkillTest_1.default { static skillCacheKey = 'events'; static eventOptionsFile; static skill; static async feedIsPassedToRegistration() { this.skill = await this.registerSkill(); await this.createEvent(); const feedTemplate = { template: (0, test_utils_1.generateId)(), }; this.dropIntoEventOptions(`feed: ${JSON.stringify(feedTemplate)},`); const signature = await this.syncAndFetchSignature(); test_utils_1.assert.isEqualDeep(signature.feed, feedTemplate, 'Feed template should match.'); } static async canHandleBackticksInAiInstructions() { const aiInstructions = 'Here `there` be dragons'; this.dropIntoEventOptions(`aiInstructions: '${aiInstructions}',`); const signature = await this.syncAndFetchSignature(); test_utils_1.assert.isEqual(signature.aiInstructions, aiInstructions, 'AI instructions should match.'); } static async canHandleBackticksInDescription() { const description = 'This event `describes` something'; this.dropIntoEventOptions(`description: '${description}',`); const signature = await this.syncAndFetchSignature(); test_utils_1.assert.isEqual(signature.description, description, 'Description should match.'); } static async syncAndFetchSignature() { await this.syncEvents(); await this.lintBuildAndBoot(); const signature = await this.fetchCreatedEventSignature(); return signature; } static dropIntoEventOptions(dropIn) { const contents = spruce_skill_utils_1.diskUtil.readFile(this.eventOptionsFile); const updated = contents.replace('isGlobal: false,', `isGlobal: false, ${dropIn}`); spruce_skill_utils_1.diskUtil.writeFile(this.eventOptionsFile, updated); return updated; } static async fetchCreatedEventSignature() { const client = await this.connectToApi({ shouldAuthAsCurrentSkill: true, }); const [{ contracts }] = await client.emitAndFlattenResponses('get-event-contracts::v2020_12_25', { target: { namespaces: [this.skill.slug], }, }); const first = contracts[0]; const { eventSignatures } = first; const fqen = Object.keys(eventSignatures)[0]; const signature = eventSignatures[fqen]; return signature; } static async lintBuildAndBoot() { await this.Service('command').execute('yarn fix.lint'); await this.Service('command').execute('yarn build.dev'); const boot = await this.Action('skill', 'boot').execute({}); test_utils_1.assert.isFalsy(boot.errors, 'Should not have boot errors.'); boot.meta?.kill(); } static async createEvent() { const results = await this.Action('event', 'create').execute({ nameReadable: 'a new event', nameKebab: 'my-new-event', nameCamel: 'myNewEvent', }); test_utils_1.assert.isFalsy(results.errors, 'Should not have errors.'); this.eventOptionsFile = test_utility_1.default.assertFileByNameInGeneratedFiles('event.options.ts', results.files); } static async registerSkill() { return await this.getSkillFixture().registerCurrentSkill({ name: 'current skill', }); } static async syncEvents() { const syncResults = await this.Action('event', 'sync').execute({}); test_utils_1.assert.isFalsy(syncResults.errors, 'Should not have sync errors.'); } } exports.default = EventsWithFeedTemplatesTest; __decorate([ (0, test_utils_1.test)() ], EventsWithFeedTemplatesTest, "feedIsPassedToRegistration", null); __decorate([ (0, test_utils_1.test)() ], EventsWithFeedTemplatesTest, "canHandleBackticksInAiInstructions", null); __decorate([ (0, test_utils_1.test)() ], EventsWithFeedTemplatesTest, "canHandleBackticksInDescription", null); //# sourceMappingURL=DifferentEventOptions.test.js.map