@sprucelabs/spruce-cli
Version:
Command line interface for building Spruce skills.
95 lines • 4.23 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");
const AbstractSkillTest_1 = __importDefault(require("../../../tests/AbstractSkillTest"));
const test_utility_1 = __importDefault(require("../../../tests/utilities/test.utility"));
class KeepingDataStoresInSyncTest extends AbstractSkillTest_1.default {
static skillCacheKey = 'stores';
static badStoreDest;
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);
}
static async hasSyncAction() {
test_utils_1.assert.isFunction(this.Action('store', 'sync').execute);
}
static async syncsNothingToStart() {
const results = await this.syncStores();
test_utils_1.assert.isLength(results.files, 0);
}
static async badFileReturnsError() {
spruce_skill_utils_1.diskUtil.writeFile(this.badStoreDest, 'throw new Error("Cheese!")');
const results = await this.syncStores();
test_utils_1.assert.isArray(results.errors);
test_utils_1.assert.isLength(results.errors, 1);
test_utils_2.errorAssert.assertError(results.errors[0], 'FAILED_TO_IMPORT', {
file: 'Bad.store.ts',
});
}
static async generatesValidTypeFile() {
const results = await this.Action('store', 'create').execute({
nameReadable: 'Bid',
nameReadablePlural: 'Bids',
namePascal: 'Bid',
});
await this.validateFiles(results);
}
static async fileIsValidAfterSync() {
const results = await this.syncStores();
await this.validateFiles(results);
}
static async canAddSecondStore() {
const results = await this.Action('store', 'create').execute({
nameReadable: 'Person',
nameReadablePlural: 'People',
namePascal: 'Person',
});
await this.validateFiles(results);
}
static async validateFiles(results) {
const typesFile = test_utility_1.default.assertFileByNameInGeneratedFiles('stores.types.ts', results.files);
const mapFile = test_utility_1.default.assertFileByNameInGeneratedFiles('stores.ts', results.files);
await Promise.all([
this.Service('typeChecker').check(typesFile),
this.Service('typeChecker').check(mapFile),
]);
}
static async syncStores() {
return this.Action('store', 'sync').execute({});
}
}
exports.default = KeepingDataStoresInSyncTest;
__decorate([
(0, test_utils_1.test)()
], KeepingDataStoresInSyncTest, "hasSyncAction", null);
__decorate([
(0, test_utils_1.test)()
], KeepingDataStoresInSyncTest, "syncsNothingToStart", null);
__decorate([
(0, test_utils_1.test)()
], KeepingDataStoresInSyncTest, "badFileReturnsError", null);
__decorate([
(0, test_utils_1.test)()
], KeepingDataStoresInSyncTest, "generatesValidTypeFile", null);
__decorate([
(0, test_utils_1.test)()
], KeepingDataStoresInSyncTest, "fileIsValidAfterSync", null);
__decorate([
(0, test_utils_1.test)()
], KeepingDataStoresInSyncTest, "canAddSecondStore", null);
//# sourceMappingURL=KeepingDataStoresInSync.test.js.map