UNPKG

@sprucelabs/spruce-cli

Version:

Command line interface for building Spruce skills.

116 lines 5.21 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 test_utils_2 = require("@sprucelabs/test-utils"); const AbstractSkillTest_1 = __importDefault(require("../../tests/AbstractSkillTest")); const test_utility_1 = __importDefault(require("../../tests/utilities/test.utility")); class DataStoreStoreTest extends AbstractSkillTest_1.default { static store; static badStoreDest; static skillCacheKey = 'stores'; static async beforeAll() { await super.beforeAll(); this.badStoreDest = this.resolvePath('src/stores/Bad.store.ts'); } static async beforeEach() { await super.beforeEach(); spruce_skill_utils_1.diskUtil.deleteFile(this.badStoreDest); this.store = this.Store('store'); } static async canInstantiateDataStore() { test_utils_1.assert.isTruthy(this.Store('store')); } static async hasFetchStores() { test_utils_1.assert.isTruthy(this.Store('store').fetchStores); } static async fetchesNoStoresToStart() { this.cwd = this.freshTmpDir(); const results = await this.store.fetchStores(); test_utils_1.assert.isLength(results, 0); } static async throwsWhenStoreIsNotValid() { spruce_skill_utils_1.diskUtil.writeFile(this.badStoreDest, 'throw new Error("Cheese!")'); const err = await test_utils_1.assert.doesThrowAsync(() => this.store.fetchStores()); test_utils_2.errorAssert.assertError(err, 'FAILED_TO_IMPORT', { file: 'Bad.store.ts', }); } static async canImportAGoodStore() { const results = await this.Action('store', 'create').execute({ nameReadable: 'Good', nameReadablePlural: 'Good', namePascal: 'Good', }); test_utils_1.assert.isFalsy(results.errors); const storeFilepath = test_utility_1.default.assertFileByNameInGeneratedFiles('Good.store.ts', results.files); const stores = await this.store.fetchStores(); test_utils_1.assert.isLength(stores, 1); test_utils_1.assert.doesInclude(stores, { className: 'GoodStore', path: storeFilepath, }); } static async canImportTwoGoodStores() { const results = await this.Action('store', 'create').execute({ nameReadable: 'Apple', nameReadablePlural: 'Apples', namePascal: 'Apple', }); test_utils_1.assert.isFalsy(results.errors); const storeFilepath = test_utility_1.default.assertFileByNameInGeneratedFiles('Apples.store.ts', results.files); const stores = await this.store.fetchStores(); test_utils_1.assert.isLength(stores, 2); test_utils_1.assert.doesInclude(stores, { className: 'ApplesStore', path: storeFilepath, }); } static async accuratelyReportsBadStoreAfterGoodStoresAreCreated() { spruce_skill_utils_1.diskUtil.writeFile(this.badStoreDest, 'throw new Error("Cheese!")'); const err = await test_utils_1.assert.doesThrowAsync(() => this.store.fetchStores()); test_utils_2.errorAssert.assertError(err, 'FAILED_TO_IMPORT', { file: 'Bad.store.ts', }); } static async globbyPatternLooksEverywhere() { const expected = this.resolvePath('src', '**', '*.store.ts'); //@ts-ignore test_utils_1.assert.isEqual(this.store.generateGlobbyPattern(), expected); } } exports.default = DataStoreStoreTest; __decorate([ (0, test_utils_1.test)() ], DataStoreStoreTest, "canInstantiateDataStore", null); __decorate([ (0, test_utils_1.test)() ], DataStoreStoreTest, "hasFetchStores", null); __decorate([ (0, test_utils_1.test)() ], DataStoreStoreTest, "fetchesNoStoresToStart", null); __decorate([ (0, test_utils_1.test)() ], DataStoreStoreTest, "throwsWhenStoreIsNotValid", null); __decorate([ (0, test_utils_1.test)() ], DataStoreStoreTest, "canImportAGoodStore", null); __decorate([ (0, test_utils_1.test)() ], DataStoreStoreTest, "canImportTwoGoodStores", null); __decorate([ (0, test_utils_1.test)() ], DataStoreStoreTest, "accuratelyReportsBadStoreAfterGoodStoresAreCreated", null); __decorate([ (0, test_utils_1.test)() ], DataStoreStoreTest, "globbyPatternLooksEverywhere", null); //# sourceMappingURL=DataStoreStore.test.js.map