UNPKG

@sprucelabs/spruce-cli

Version:

Command line interface for building Spruce skills.

79 lines 4.92 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 AbstractSchemaTest_1 = __importDefault(require("../../../tests/AbstractSchemaTest")); const test_utility_1 = __importDefault(require("../../../tests/utilities/test.utility")); class HandlesRelatedSchemasTest extends AbstractSchemaTest_1.default { static async relatedSchemasGeneratesValidFiles() { const { syncResults: results } = await this.installCopyAndSync(); test_utils_1.assert.isUndefined(results.errors); test_utility_1.default.assertFileByNameInGeneratedFiles(/testPerson\.schema/, results.files); test_utility_1.default.assertFileByNameInGeneratedFiles(/pet\.schema/, results.files); test_utility_1.default.assertFileByNameInGeneratedFiles(/nested-schema\.schema/, results.files); await this.assertValidActionResponseFiles(results); } static async nestedSchemasInDynamicFields() { await this.installSchemaFeature('schemas'); const schemasDir = this.resolvePath('src', 'schemas'); await spruce_skill_utils_1.diskUtil.copyDir(this.resolveTestPath('dynamic_key_schemas'), schemasDir); const results = await this.Action('schema', 'sync').execute({}); const typesPath = this.resolveHashSprucePath('schemas', 'schemas.types.ts'); const typesContent = spruce_skill_utils_1.diskUtil.readFile(typesPath); test_utils_1.assert.doesInclude(typesContent, "[fullyQualifiedEventName:string]: { id: 'eventSignature', values: SpruceSchemas.TestingSchemas.v2020_07_22.EventSignature } | { id: 'eventSignature2', values: SpruceSchemas.TestingSchemas.v2020_07_22.EventSignature2 }"); await this.Service('typeChecker').check(typesPath); const schemaMatch = test_utility_1.default.assertFileByNameInGeneratedFiles('mercuryContract.schema.ts', results.files); await this.Service('typeChecker').check(schemaMatch); } static async generatesCoreSchemasFirstSoSchemasCanRelateToThem() { const { syncResults } = await this.installCopyAndSync(); test_utils_1.assert.isFalsy(syncResults.errors); test_utils_1.assert.isTruthy(syncResults.files); test_utility_1.default.assertCountsByAction(syncResults.files, { generated: syncResults.files.length, updated: 0, skipped: 0, }); } static async makesSureMixinSchemaFieldsDontCopySchemaToLocal() { const { syncResults } = await this.installCopyAndSync(); test_utils_1.assert.isFalsy(syncResults.errors); test_utils_1.assert.isTruthy(syncResults.files); const matches = syncResults.files.filter((f) => f.name === 'skillCreator.schema.ts'); test_utils_1.assert.isLength(matches, 1); test_utils_1.assert.doesInclude(matches[0].path, spruce_skill_utils_1.CORE_SCHEMA_VERSION.dirValue); test_utils_1.assert.doesInclude(matches[0].path, spruce_skill_utils_1.CORE_NAMESPACE.toLowerCase()); test_utils_1.assert.doesNotInclude(matches[0].path, 'testing'); } static async installCopyAndSync(testDir = 'related_schemas') { const cli = await this.installSchemaFeature('schemas'); const source = this.resolveTestPath(testDir); const destination = this.resolvePath('src/schemas'); await spruce_skill_utils_1.diskUtil.copyDir(source, destination); const syncResults = await this.Action('schema', 'sync').execute({}); return { cli, syncResults }; } } exports.default = HandlesRelatedSchemasTest; __decorate([ (0, test_utils_1.test)() ], HandlesRelatedSchemasTest, "relatedSchemasGeneratesValidFiles", null); __decorate([ (0, test_utils_1.test)() ], HandlesRelatedSchemasTest, "nestedSchemasInDynamicFields", null); __decorate([ (0, test_utils_1.test)() ], HandlesRelatedSchemasTest, "generatesCoreSchemasFirstSoSchemasCanRelateToThem", null); __decorate([ (0, test_utils_1.test)() ], HandlesRelatedSchemasTest, "makesSureMixinSchemaFieldsDontCopySchemaToLocal", null); //# sourceMappingURL=HandlesRelatedSchemas.test.js.map