@sprucelabs/spruce-cli
Version:
Command line interface for building Spruce skills.
170 lines • 7.91 kB
JavaScript
;
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");
require("@sprucelabs/spruce-store-plugin");
const CommandService_1 = __importDefault(require("../../../services/CommandService"));
const AbstractSkillTest_1 = __importDefault(require("../../../tests/AbstractSkillTest"));
const test_utility_1 = __importDefault(require("../../../tests/utilities/test.utility"));
class CreatingDataStoresTest extends AbstractSkillTest_1.default {
static skillCacheKey = 'stores';
static async hasCreateStoreAction() {
test_utils_1.assert.isFunction(this.Action('store', 'create').execute);
}
static async getsNoStoresBackFromHealthCheck() {
const health = await this.cli.checkHealth({
shouldRunOnSourceFiles: true,
});
test_utils_1.assert.isFalsy(health.skill.errors);
//@ts-ignore
test_utils_1.assert.isTruthy(health.store);
//@ts-ignore
test_utils_1.assert.isFalsy(health.store.errors);
//@ts-ignore
test_utils_1.assert.isArray(health.store.stores);
//@ts-ignore
test_utils_1.assert.isLength(health.store.stores, 0);
}
static async generatesValidStoreFile() {
const results = await this.Action('store', 'create').execute({
nameReadable: 'Person',
nameReadablePlural: 'People',
namePascal: 'Person',
});
test_utils_1.assert.isFalsy(results.errors);
const path = test_utility_1.default.assertFileByNameInGeneratedFiles('People.store.ts', results.files);
await this.Service('typeChecker').check(path);
}
static async generatesAMapFile() {
const file = this.resolveHashSprucePath('stores', 'stores.ts');
test_utils_1.assert.isTrue(spruce_skill_utils_1.diskUtil.doesFileExist(file));
await this.Service('typeChecker').check(file);
}
static async getsOneStoresBackFromHealthCheck() {
const health = await this.cli.checkHealth({
shouldRunOnSourceFiles: true,
});
//@ts-ignore
test_utils_1.assert.isTruthy(health.store);
//@ts-ignore
test_utils_1.assert.isFalsy(health.store.errors);
//@ts-ignore
test_utils_1.assert.isLength(health.store.stores, 1);
//@ts-ignore
test_utils_1.assert.isEqual(health.store.stores[0].name, 'People');
}
static async canGenerateASecondStoreFile() {
const results = await this.Action('store', 'create').execute({
nameReadable: 'Bid',
nameReadablePlural: 'Bids',
namePascal: 'Bid',
});
test_utils_1.assert.isFalsy(results.errors);
const path = test_utility_1.default.assertFileByNameInGeneratedFiles('Bids.store.ts', results.files);
await this.Service('typeChecker').check(path);
}
static async getsSecondStoresBackFromHealthCheck() {
const health = await this.cli.checkHealth({
shouldRunOnSourceFiles: true,
});
//@ts-ignore
test_utils_1.assert.isTruthy(health.store);
//@ts-ignore
test_utils_1.assert.isFalsy(health.store.errors);
//@ts-ignore
test_utils_1.assert.isLength(health.store.stores, 2);
//@ts-ignore
test_utils_1.assert.isEqual(health.store.stores[0].name, 'Bids');
//@ts-ignore
test_utils_1.assert.isEqual(health.store.stores[1].name, 'People');
}
static async errorsWhenGeneratingAStoreWithTheSameName() {
const results = await this.Action('store', 'create').execute({
nameReadable: 'Bid',
nameReadablePlural: 'Bids',
namePascal: 'Bid',
});
test_utils_1.assert.isTruthy(results.errors);
test_utils_2.errorAssert.assertError(results.errors[0], 'STORE_EXISTS');
}
static async storeFactoryAndStoresAreTyped() {
const results = await this.Action('store', 'create').execute({
nameReadable: 'Product',
nameReadablePlural: 'Products',
namePascal: 'Product',
});
const path = test_utility_1.default.assertFileByNameInGeneratedFiles('Products.store.ts', results.files);
const storeContents = spruce_skill_utils_1.diskUtil
.readFile(path)
.replace('type ProductsStoreOptions = UniversalStoreOptions', 'type ProductsStoreOptions = UniversalStoreOptions & {hello: string}');
spruce_skill_utils_1.diskUtil.writeFile(path, storeContents);
const testFile = this.resolveTestPath('store-test.ts.hbs');
const testContents = spruce_skill_utils_1.diskUtil.readFile(testFile);
const dest = this.resolvePath('src', 'test.ts');
spruce_skill_utils_1.diskUtil.writeFile(dest, testContents);
await this.Service('typeChecker').check(dest);
}
static async doesNotCreateAbstractTestFileBecauseTestIsNotInstalled() {
test_utils_1.assert.isFalse(spruce_skill_utils_1.diskUtil.doesFileExist(CreatingDataStoresTest.getAbstractTestPath()));
}
static async upgradeRestoresDataStoreTypes() {
CommandService_1.default.fakeCommand('yarn rebuild', {
code: 0,
});
CommandService_1.default.fakeCommand(/yarn add/gis, {
code: 0,
});
const storesFile = this.resolveHashSprucePath('stores/stores.types.ts');
spruce_skill_utils_1.diskUtil.deleteFile(storesFile);
await this.Action('node', 'upgrade').execute({});
test_utils_1.assert.isTrue(spruce_skill_utils_1.diskUtil.doesFileExist(storesFile));
}
static getAbstractTestPath() {
return this.resolvePath('src', 'tests', 'AbstractDataStoreTest.ts');
}
}
exports.default = CreatingDataStoresTest;
__decorate([
(0, test_utils_1.test)()
], CreatingDataStoresTest, "hasCreateStoreAction", null);
__decorate([
(0, test_utils_1.test)()
], CreatingDataStoresTest, "getsNoStoresBackFromHealthCheck", null);
__decorate([
(0, test_utils_1.test)()
], CreatingDataStoresTest, "generatesValidStoreFile", null);
__decorate([
(0, test_utils_1.test)()
], CreatingDataStoresTest, "generatesAMapFile", null);
__decorate([
(0, test_utils_1.test)()
], CreatingDataStoresTest, "getsOneStoresBackFromHealthCheck", null);
__decorate([
(0, test_utils_1.test)()
], CreatingDataStoresTest, "canGenerateASecondStoreFile", null);
__decorate([
(0, test_utils_1.test)()
], CreatingDataStoresTest, "getsSecondStoresBackFromHealthCheck", null);
__decorate([
(0, test_utils_1.test)()
], CreatingDataStoresTest, "errorsWhenGeneratingAStoreWithTheSameName", null);
__decorate([
(0, test_utils_1.test)()
], CreatingDataStoresTest, "storeFactoryAndStoresAreTyped", null);
__decorate([
(0, test_utils_1.test)()
], CreatingDataStoresTest, "doesNotCreateAbstractTestFileBecauseTestIsNotInstalled", null);
__decorate([
(0, test_utils_1.test)()
], CreatingDataStoresTest, "upgradeRestoresDataStoreTypes", null);
//# sourceMappingURL=CreatingADataStore.test.js.map