UNPKG

@apideck/portman

Version:

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

276 lines 14.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var Either = tslib_1.__importStar(require("fp-ts/lib/Either")); var fs_extra_1 = tslib_1.__importDefault(require("fs-extra")); var postman_collection_1 = require("postman-collection"); var application_1 = require("../application"); var lib_1 = require("../lib"); var oas_1 = require("../oas"); var postman_1 = require("../postman"); var utils_1 = require("../utils"); describe('TestSuite Variations', function () { var postmanParser; var oasParser; var testSuite; var postmanJson = '__tests__/fixtures/crm-multi-responses.postman.json'; var oasYml = '__tests__/fixtures/crm.yml'; var portmanConfigFile = '__tests__/fixtures/portman-variations.crm.json'; beforeEach(function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var postmanObj, configResult, config, options; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: oasParser = new oas_1.OpenApiParser(); return [4, oasParser.convert({ inputFile: oasYml })]; case 1: _a.sent(); postmanObj = JSON.parse(fs_extra_1.default.readFileSync(postmanJson).toString()); return [4, (0, lib_1.getConfig)(portmanConfigFile)]; case 2: configResult = _a.sent(); if (Either.isLeft(configResult)) { return [2, utils_1.PortmanError.render(configResult.left)]; } config = configResult.right; postmanParser = new postman_1.PostmanParser({ collection: new postman_collection_1.Collection(postmanObj), oasParser: oasParser }); options = { includeTests: true }; testSuite = new application_1.TestSuite({ oasParser: oasParser, postmanParser: postmanParser, config: config, options: options }); testSuite.variationWriter = new application_1.VariationWriter({ testSuite: testSuite, variationFolderName: 'Variation Tests' }); return [2]; } }); }); }); it('should generateVariationTests for variations', function () { testSuite.generateVariationTests(); expect((0, utils_1.omitKeys)(testSuite.collection.toJSON(), ['id', '_postman_id'])).toMatchSnapshot(); }); }); describe('TestSuite Variations openApiResponse content-types', function () { var postmanParser; var oasParser; var testSuite; var postmanJson = '__tests__/fixtures/crm-multi-responses.postman.json'; var oasYml = '__tests__/fixtures/crm-multi-responses.yml'; beforeEach(function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var postmanObj; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: oasParser = new oas_1.OpenApiParser(); return [4, oasParser.convert({ inputFile: oasYml })]; case 1: _a.sent(); postmanObj = JSON.parse(fs_extra_1.default.readFileSync(postmanJson).toString()); postmanParser = new postman_1.PostmanParser({ collection: new postman_collection_1.Collection(postmanObj), oasParser: oasParser }); return [2]; } }); }); }); it('should use a specific content-type when multiple are available', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var configResult, config; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4, (0, lib_1.getConfig)('__tests__/fixtures/portman-variations.multiple-ct-specific.json')]; case 1: configResult = _a.sent(); if (Either.isLeft(configResult)) { return [2, utils_1.PortmanError.render(configResult.left)]; } config = configResult.right; testSuite = new application_1.TestSuite({ oasParser: oasParser, postmanParser: postmanParser, config: config }); testSuite.variationWriter = new application_1.VariationWriter({ testSuite: testSuite, variationFolderName: 'Variation Tests' }); testSuite.generateVariationTests(); expect((0, utils_1.omitKeys)(testSuite.collection.toJSON(), ['id', '_postman_id'])).toMatchSnapshot(); return [2]; } }); }); }); it('should handle wildcard content-type and generate multiple variations', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var configResult, config; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4, (0, lib_1.getConfig)('__tests__/fixtures/portman-variations.multiple-ct-wildcard.json')]; case 1: configResult = _a.sent(); if (Either.isLeft(configResult)) { return [2, utils_1.PortmanError.render(configResult.left)]; } config = configResult.right; testSuite = new application_1.TestSuite({ oasParser: oasParser, postmanParser: postmanParser, config: config }); testSuite.variationWriter = new application_1.VariationWriter({ testSuite: testSuite, variationFolderName: 'Variation Tests' }); testSuite.generateVariationTests(); expect((0, utils_1.omitKeys)(testSuite.collection.toJSON(), ['id', '_postman_id'])).toMatchSnapshot(); return [2]; } }); }); }); }); describe('TestSuite Variations openApiRequest content-types', function () { var postmanParser; var oasParser; var testSuite; var postmanJson = '__tests__/fixtures/request-multi.postman.json'; var oasYml = '__tests__/fixtures/request-multi.yml'; beforeEach(function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var postmanObj; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: oasParser = new oas_1.OpenApiParser(); return [4, oasParser.convert({ inputFile: oasYml })]; case 1: _a.sent(); postmanObj = JSON.parse(fs_extra_1.default.readFileSync(postmanJson).toString()); postmanParser = new postman_1.PostmanParser({ collection: new postman_collection_1.Collection(postmanObj), oasParser: oasParser }); return [2]; } }); }); }); it('should use a specific request content-type when multiple are available', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var configResult, config; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4, (0, lib_1.getConfig)('__tests__/fixtures/portman-variations.request-ct-specific.json')]; case 1: configResult = _a.sent(); if (Either.isLeft(configResult)) { return [2, utils_1.PortmanError.render(configResult.left)]; } config = configResult.right; testSuite = new application_1.TestSuite({ oasParser: oasParser, postmanParser: postmanParser, config: config }); testSuite.variationWriter = new application_1.VariationWriter({ testSuite: testSuite, variationFolderName: 'Variation Tests' }); testSuite.generateVariationTests(); expect((0, utils_1.omitKeys)(testSuite.collection.toJSON(), ['id', '_postman_id'])).toMatchSnapshot(); return [2]; } }); }); }); it('should handle wildcard request content-type and generate multiple variations', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var configResult, config; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4, (0, lib_1.getConfig)('__tests__/fixtures/portman-variations.request-ct-wildcard.json')]; case 1: configResult = _a.sent(); if (Either.isLeft(configResult)) { return [2, utils_1.PortmanError.render(configResult.left)]; } config = configResult.right; testSuite = new application_1.TestSuite({ oasParser: oasParser, postmanParser: postmanParser, config: config }); testSuite.variationWriter = new application_1.VariationWriter({ testSuite: testSuite, variationFolderName: 'Variation Tests' }); testSuite.generateVariationTests(); expect((0, utils_1.omitKeys)(testSuite.collection.toJSON(), ['id', '_postman_id'])).toMatchSnapshot(); return [2]; } }); }); }); }); describe('TestSuite Variations response codes', function () { var postmanParser; var oasParser; var testSuite; var postmanJson = '__tests__/fixtures/crm-multi-responses.postman.json'; var oasYml = '__tests__/fixtures/multiple-content-types.yml'; beforeEach(function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var postmanObj; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: oasParser = new oas_1.OpenApiParser(); return [4, oasParser.convert({ inputFile: oasYml })]; case 1: _a.sent(); postmanObj = JSON.parse(fs_extra_1.default.readFileSync(postmanJson).toString()); postmanParser = new postman_1.PostmanParser({ collection: new postman_collection_1.Collection(postmanObj), oasParser: oasParser }); return [2]; } }); }); }); it('should handle partial wildcard response codes and generate multiple variations', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var configResult, config; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4, (0, lib_1.getConfig)('__tests__/fixtures/portman-variations.response-code-partial-wildcard.json')]; case 1: configResult = _a.sent(); if (Either.isLeft(configResult)) { return [2, utils_1.PortmanError.render(configResult.left)]; } config = configResult.right; testSuite = new application_1.TestSuite({ oasParser: oasParser, postmanParser: postmanParser, config: config }); testSuite.variationWriter = new application_1.VariationWriter({ testSuite: testSuite, variationFolderName: 'Variation Tests' }); testSuite.generateVariationTests(); expect((0, utils_1.omitKeys)(testSuite.collection.toJSON(), [ 'id', '_postman_id', 'request', 'response', 'type', 'listen' ])).toMatchSnapshot(); return [2]; } }); }); }); it('should handle wildcard response codes and generate multiple variations', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var configResult, config; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4, (0, lib_1.getConfig)('__tests__/fixtures/portman-variations.response-code-wildcard.json')]; case 1: configResult = _a.sent(); if (Either.isLeft(configResult)) { return [2, utils_1.PortmanError.render(configResult.left)]; } config = configResult.right; testSuite = new application_1.TestSuite({ oasParser: oasParser, postmanParser: postmanParser, config: config }); testSuite.variationWriter = new application_1.VariationWriter({ testSuite: testSuite, variationFolderName: 'Variation Tests' }); testSuite.generateVariationTests(); expect((0, utils_1.omitKeys)(testSuite.collection.toJSON(), [ 'id', '_postman_id', 'request', 'response', 'type', 'listen' ])).toMatchSnapshot(); return [2]; } }); }); }); }); //# sourceMappingURL=TestSuiteVariations.test.js.map