UNPKG

@sprucelabs/spruce-cli

Version:

Command line interface for building Spruce skills.

68 lines 2.69 kB
"use strict"; 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 apiClient_utility_1 = __importDefault(require("../../utilities/apiClient.utility")); class SkillFixture { storeFactory; apiClientFactory; personFixture; static skillCount = Math.round(Math.random() * 100); constructor(personFixture, storeFactory, apiClientFactory) { this.personFixture = personFixture; this.storeFactory = storeFactory; this.apiClientFactory = apiClientFactory; } async seedDemoSkill(values, options) { return this.registerCurrentSkill(values, { isRegisteringCurrentSkill: false, ...options, }); } async registerCurrentSkill(values, options) { await this.personFixture.loginAsDemoPerson(options?.phone); return this.storeFactory.Store('skill').register({ slug: values.slug ?? this.generateSkillSlug(values.name), ...values, }, options); } generateSkillSlug(name) { SkillFixture.skillCount++; return `${spruce_skill_utils_1.namesUtil.toKebab(name)}-${new Date().getTime()}-count-${SkillFixture.skillCount}-cli-test`; } async registerEventContract(auth, contract) { const skillAuth = apiClient_utility_1.default.skillOrAuthToAuth(auth); const client = await this.apiClientFactory(skillAuth); const eventStore = this.storeFactory.Store('event', { apiClientFactory: async () => { return client; }, }); await eventStore.registerEventContract({ eventContract: contract, }); } async unRegisterEvents(auth, options) { const skillAuth = apiClient_utility_1.default.skillOrAuthToAuth(auth); const client = await this.apiClientFactory(skillAuth); const eventStore = this.storeFactory.Store('event', { apiClientFactory: async () => { return client; }, }); await eventStore.unRegisterEvents(options); } async clearAllSkills() { await this.personFixture.loginAsDemoPerson(); const skillStore = this.storeFactory.Store('skill'); const skills = await skillStore.fetchMySkills(); for (const skill of skills) { await skillStore.unregisterSkill(skill.id); } return skills.length; } } exports.default = SkillFixture; //# sourceMappingURL=SkillFixture.js.map