UNPKG

declapract

Version:

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

91 lines (87 loc) 3.24 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const yaml_1 = __importDefault(require("yaml")); const readFileAsync_1 = require("./readFileAsync"); const readYmlFile_1 = require("./readYmlFile"); jest.mock('./readFileAsync'); const readFileAsyncMock = readFileAsync_1.readFileAsync; readFileAsyncMock.mockResolvedValue(` - type: change path: 'init/service_user.sql' id: 'init_20190619_1' reapplyOnUpdate: false # we'll do it manually for now - type: change id: 'data_20190619_1' path: 'data/data_sources.sql' reapplyOnUpdate: false # only run each insert once - type: change id: 'procedures_20190619_1' path: 'procedures/awesome_sproc.sql' reapplyOnUpdate: true `); describe('readDefinitionsFileRecursive', () => { beforeEach(() => jest.clearAllMocks()); it('should throw an error if the filepath defined does not point to a yml file', async () => { try { await (0, readYmlFile_1.readYmlFile)({ filePath: 'some.json' }); throw new Error('should not reach here'); } catch (error) { expect(error.message).toMatch('file path point to a .yml file.'); } }); it('should attempt to read the file', async () => { await (0, readYmlFile_1.readYmlFile)({ filePath: 'some.yml' }); expect(readFileAsyncMock.mock.calls.length).toEqual(1); expect(readFileAsyncMock.mock.calls[0][0]).toEqual({ filePath: 'some.yml', }); }); it('should parse the contents into yml with the YAML library', async () => { const spy = jest.spyOn(yaml_1.default, 'parse'); expect(spy.mock.calls.length).toEqual(0); await (0, readYmlFile_1.readYmlFile)({ filePath: 'some.yml' }); expect(spy.mock.calls.length).toEqual(1); }); it('should return the parsed yml content', async () => { readFileAsyncMock.mockResolvedValueOnce(` - type: change path: 'init/service_user.sql' id: 'init_20190619_1' reapplyOnUpdate: false # we'll do it manually for now - type: change id: 'data_20190619_1' path: 'data/data_sources.sql' reapplyOnUpdate: false # only run each insert once - type: change id: 'procedures_20190619_1' path: 'procedures/awesome_sproc.sql' reapplyOnUpdate: true `); const result = await (0, readYmlFile_1.readYmlFile)({ filePath: 'some.yml' }); expect(result).toMatchObject([ { type: 'change', path: 'init/service_user.sql', id: 'init_20190619_1', reapplyOnUpdate: false, }, { type: 'change', id: 'data_20190619_1', path: 'data/data_sources.sql', reapplyOnUpdate: false, }, { type: 'change', id: 'procedures_20190619_1', path: 'procedures/awesome_sproc.sql', reapplyOnUpdate: true, }, ]); }); }); //# sourceMappingURL=readYmlFile.test.js.map