UNPKG

@apideck/portman

Version:

Port OpenAPI Spec to Postman Collection, with contract & variation tests included

182 lines 8.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var fs_extra_1 = tslib_1.__importDefault(require("fs-extra")); var path_1 = tslib_1.__importDefault(require("path")); var uuid_1 = require("uuid"); var Portman_1 = require("./Portman"); var utils_1 = require("./utils"); var postman_collection_1 = require("postman-collection"); describe('Portman', function () { beforeEach(function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) { jest.spyOn(global.console, 'log').mockImplementation(function () { }); return [2]; }); }); }); afterEach(function () { jest.clearAllMocks(); }); it('should be runnable', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var outputFile, portman, outputFilePath, _a, finalCollection, _b, _c; return tslib_1.__generator(this, function (_d) { switch (_d.label) { case 0: outputFile = "./tmp/converted/crmApi.".concat((0, uuid_1.v4)(), ".json"); portman = new Portman_1.Portman({ postmanUid: 'eb1ffad6-eece-456b-ad32-3f2a3f605537', oaLocal: './__tests__/fixtures/crm-run.yml', postmanConfigFile: './__tests__/fixtures/postman-config.run.json', postmanConfigPath: './__tests__/fixtures/postman-config.run.json', portmanConfigFile: './__tests__/fixtures/portman.kitchensink.json', portmanConfigPath: './__tests__/fixtures/portman.kitchensink.json', envFile: './__tests__/fixtures/.crm.env', baseUrl: 'http://localhost:3050', output: outputFile, syncPostman: false, includeTests: true, runNewman: false }); return [4, portman.run()]; case 1: _d.sent(); outputFilePath = path_1.default.resolve(outputFile); _a = expect; return [4, fs_extra_1.default.pathExists(outputFilePath)]; case 2: _a.apply(void 0, [_d.sent()]).toBe(true); _c = (_b = JSON).parse; return [4, fs_extra_1.default.readFile(outputFilePath, 'utf8')]; case 3: finalCollection = _c.apply(_b, [_d.sent()]); expect((0, utils_1.omitKeys)(finalCollection, ['id', '_postman_id', 'postman_id', 'info'])).toMatchSnapshot(); return [2]; } }); }); }, 30000); it('convert oneOf OAS, verify schema', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var outputFile, portman, outputFilePath, _a, finalCollection, _b, _c, result, result; var _d, _e, _f, _g, _h; return tslib_1.__generator(this, function (_j) { switch (_j.label) { case 0: outputFile = "./tmp/converted/crmApi.".concat((0, uuid_1.v4)(), ".json"); portman = new Portman_1.Portman({ oaLocal: './__tests__/fixtures/oas-oneof.yaml', portmanConfigFile: 'portman-config.default.json', portmanConfigPath: 'portman-config.default.json', postmanConfigFile: './__tests__/fixtures/postman-config.run.json', postmanConfigPath: './__tests__/fixtures/postman-config.run.json', baseUrl: 'http://localhost:3050', output: outputFile, syncPostman: false, includeTests: true, runNewman: false }); return [4, portman.run()]; case 1: _j.sent(); outputFilePath = path_1.default.resolve(outputFile); _a = expect; return [4, fs_extra_1.default.pathExists(outputFilePath)]; case 2: _a.apply(void 0, [_j.sent()]).toBe(true); _c = (_b = JSON).parse; return [4, fs_extra_1.default.readFile(outputFilePath, 'utf8')]; case 3: finalCollection = _c.apply(_b, [_j.sent()]); if ((_h = (_g = (_f = (_e = (_d = finalCollection === null || finalCollection === void 0 ? void 0 : finalCollection.item) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.event) === null || _f === void 0 ? void 0 : _f[0]) === null || _g === void 0 ? void 0 : _g.script) === null || _h === void 0 ? void 0 : _h.exec) { result = finalCollection.item[0].event[0].script.exec; expect(result).toMatchSnapshot(); } else { result = finalCollection.item[0].item[0].event[0].script.exec; expect(result).toMatchSnapshot(); } return [2]; } }); }); }, 30000); }); describe('Portman version', function () { var outputFile = "./tmp/converted/crmApi.".concat((0, uuid_1.v4)(), ".json"); var portmanInstance; beforeEach(function () { portmanInstance = new Portman_1.Portman({ postmanUid: 'eb1ffad6-eece-456b-ad32-3f2a3f605537', oaLocal: './__tests__/fixtures/crm.yml', postmanConfigFile: './__tests__/fixtures/postman-config.json', portmanConfigFile: './__tests__/fixtures/portman.kitchensink.json', portmanConfigPath: './__tests__/fixtures/portman.kitchensink.json', envFile: './__tests__/fixtures/.crm.env', baseUrl: 'http://localhost:3050', output: outputFile, syncPostman: false, includeTests: true, runNewman: false }); portmanInstance.config = { globals: { stripResponseExamples: false, portmanReplacements: null } }; portmanInstance.oasParser = { oas: { info: { version: '1.2.3' } } }; portmanInstance.postmanParser = { collection: new postman_collection_1.Collection({ info: { name: 'Test Collection' } }) }; }); it('should set the postman collection version from the OpenAPI version', function () { portmanInstance.writePortmanCollectionToFile(); expect(portmanInstance.postmanParser.collection.version).toEqual(new postman_collection_1.Version('1.2.3')); }); it('should nto return the postman collection version since it is an incomplete version', function () { portmanInstance.oasParser = { oas: { info: { version: '1.2' } } }; portmanInstance.writePortmanCollectionToFile(); expect(portmanInstance.postmanParser.collection.version).toBeUndefined(); }); it('should handle swagger 2.0 info', function () { portmanInstance.oasParser = { oas: { swagger: '2.0', info: { version: 'v1' } } }; portmanInstance.writePortmanCollectionToFile(); expect(portmanInstance.postmanParser.collection.version).toBeUndefined(); expect(portmanInstance.portmanCollection.info.version).toBeUndefined(); expect(portmanInstance.portmanCollection.info.name).toEqual('Test Collection'); }); it('should handle case when there is no version', function () { portmanInstance.oasParser = { oas: { info: { title: 'Test Collection' } } }; portmanInstance.writePortmanCollectionToFile(); expect(portmanInstance.postmanParser.collection.version).toBeUndefined(); expect(portmanInstance.portmanCollection.info.version).toBeUndefined(); expect(portmanInstance.portmanCollection.info.name).toEqual('Test Collection'); }); }); //# sourceMappingURL=Portman.test.js.map