UNPKG

declapract

Version:

A tool to declaratively define best practices, maintainable evolve them, and scalably enforce them.

52 lines (48 loc) 2.82 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const UserInputError_1 = require("../../../UserInputError"); const replaceProjectVariablesInDeclaredFileContents_1 = require("./replaceProjectVariablesInDeclaredFileContents"); const exampleReadmeFileContents = ` # @declapract{variable.serviceName} this is the readme for @declapract{variable.serviceName} of the @declapract{variable.organizationName} org the database service user is named '@declapract{variable.databaseUserName.serviceUser}'. you can auth under that in dev `.trim(); describe('replaceProjectVariablesInDeclaredFileContents', () => { it('should replace all occurrences of declared variables with their implemented values', () => __awaiter(void 0, void 0, void 0, function* () { const replacedFileContents = (0, replaceProjectVariablesInDeclaredFileContents_1.replaceProjectVariablesInDeclaredFileContents)({ projectVariables: { serviceName: 'super-cool-service', organizationName: 'org-of-coolness', databaseUserName: { serviceUser: 'super-cool-service-user' }, }, fileContents: exampleReadmeFileContents, }); expect(replacedFileContents).toEqual(` # super-cool-service this is the readme for super-cool-service of the org-of-coolness org the database service user is named 'super-cool-service-user'. you can auth under that in dev `.trim()); })); it('should throw an error if one of the variables did not have its value defined', () => __awaiter(void 0, void 0, void 0, function* () { try { (0, replaceProjectVariablesInDeclaredFileContents_1.replaceProjectVariablesInDeclaredFileContents)({ projectVariables: { organizationName: 'org-of-coolness' }, fileContents: exampleReadmeFileContents, }); fail('should not reach here'); } catch (error) { expect(error).toBeInstanceOf(UserInputError_1.UserInputError); } })); }); //# sourceMappingURL=replaceProjectVariablesInDeclaredFileContents.test.js.map