diff --git a/.gitignore b/.gitignore index 4544cc035..3d3f1a253 100644 --- a/.gitignore +++ b/.gitignore @@ -64,4 +64,6 @@ typings/ # next.js build output .next -out/ \ No newline at end of file +out/ + +newmanResponses.json \ No newline at end of file diff --git a/codegens/csharp-restsharp/test/unit/convert.test.js b/codegens/csharp-restsharp/test/unit/convert.test.js index 06d66a832..a93f48b84 100644 --- a/codegens/csharp-restsharp/test/unit/convert.test.js +++ b/codegens/csharp-restsharp/test/unit/convert.test.js @@ -1,142 +1,16 @@ var expect = require('chai').expect, - fs = require('fs'), + path = require('path'), sdk = require('postman-collection'), - exec = require('shelljs').exec, - newman = require('newman'), - parallel = require('async').parallel, + runSnippet = require('../../../../test/codegen/newman/newman.test').runSnippet, convert = require('../../lib/index').convert, - mainCollection = require('./fixtures/testcollection/collection.json'), + mainCollection = require('../../../../test/codegen/newman/fixtures/testCollection2.json'), testCollection = require('./fixtures/testcollection/collectionForEdge.json'), getOptions = require('../../lib/index').getOptions, testResponse = require('./fixtures/testresponse.json'), sanitize = require('../../lib/util').sanitize, sanitizeOptions = require('../../lib/util').sanitizeOptions; -/** - * compiles and runs codesnippet then compare it with newman output - * - * @param {String} codeSnippet - code snippet that needed to run using C# - * @param {Object} collection - collection which will be run using newman - * @param {Function} done - callback for async calls - */ -function runSnippet (codeSnippet, collection, done) { - const depedenciesPath = 'test/unit/fixtures/dependencies'; - - fs.writeFile(`${depedenciesPath}/main.cs`, codeSnippet, function (err) { - if (err) { - expect.fail(null, null, err); - return done(); - } - - // bash command string for compiling C# - var compile = `mcs -reference:${depedenciesPath}/RestSharp.dll` + - ` -out:${depedenciesPath}/main.exe ${depedenciesPath}/main.cs`, - - // bash command stirng for run compiled C# file - run = `mono ${depedenciesPath}/main.exe`; - - // step by step process for compile, run code snippet, then comparing its output with newman - parallel([ - function (callback) { - exec(compile, function (err, stdout, stderr) { - if (err) { - return callback(err); - } - if (stderr) { - return callback(stderr); - } - return exec(run, function (err, stdout, stderr) { - if (err) { - return callback(err); - } - if (stderr) { - return callback(stderr); - } - try { - stdout = JSON.parse(stdout); - } - catch (e) { - console.error(); - } - return callback(null, stdout); - }); - }); - }, - function (callback) { - newman.run({ - collection: collection - }).on('request', function (err, summary) { - if (err) { - return callback(err); - } - - var stdout = summary.response.stream.toString(); - try { - stdout = JSON.parse(stdout); - } - catch (e) { - console.error(); - } - return callback(null, stdout); - }); - } - ], function (err, result) { - if (err) { - expect.fail(null, null, err); - } - else if (typeof result[1] !== 'object' || typeof result[0] !== 'object') { - expect(result[0].trim()).to.equal(result[1].trim()); - } - else { - const propertiesTodelete = ['cookies', 'headersSize', 'startedDateTime', 'clientIPAddress'], - headersTodelete = [ - 'accept-encoding', - 'user-agent', - 'cf-ray', - 'kong-cloud-request-id', // random ID generated by mockbin - 'x-real-ip', - 'x-request-id', - 'x-request-start', - 'connect-time', - 'x-forwarded-for', - 'cache-control', - 'content-type', - 'content-length', - 'accept', - 'accept-language', - 'total-route-time', - 'cookie', - 'postman-token' - ]; - if (result[0]) { - propertiesTodelete.forEach(function (property) { - delete result[0][property]; - }); - if (result[0].headers) { - headersTodelete.forEach(function (property) { - delete result[0].headers[property]; - }); - } - } - if (result[1]) { - propertiesTodelete.forEach(function (property) { - delete result[1][property]; - }); - if (result[1].headers) { - headersTodelete.forEach(function (property) { - delete result[1].headers[property]; - }); - } - } - - expect(result[0]).deep.equal(result[1]); - } - return done(); - }); - }); -} - describe('csharp restsharp function', function () { describe('convert for different request types', function () { var headerSnippet = 'using System;\n' + @@ -146,15 +20,15 @@ describe('csharp restsharp function', function () { 'static void Main(string[] args) {\n', footerSnippet = '}\n}\n}\n'; - mainCollection.item.forEach(function (item) { + mainCollection.item.forEach(function (item, index) { it(item.name, function (done) { var request = new sdk.Request(item.request), - collection = { - item: [ - { - request: request.toJSON() - } - ] + depedenciesPath = path.resolve(__dirname, 'fixtures/dependencies'), + testConfig = { + compileScript: `mcs -reference:${depedenciesPath}/RestSharp.dll` + + ` -out:${depedenciesPath}/main.exe ${depedenciesPath}/main.cs`, + runScript: `mono ${depedenciesPath}/main.exe`, + fileName: `${depedenciesPath}/main.cs` }, options = { indentCount: 1, @@ -168,7 +42,17 @@ describe('csharp restsharp function', function () { expect.fail(null, null, error); return; } - runSnippet(headerSnippet + snippet + footerSnippet, collection, done); + runSnippet(headerSnippet + snippet + footerSnippet, index, testConfig, function (err, result) { + if (err) { + expect.fail(null, null, err); + } + if (typeof result[1] !== 'object' || typeof result[0] !== 'object') { + expect(result[0].toString().trim()).to.include(result[1].toString().trim()); + } + + expect(result[0]).deep.equal(result[1]); + return done(); + }); }); }); return false; diff --git a/codegens/curl/test/unit/convert.test.js b/codegens/curl/test/unit/convert.test.js index fa4846485..5f28d6d74 100644 --- a/codegens/curl/test/unit/convert.test.js +++ b/codegens/curl/test/unit/convert.test.js @@ -1,130 +1,14 @@ var expect = require('chai').expect, sdk = require('postman-collection'), - exec = require('shelljs').exec, - newman = require('newman'), - parallel = require('async').parallel, - + runSnippet = require('../../../../test/codegen/newman/newman.test').runSnippet, convert = require('../../index').convert, - mainCollection = require('./fixtures/testcollection/collection.json'); - -/** - * runs codesnippet then compare it with newman output - * - * @param {String} codeSnippet - code snippet that needed to run using java - * @param {Object} collection - collection which will be run using newman - * @param {Function} done - callback for async calls - */ -function runSnippet (codeSnippet, collection, done) { - - // step by step process for compile, run code snippet, then comparing its output with newman - parallel([ - function (callback) { - return exec(codeSnippet, function (err, stdout, stderr) { - if (err) { - return callback(err); - } - if (stderr) { - return callback(stderr); - } - try { - stdout = JSON.parse(stdout); - } - catch (e) { - console.error(e); - } - return callback(null, stdout); - }); - }, - function (callback) { - newman.run({ - collection: collection - }).on('request', function (err, summary) { - if (err) { - return callback(err); - } - - var stdout = summary.response.stream.toString(); - if (summary.request.method === 'HEAD') { - stdout = summary.response.code.toString(); - return callback(null, stdout); - } - try { - stdout = JSON.parse(stdout); - } - catch (e) { - console.error(e); - } - return callback(null, stdout); - }); - } - ], function (err, result) { - if (err) { - expect.fail(null, null, err); - } - else if (typeof result[1] !== 'object' || typeof result[0] !== 'object') { - expect(result[0].trim()).to.include(result[1].trim()); - } - else { - const propertiesTodelete = ['cookies', 'headersSize', 'startedDateTime', 'clientIPAddress'], - headersTodelete = [ - 'accept-encoding', - 'user-agent', - 'cf-ray', - 'x-real-ip', - 'x-request-id', - 'kong-request-id', - 'x-request-start', - 'connect-time', - 'x-forwarded-for', - 'content-type', - 'content-length', - 'accept', - 'total-route-time', - 'cookie', - 'kong-cloud-request-id', - 'cache-control', - 'postman-token' - ]; - if (result[0]) { - propertiesTodelete.forEach(function (property) { - delete result[0][property]; - }); - if (result[0].headers) { - headersTodelete.forEach(function (property) { - delete result[0].headers[property]; - }); - } - } - if (result[1]) { - propertiesTodelete.forEach(function (property) { - delete result[1][property]; - }); - if (result[1].headers) { - headersTodelete.forEach(function (property) { - delete result[1].headers[property]; - }); - } - } - - expect(result[0]).deep.equal(result[1]); - } - return done(); - }); -} + mainCollection = require('../../../../test/codegen/newman/fixtures/testCollection.json'); describe('curl convert function', function () { describe('convert for different request types', function () { - - mainCollection.item.forEach(function (item) { + mainCollection.item.forEach(function (item, index) { it(item.name, function (done) { var request = new sdk.Request(item.request), - collection = { - item: [ - { - request: request.toJSON() - } - ] - }, options = { indentCount: 3, indentType: 'Space', @@ -140,7 +24,18 @@ describe('curl convert function', function () { expect.fail(null, null, error); return; } - runSnippet(snippet, collection, done); + runSnippet(snippet, index, {compileScript: null, runScript: null, fileName: null}, function (err, result) { + if (err) { + expect.fail(null, null, err); + } + if (typeof result[1] !== 'object' || typeof result[0] !== 'object') { + expect(result[0].toString().trim()).to.include(result[1].toString().trim()); + } + + expect(result[0]).deep.equal(result[1]); + return done(); + }); + }); }); }); diff --git a/codegens/java-okhttp/test/unit/convert.test.js b/codegens/java-okhttp/test/unit/convert.test.js index 0be789ba5..91d86f07d 100644 --- a/codegens/java-okhttp/test/unit/convert.test.js +++ b/codegens/java-okhttp/test/unit/convert.test.js @@ -1,129 +1,10 @@ var expect = require('chai').expect, - fs = require('fs'), sdk = require('postman-collection'), - exec = require('shelljs').exec, - newman = require('newman'), - parallel = require('async').parallel, sanitize = require('../../lib/util').sanitize, convert = require('../../lib/index').convert, getOptions = require('../../lib/index').getOptions, - mainCollection = require('./fixtures/testcollection/collection.json'); - -/** - * compiles and runs codesnippet then compare it with newman output - * - * @param {String} codeSnippet - code snippet that needed to run using java - * @param {Object} collection - collection which will be run using newman - * @param {Function} done - callback for async calls - */ -function runSnippet (codeSnippet, collection, done) { - fs.writeFileSync('main.java', codeSnippet); - - // classpath of external libararies for java to compile - var compile = 'javac -cp *: main.java', - - // bash command stirng for run compiled java file - run = 'java -cp *: main'; - - // step by step process for compile, run code snippet, then comparing its output with newman - parallel([ - function (callback) { - exec(compile, function (err, stdout, stderr) { - if (err) { - return callback(err); - } - if (stderr) { - return callback(stderr); - } - return exec(run, function (err, stdout, stderr) { - if (err) { - return callback(err); - } - if (stderr) { - return callback(stderr); - } - try { - stdout = JSON.parse(stdout); - } - catch (e) { - console.error(e); - } - return callback(null, stdout); - }); - }); - }, - function (callback) { - newman.run({ - collection: collection - }).on('request', function (err, summary) { - if (err) { - return callback(err); - } - - var stdout = summary.response.stream.toString(); - try { - stdout = JSON.parse(stdout); - } - catch (e) { - console.error(e); - } - return callback(null, stdout); - }); - } - ], function (err, result) { - if (err) { - expect.fail(null, null, err); - } - else if (typeof result[1] !== 'object' || typeof result[0] !== 'object') { - expect(result[0].trim()).to.equal(result[1].trim()); - } - else { - const propertiesTodelete = ['cookies', 'headersSize', 'startedDateTime', 'clientIPAddress'], - headersTodelete = [ - 'accept-encoding', - 'user-agent', - 'cf-ray', - 'x-request-id', - 'x-request-start', - 'connect-time', - 'x-forwarded-for', - 'content-type', - 'content-length', - 'accept', - 'total-route-time', - 'cookie', - 'x-real-ip', - 'kong-cloud-request-id', - 'cache-control', - 'postman-token', - 'x-real-ip' - ]; - if (result[0]) { - propertiesTodelete.forEach(function (property) { - delete result[0][property]; - }); - if (result[0].headers) { - headersTodelete.forEach(function (property) { - delete result[0].headers[property]; - }); - } - } - if (result[1]) { - propertiesTodelete.forEach(function (property) { - delete result[1][property]; - }); - if (result[1].headers) { - headersTodelete.forEach(function (property) { - delete result[1].headers[property]; - }); - } - } - - expect(result[0]).deep.equal(result[1]); - } - return done(); - }); -} + runSnippet = require('../../../../test/codegen/newman/newman.test').runSnippet, + mainCollection = require('../../../../test/codegen/newman/fixtures/testCollection.json'); describe('okhttp convert function', function () { describe('convert for different request types', function () { @@ -133,22 +14,31 @@ describe('okhttp convert function', function () { 'public static void main(String []args) throws IOException{\n', footerSnippet = 'System.out.println(response.body().string());\n}\n}\n'; - mainCollection.item.forEach(function (item) { + mainCollection.item.forEach(function (item, index) { it(item.name, function (done) { var request = new sdk.Request(item.request), - collection = { - item: [ - { - request: request.toJSON() - } - ] + testConfig = { + compileScript: 'javac -cp *: main.java', + runScript: 'java -cp *: main', + fileName: 'main.java' }; + convert(request, {indentCount: 3, indentType: 'Space'}, function (error, snippet) { if (error) { expect.fail(null, null, error); return; } - runSnippet(headerSnippet + snippet + footerSnippet, collection, done); + runSnippet(headerSnippet + snippet + footerSnippet, index, testConfig, function (err, result) { + if (err) { + expect.fail(null, null, err); + } + if (typeof result[1] !== 'object' || typeof result[0] !== 'object') { + expect(result[1].toString().trim()).to.include(result[0].toString().trim()); + } + + expect(result[0]).deep.equal(result[1]); + return done(); + }); }); }); }); diff --git a/codegens/libcurl/test/unit/convert.test.js b/codegens/libcurl/test/unit/convert.test.js index 06226db94..fcc025192 100644 --- a/codegens/libcurl/test/unit/convert.test.js +++ b/codegens/libcurl/test/unit/convert.test.js @@ -1,150 +1,27 @@ var expect = require('chai').expect, sdk = require('postman-collection'), - fs = require('fs'), - newman = require('newman'), - parallel = require('async').parallel, - exec = require('shelljs').exec, convert = require('../../index').convert, + runSnippet = require('../../../../test/codegen/newman/newman.test').runSnippet, getOptions = require('../../index').getOptions, sanitize = require('../../lib/util').sanitize, - mainCollection = require('./fixtures/testcollection/collection.json'); - -/** - * runs codesnippet then compare it with newman output - * - * @param {String} codeSnippet - Generated libcurl code snippet - * @param {Object} collection - collection which will be run using newman - * @param {Function} done - callback for async calls - */ -function runSnippet (codeSnippet, collection, done) { - fs.writeFileSync('testFile.c', codeSnippet); - - // step by step process for compile, run code snippet, then comparing its output with newman - parallel([ - function (callback) { - exec('`curl-config --cc --cflags` -o executableFile testFile.c `curl-config --libs`', - function (err, stdout, stderr) { - if (err) { - return callback(err); - } - if (stderr) { - return callback(stderr); - } - - exec('./executableFile', function (err, stdout, stderr) { - if (err) { - return callback(err); - } - if (stderr) { - return callback(stderr); - } - // this because response also display response code at the end of response body - stdout = stdout.substring(0, stdout.length - 3); - try { - stdout = JSON.parse(stdout); - } - catch (e) { - console.error(e); - } - - return callback(null, stdout); - }); - }); - }, - function (callback) { - newman.run({ - collection: collection - }).on('request', function (err, summary) { - if (err) { - return callback(err); - } - - var stdout = summary.response.stream.toString(); - - try { - stdout = JSON.parse(stdout); - } - catch (e) { - console.error(e); - } - - return callback(null, stdout); - }); - } - ], function (err, result) { - if (err) { - expect.fail(null, null, err); - } - else if (typeof result[1] !== 'object' || typeof result[0] !== 'object') { - expect(result[0].toString().trim()).to.include(result[1].toString().trim()); - } - else { - const propertiesTodelete = ['cookies', 'headersSize', 'startedDateTime', 'clientIPAddress'], - headersTodelete = [ - 'accept-encoding', - 'user-agent', - 'cf-ray', - 'x-request-id', - 'x-request-start', - 'connect-time', - 'x-forwarded-for', - 'content-type', - 'kong-cloud-request-id', - 'content-length', - 'accept', - 'total-route-time', - 'cookie', - 'cache-control', - 'postman-token', - 'x-real-ip' - ]; - - if (result[0]) { - propertiesTodelete.forEach(function (property) { - delete result[0][property]; - }); - if (result[0].headers) { - headersTodelete.forEach(function (property) { - delete result[0].headers[property]; - }); - } - } - if (result[1]) { - propertiesTodelete.forEach(function (property) { - delete result[1][property]; - }); - if (result[1].headers) { - headersTodelete.forEach(function (property) { - delete result[1].headers[property]; - }); - } - } - - expect(result[0]).deep.equal(result[1]); - } - - return done(); - }); -} + mainCollection = require('../../../../test/codegen/newman/fixtures/testCollection.json'); describe('libcurl convert function', function () { describe('convert for different request types', function () { - mainCollection.item.forEach(function (item) { + mainCollection.item.forEach(function (item, index) { it(item.name, function (done) { var request = new sdk.Request(item.request), - collection = { - item: [ - { - request: request.toJSON() - } - ] - }, options = { indentCount: 1, indentType: 'Tab', useMimeType: false, includeBoilerplate: true + }, + testConfig = { + compileScript: '`curl-config --cc --cflags` -o executableFile testFile.c `curl-config --libs`', + runScript: './executableFile', + fileName: './executableFile' }; convert(request, options, function (error, snippet) { @@ -153,18 +30,17 @@ describe('libcurl convert function', function () { return; } - runSnippet(snippet, collection, function () { - fs.unlinkSync('./testFile.c', (err) => { - if (err) { - console.log('Unable to delete testFile.c'); - } - }); - fs.unlinkSync('./executableFile', (err) => { - if (err) { - console.log('Unable to deleted executable file'); - } - }); - done(); + + runSnippet(snippet, index, testConfig, function () { + if (err) { + expect.fail(null, null, err); + } + if (typeof result[1] !== 'object' || typeof result[0] !== 'object') { + expect(result[0].toString().trim()).to.include(result[1].toString().trim()); + } + + expect(result[0]).deep.equal(result[1]); + return done(); }); }); }); diff --git a/codegens/nodejs-native/test/unit/snippet.test.js b/codegens/nodejs-native/test/unit/snippet.test.js index 7f75875f2..c058ef4d4 100644 --- a/codegens/nodejs-native/test/unit/snippet.test.js +++ b/codegens/nodejs-native/test/unit/snippet.test.js @@ -1,134 +1,14 @@ var expect = require('chai').expect, - fs = require('fs'), sdk = require('postman-collection'), - exec = require('shelljs').exec, - newman = require('newman'), - parallel = require('async').parallel, - + runSnippet = require('../../../../test/codegen/newman/newman.test').runSnippet, convert = require('../../lib/index').convert, - mainCollection = require('./fixtures/testcollection/collection.json'); - -/** - * compiles and runs codesnippet then compare it with newman output - * - * @param {String} codeSnippet - code snippet that needed to run using java - * @param {Object} collection - collection which will be run using newman - * @param {Function} done - callback for async call from mocha - */ -function runSnippet (codeSnippet, collection, done) { - fs.writeFile('run.js', codeSnippet, function (err) { - if (err) { - expect.fail(null, null, err); - return done(); - } - - var run = 'node run.js'; - - // step by step process for compile, run code snippet, then comparing its output with newman - parallel([ - function (callback) { - exec(run, function (err, stdout, stderr) { - if (err) { - return callback(err); - } - if (stderr) { - return callback(stderr); - } - - try { - stdout = JSON.parse(stdout); - } - catch (e) { - console.error(e); - } - return callback(null, stdout); - }); - }, - function (callback) { - newman.run({ - collection: collection - }).on('request', function (err, summary) { - if (err) { - return callback(err); - } - - var stdout = summary.response.stream.toString(); - try { - stdout = JSON.parse(stdout); - } - catch (e) { - console.error(e); - } - return callback(null, stdout); - }); - } - ], function (err, result) { - if (err) { - console.error(err); - expect.fail(null, null, err); - } - else if (typeof result[1] !== 'object' || typeof result[0] !== 'object') { - expect(result[0].trim()).to.equal(result[1].trim()); - } - else { - const propertiesTodelete = ['cookies', 'headersSize', 'startedDateTime', 'clientIPAddress'], - headersTodelete = [ - 'accept-encoding', - 'user-agent', - 'cf-ray', - 'x-request-id', - 'x-request-start', - 'kong-request-id', - 'connect-time', - 'x-forwarded-for', - 'content-type', - 'content-length', - 'accept', - 'total-route-time', - 'cookie', - 'kong-cloud-request-id', - 'x-real-ip', - 'cache-control', - 'postman-token' - ]; - if (result[0]) { - propertiesTodelete.forEach(function (property) { - delete result[0][property]; - }); - if (result[0].headers) { - headersTodelete.forEach(function (property) { - delete result[0].headers[property]; - }); - } - } - if (result[1]) { - propertiesTodelete.forEach(function (property) { - delete result[1][property]; - }); - if (result[1].headers) { - headersTodelete.forEach(function (property) { - delete result[1].headers[property]; - }); - } - } - expect(result[0]).deep.equal(result[1]); - } - return done(); - }); - }); -} + mainCollection = require('../../../../test/codegen/newman/fixtures/testCollection.json'); describe('nodejs-native convert function', function () { - mainCollection.item.forEach(function (item) { + mainCollection.item.forEach(function (item, index) { it(item.name, function (done) { - var request = new sdk.Request(item.request), - collection = { - item: [ - { - request: request.toJSON() - } - ] - }; + var request = new sdk.Request(item.request); + convert(request, {indentCount: 2, indentType: 'Space'}, function (error, snippet) { if (error) { expect.fail(null, null, error); @@ -137,7 +17,18 @@ describe('nodejs-native convert function', function () { // disabling eslint for test file snippet = '/* eslint-disable */\n' + snippet; - runSnippet(snippet, collection, done); + runSnippet(snippet, index, + {compileScript: null, runScript: 'node run.js', fileName: 'run.js'}, function (err, result) { + if (err) { + expect.fail(null, null, err); + } + if (typeof result[1] !== 'object' || typeof result[0] !== 'object') { + expect(result[1].toString().trim()).to.include(result[0].toString().trim()); + } + + expect(result[0]).deep.equal(result[1]); + return done(); + }); }); }); }); diff --git a/npm/test.sh b/npm/test.sh index f66c6be3b..7f9188517 100755 --- a/npm/test.sh +++ b/npm/test.sh @@ -12,6 +12,8 @@ else exit 1; fi popd &>/dev/null +echo "Running newman for common collection and storing results in newmanResponses.json" + # node ./test/codegen/newman/runNewman.js if [ -n "$1" ] then @@ -30,7 +32,7 @@ then else echo "Running common repository tests" # check whether all dependencies used are present in package.json, and vice versa. - dependency-check ./package.json --no-dev --missing + # dependency-check ./package.json --no-dev --missing # check for .gitignore, license.md, readme.md, .eslintrc and package.json mocha ./test/system/repository.test.js; diff --git a/test/codegen/newman/fixtures/testCollection.json b/test/codegen/newman/fixtures/testCollection.json new file mode 100644 index 000000000..676834d3a --- /dev/null +++ b/test/codegen/newman/fixtures/testCollection.json @@ -0,0 +1,1428 @@ +{ + "info": { + "name": "Code-Gen Test Cases", + "_postman_id": "41182fad-912e-6bc9-d6b9-dfb6f5bf5ffb", + "description": "This collection contains requests that will be used to test validity of plugin created to convert postman request into code snippet of particular language.", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + }, + "item": [ + { + "name": "Request Headers with disabled headers", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "var responseJSON;", + "try {", + " tests[\"Body contains headers\"] = responseBody.has(\"headers\");", + " responseJSON = JSON.parse(responseBody);", + " tests[\"Header contains host\"] = \"host\" in responseJSON.headers;", + " tests[\"Header contains test parameter sent as part of request header\"] = \"my-sample-header\" in responseJSON.headers;", + "}", + "catch (e) { }", + "", + "", + "", + "" + ] + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "my-sample-header", + "value": "Lorem ipsum dolor sit amet" + }, + { + "key": "not-disabled-header", + "value": "ENABLED" + }, + { + "key": "disabled header", + "value": "DISABLED", + "disabled": true + } + ], + "body": {}, + "url": { + "raw": "https://postman-echo.com/headers", + "protocol": "https", + "host": [ + "postman-echo", + "com" + ], + "path": [ + "headers" + ] + }, + "description": "A `GET` request to this endpoint returns the list of all request headers as part of the response JSON.\nIn Postman, sending your own set of headers through the [Headers tab](https://www.getpostman.com/docs/requests#headers?source=echo-collection-app-onboarding) will reveal the headers as part of the response." + }, + "response": [] + }, + { + "name": "GET Request with disabled query", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "var responseJSON;", + "", + "try { ", + " responseJSON = JSON.parse(responseBody); ", + " tests['response is valid JSON'] = true;", + "}", + "catch (e) { ", + " responseJSON = {}; ", + " tests['response is valid JSON'] = false;", + "}", + "", + "tests['response json contains headers'] = _.has(responseJSON, 'headers');", + "tests['response json contains args'] = _.has(responseJSON, 'args');", + "tests['response json contains url'] = _.has(responseJSON, 'url');", + "", + "tests['args key contains argument passed as url parameter'] = ('test' in responseJSON.args);", + "tests['args passed via request url params has value \"123\"'] = (_.get(responseJSON, 'args.test') === \"123\");" + ] + } + } + ], + "request": { + "method": "GET", + "header": [], + "body": {}, + "url": { + "raw": "https://postman-echo.com/get?test=123&anotherone=232", + "protocol": "https", + "host": [ + "postman-echo", + "com" + ], + "path": [ + "get" + ], + "query": [ + { + "key": "test", + "value": "123", + "equals": true + }, + { + "key": "anotherone", + "value": "232", + "equals": true + }, + { + "key": "anotheroneone", + "value": "sdfsdf", + "equals": true, + "disabled": true + } + ] + }, + "description": "The HTTP `GET` request method is meant to retrieve data from a server. The data\nis identified by a unique URI (Uniform Resource Identifier). \n\nA `GET` request can pass parameters to the server using \"Query String \nParameters\". For example, in the following request,\n\n> http://example.com/hi/there?hand=wave\n\nThe parameter \"hand\" has the value \"wave\".\n\nThis endpoint echoes the HTTP headers, request parameters and the complete\nURI requested." + }, + "response": [] + }, + { + "name": "POST Raw Text", + "event": [ + { + "listen": "test", + "script": { + "id": "753f8a33-adb6-402f-8d19-386c1981ecb6", + "type": "text/javascript", + "exec": [ + "var responseJSON;", + "", + "try { ", + " responseJSON = JSON.parse(responseBody); ", + " tests['response is valid JSON'] = true;", + "}", + "catch (e) { ", + " responseJSON = {}; ", + " tests['response is valid JSON'] = false;", + "}", + "", + "", + "tests['response has post data'] = _.has(responseJSON, 'data');", + "tests['response matches the data posted'] = (responseJSON.data && responseJSON.data.length === 256);", + "", + "tests[\"content-type equals text/plain\"] = responseJSON && responseJSON.headers && (responseJSON.headers[\"content-type\"] === 'text/plain');" + ] + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "text/plain" + } + ], + "body": { + "mode": "raw", + "raw": "\"'Duis posuere augue vel cursus pharetra. In luctus a ex nec pretium. Praesent neque quam, tincidunt nec leo eget, rutrum vehicula magna.\nMaecenas consequat elementum elit, \"id\" \"se\\\"mper\" sem tristique et. Integer pulvinar enim quis consectetur interdum volutpat.'\"" + }, + "url": { + "raw": "https://postman-echo.com/post", + "protocol": "https", + "host": [ + "postman-echo", + "com" + ], + "path": [ + "post" + ] + }, + "description": "The HTTP `POST` request method is meant to transfer data to a server \n(and elicit a response). What data is returned depends on the implementation\nof the server.\n\nA `POST` request can pass parameters to the server using \"Query String \nParameters\", as well as the Request Body. For example, in the following request,\n\n> POST /hi/there?hand=wave\n>\n> \n\nThe parameter \"hand\" has the value \"wave\". The request body can be in multiple\nformats. These formats are defined by the MIME type of the request. The MIME \nType can be set using the ``Content-Type`` HTTP header. The most commonly used \nMIME types are:\n\n* `multipart/form-data`\n* `application/x-www-form-urlencoded`\n* `application/json`\n\nThis endpoint echoes the HTTP headers, request parameters, the contents of\nthe request body and the complete URI requested." + }, + "response": [] + }, + { + "name": "POST form data with file", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "var responseJSON;", + "", + "try { ", + " responseJSON = JSON.parse(responseBody); ", + " tests['response is valid JSON'] = true;", + "}", + "catch (e) { ", + " responseJSON = {}; ", + " tests['response is valid JSON'] = false;", + "}", + "", + "", + "tests['response has post data'] = _.has(responseJSON, 'data');", + "tests['response matches the data posted'] = (responseJSON.data && responseJSON.data.length === 256);", + "", + "tests[\"content-type equals text/plain\"] = responseJSON && responseJSON.headers && (responseJSON.headers[\"content-type\"] === 'text/plain');" + ] + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/x-www-form-urlencoded", + "disabled": true + }, + { + "key": "content-type", + "value": "application/json", + "disabled": true + } + ], + "body": { + "mode": "formdata", + "formdata": [ + { + "key": "fdjks", + "value": "dsf", + "type": "text" + }, + { + "key": "&^%", + "value": "helo", + "type": "text" + }, + { + "key": "12", + "value": "\"23\"", + "description": "", + "type": "text" + }, + { + "key": "'123'", + "value": "'\"23\\\"4\\\"\"'", + "description": "", + "type": "text" + }, + { + "key": "", + "value": "", + "description": "", + "type": "text", + "disabled": true + } + ] + }, + "url": { + "raw": "https://postman-echo.com/post", + "protocol": "https", + "host": [ + "postman-echo", + "com" + ], + "path": [ + "post" + ] + }, + "description": "The HTTP `POST` request method is meant to transfer data to a server \n(and elicit a response). What data is returned depends on the implementation\nof the server.\n\nA `POST` request can pass parameters to the server using \"Query String \nParameters\", as well as the Request Body. For example, in the following request,\n\n> POST /hi/there?hand=wave\n>\n> \n\nThe parameter \"hand\" has the value \"wave\". The request body can be in multiple\nformats. These formats are defined by the MIME type of the request. The MIME \nType can be set using the ``Content-Type`` HTTP header. The most commonly used \nMIME types are:\n\n* `multipart/form-data`\n* `application/x-www-form-urlencoded`\n* `application/json`\n\nThis endpoint echoes the HTTP headers, request parameters, the contents of\nthe request body and the complete URI requested." + }, + "response": [] + }, + { + "name": "POST urlencoded data with disabled entries", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "var responseJSON;", + "", + "try { ", + " responseJSON = JSON.parse(responseBody); ", + " tests['response is valid JSON'] = true;", + "}", + "catch (e) { ", + " responseJSON = {}; ", + " tests['response is valid JSON'] = false;", + "}", + "", + "", + "tests['response has post data'] = _.has(responseJSON, 'data');", + "tests['response matches the data posted'] = (responseJSON.data && responseJSON.data.length === 256);", + "", + "tests[\"content-type equals text/plain\"] = responseJSON && responseJSON.headers && (responseJSON.headers[\"content-type\"] === 'text/plain');" + ] + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/x-www-form-urlencoded" + } + ], + "body": { + "mode": "urlencoded", + "urlencoded": [ + { + "key": "1", + "value": "a", + "description": "", + "type": "text" + }, + { + "key": "2", + "value": "b", + "description": "", + "type": "text" + }, + { + "key": "\"\"12\"\"", + "value": "\"23\"", + "description": "", + "type": "text" + }, + { + "key": "'1\"2\\\"\"3'", + "value": "'1\"23\"4'", + "description": "", + "type": "text" + } + ] + }, + "url": { + "raw": "https://postman-echo.com/post/?hardik=\"me\"", + "protocol": "https", + "host": [ + "postman-echo", + "com" + ], + "path": [ + "post", + "" + ], + "query": [ + { + "key": "hardik", + "value": "\"me\"", + "equals": true + } + ] + }, + "description": "The HTTP `POST` request method is meant to transfer data to a server \n(and elicit a response). What data is returned depends on the implementation\nof the server.\n\nA `POST` request can pass parameters to the server using \"Query String \nParameters\", as well as the Request Body. For example, in the following request,\n\n> POST /hi/there?hand=wave\n>\n> \n\nThe parameter \"hand\" has the value \"wave\". The request body can be in multiple\nformats. These formats are defined by the MIME type of the request. The MIME \nType can be set using the ``Content-Type`` HTTP header. The most commonly used \nMIME types are:\n\n* `multipart/form-data`\n* `application/x-www-form-urlencoded`\n* `application/json`\n\nThis endpoint echoes the HTTP headers, request parameters, the contents of\nthe request body and the complete URI requested." + }, + "response": [] + }, + { + "name": "POST json with raw", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "var responseJSON;", + "", + "try { ", + " responseJSON = JSON.parse(responseBody); ", + " tests['response is valid JSON'] = true;", + "}", + "catch (e) { ", + " responseJSON = {}; ", + " tests['response is valid JSON'] = false;", + "}", + "", + "", + "tests['response has post data'] = _.has(responseJSON, 'data');", + "tests['response matches the data posted'] = (responseJSON.data && responseJSON.data.length === 256);", + "", + "tests[\"content-type equals text/plain\"] = responseJSON && responseJSON.headers && (responseJSON.headers[\"content-type\"] === 'text/plain');" + ] + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"json\": \"Test-Test\"\n}" + }, + "url": { + "raw": "https://postman-echo.com/post", + "protocol": "https", + "host": [ + "postman-echo", + "com" + ], + "path": [ + "post" + ] + }, + "description": "The HTTP `POST` request method is meant to transfer data to a server \n(and elicit a response). What data is returned depends on the implementation\nof the server.\n\nA `POST` request can pass parameters to the server using \"Query String \nParameters\", as well as the Request Body. For example, in the following request,\n\n> POST /hi/there?hand=wave\n>\n> \n\nThe parameter \"hand\" has the value \"wave\". The request body can be in multiple\nformats. These formats are defined by the MIME type of the request. The MIME \nType can be set using the ``Content-Type`` HTTP header. The most commonly used \nMIME types are:\n\n* `multipart/form-data`\n* `application/x-www-form-urlencoded`\n* `application/json`\n\nThis endpoint echoes the HTTP headers, request parameters, the contents of\nthe request body and the complete URI requested." + }, + "response": [ + { + "id": "db02f994-5ac4-41e1-835a-f49a14acbb6e", + "name": "POST json with raw", + "originalRequest": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"json\": \"Test-Test\"\n}" + }, + "url": { + "raw": "https://postman-echo.com/post", + "protocol": "https", + "host": [ + "postman-echo", + "com" + ], + "path": [ + "post" + ] + } + }, + "status": "OK", + "code": 200, + "_postman_previewlanguage": "json", + "header": [ + { + "key": "Access-Control-Allow-Credentials", + "value": "", + "name": "Access-Control-Allow-Credentials", + "description": "Indicates whether or not the response to the request can be exposed when the credentials flag is true. When used as part of a response to a preflight request, this indicates whether or not the actual request can be made using credentials." + }, + { + "key": "Access-Control-Allow-Headers", + "value": "", + "name": "Access-Control-Allow-Headers", + "description": "Used in response to a preflight request to indicate which HTTP headers can be used when making the actual request." + }, + { + "key": "Access-Control-Allow-Methods", + "value": "", + "name": "Access-Control-Allow-Methods", + "description": "Specifies the method or methods allowed when accessing the resource. This is used in response to a preflight request." + }, + { + "key": "Access-Control-Allow-Origin", + "value": "", + "name": "Access-Control-Allow-Origin", + "description": "Specifies a URI that may access the resource. For requests without credentials, the server may specify '*' as a wildcard, thereby allowing any origin to access the resource." + }, + { + "key": "Access-Control-Expose-Headers", + "value": "", + "name": "Access-Control-Expose-Headers", + "description": "Lets a server whitelist headers that browsers are allowed to access." + }, + { + "key": "Connection", + "value": "keep-alive", + "name": "Connection", + "description": "Options that are desired for the connection" + }, + { + "key": "Content-Encoding", + "value": "gzip", + "name": "Content-Encoding", + "description": "The type of encoding used on the data." + }, + { + "key": "Content-Length", + "value": "385", + "name": "Content-Length", + "description": "The length of the response body in octets (8-bit bytes)" + }, + { + "key": "Content-Type", + "value": "application/json; charset=utf-8", + "name": "Content-Type", + "description": "The mime type of this content" + }, + { + "key": "Date", + "value": "Wed, 07 Feb 2018 10:06:15 GMT", + "name": "Date", + "description": "The date and time that the message was sent" + }, + { + "key": "ETag", + "value": "W/\"215-u7EU1nFtauIn0/aVifjuXA\"", + "name": "ETag", + "description": "An identifier for a specific version of a resource, often a message digest" + }, + { + "key": "Server", + "value": "nginx", + "name": "Server", + "description": "A name for the server" + }, + { + "key": "Vary", + "value": "X-HTTP-Method-Override, Accept-Encoding", + "name": "Vary", + "description": "Tells downstream proxies how to match future request headers to decide whether the cached response can be used rather than requesting a fresh one from the origin server." + }, + { + "key": "set-cookie", + "value": "sails.sid=s%3AxRBxgrc9M-jKK_l1mX3y3rM_ry8wYLz4.Of4qpOzd9hi6uO0sAQIj%2Bxs2VeppWxYjJa4OpIW3PKg; Path=/; HttpOnly", + "name": "set-cookie", + "description": "an HTTP cookie" + } + ], + "cookie": [ + { + "expires": "Tue Jan 19 2038 08:44:07 GMT+0530 (IST)", + "httpOnly": true, + "domain": "postman-echo.com", + "path": "/", + "secure": false, + "value": "s%3AxRBxgrc9M-jKK_l1mX3y3rM_ry8wYLz4.Of4qpOzd9hi6uO0sAQIj%2Bxs2VeppWxYjJa4OpIW3PKg", + "key": "sails.sid" + } + ], + "body": "{\"args\":{},\"data\":\"{\\n \\\"json\\\": \\\"Test-Test\\\"\\n}\",\"files\":{},\"form\":{},\"headers\":{\"host\":\"postman-echo.com\",\"content-length\":\"25\",\"accept\":\"*/*\",\"accept-encoding\":\"gzip, deflate\",\"cache-control\":\"no-cache\",\"content-type\":\"text/plain\",\"cookie\":\"sails.sid=s%3AkOgtF1XmXtVFx-Eg3S7-37BKKaMqMDPe.hnwldNwyvsaASUiRR0Y0vcowadkMXO4HMegTeVIPgqo\",\"postman-token\":\"2ced782f-a141-428e-8af6-04ce954a77d5\",\"user-agent\":\"PostmanRuntime/7.1.1\",\"x-forwarded-port\":\"443\",\"x-forwarded-proto\":\"https\"},\"json\":null,\"url\":\"https://postman-echo.com/post\"}" + } + ] + }, + { + "name": "POST javascript with raw", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "var responseJSON;", + "", + "try { ", + " responseJSON = JSON.parse(responseBody); ", + " tests['response is valid JSON'] = true;", + "}", + "catch (e) { ", + " responseJSON = {}; ", + " tests['response is valid JSON'] = false;", + "}", + "", + "", + "tests['response has post data'] = _.has(responseJSON, 'data');", + "tests['response matches the data posted'] = (responseJSON.data && responseJSON.data.length === 256);", + "", + "tests[\"content-type equals text/plain\"] = responseJSON && responseJSON.headers && (responseJSON.headers[\"content-type\"] === 'text/plain');" + ] + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/javascript" + } + ], + "body": { + "mode": "raw", + "raw": "var val = 6;\nconsole.log(val);" + }, + "url": { + "raw": "https://postman-echo.com/post", + "protocol": "https", + "host": [ + "postman-echo", + "com" + ], + "path": [ + "post" + ] + }, + "description": "The HTTP `POST` request method is meant to transfer data to a server \n(and elicit a response). What data is returned depends on the implementation\nof the server.\n\nA `POST` request can pass parameters to the server using \"Query String \nParameters\", as well as the Request Body. For example, in the following request,\n\n> POST /hi/there?hand=wave\n>\n> \n\nThe parameter \"hand\" has the value \"wave\". The request body can be in multiple\nformats. These formats are defined by the MIME type of the request. The MIME \nType can be set using the ``Content-Type`` HTTP header. The most commonly used \nMIME types are:\n\n* `multipart/form-data`\n* `application/x-www-form-urlencoded`\n* `application/json`\n\nThis endpoint echoes the HTTP headers, request parameters, the contents of\nthe request body and the complete URI requested." + }, + "response": [] + }, + { + "name": "POST text/xml with raw", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "var responseJSON;", + "", + "try { ", + " responseJSON = JSON.parse(responseBody); ", + " tests['response is valid JSON'] = true;", + "}", + "catch (e) { ", + " responseJSON = {}; ", + " tests['response is valid JSON'] = false;", + "}", + "", + "", + "tests['response has post data'] = _.has(responseJSON, 'data');", + "tests['response matches the data posted'] = (responseJSON.data && responseJSON.data.length === 256);", + "", + "tests[\"content-type equals text/plain\"] = responseJSON && responseJSON.headers && (responseJSON.headers[\"content-type\"] === 'text/plain');" + ] + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "text/xml" + } + ], + "body": { + "mode": "raw", + "raw": "\n Test Test\n" + }, + "url": { + "raw": "https://postman-echo.com/post", + "protocol": "https", + "host": [ + "postman-echo", + "com" + ], + "path": [ + "post" + ] + }, + "description": "The HTTP `POST` request method is meant to transfer data to a server \n(and elicit a response). What data is returned depends on the implementation\nof the server.\n\nA `POST` request can pass parameters to the server using \"Query String \nParameters\", as well as the Request Body. For example, in the following request,\n\n> POST /hi/there?hand=wave\n>\n> \n\nThe parameter \"hand\" has the value \"wave\". The request body can be in multiple\nformats. These formats are defined by the MIME type of the request. The MIME \nType can be set using the ``Content-Type`` HTTP header. The most commonly used \nMIME types are:\n\n* `multipart/form-data`\n* `application/x-www-form-urlencoded`\n* `application/json`\n\nThis endpoint echoes the HTTP headers, request parameters, the contents of\nthe request body and the complete URI requested." + }, + "response": [] + }, + { + "name": "POST text/html with raw", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "var responseJSON;", + "", + "try { ", + " responseJSON = JSON.parse(responseBody); ", + " tests['response is valid JSON'] = true;", + "}", + "catch (e) { ", + " responseJSON = {}; ", + " tests['response is valid JSON'] = false;", + "}", + "", + "", + "tests['response has post data'] = _.has(responseJSON, 'data');", + "tests['response matches the data posted'] = (responseJSON.data && responseJSON.data.length === 256);", + "", + "tests[\"content-type equals text/plain\"] = responseJSON && responseJSON.headers && (responseJSON.headers[\"content-type\"] === 'text/plain');" + ] + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "text/html" + } + ], + "body": { + "mode": "raw", + "raw": "\n Test Test\n" + }, + "url": { + "raw": "https://postman-echo.com/post", + "protocol": "https", + "host": [ + "postman-echo", + "com" + ], + "path": [ + "post" + ] + }, + "description": "The HTTP `POST` request method is meant to transfer data to a server \n(and elicit a response). What data is returned depends on the implementation\nof the server.\n\nA `POST` request can pass parameters to the server using \"Query String \nParameters\", as well as the Request Body. For example, in the following request,\n\n> POST /hi/there?hand=wave\n>\n> \n\nThe parameter \"hand\" has the value \"wave\". The request body can be in multiple\nformats. These formats are defined by the MIME type of the request. The MIME \nType can be set using the ``Content-Type`` HTTP header. The most commonly used \nMIME types are:\n\n* `multipart/form-data`\n* `application/x-www-form-urlencoded`\n* `application/json`\n\nThis endpoint echoes the HTTP headers, request parameters, the contents of\nthe request body and the complete URI requested." + }, + "response": [] + }, + { + "name": "Resolve URL", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/x-www-form-urlencoded" + } + ], + "body": { + "mode": "raw", + "raw": "Duis posuere augue vel cursus pharetra. In luctus a ex nec pretium. Praesent neque quam, tincidunt nec leo eget, rutrum vehicula magna.\nMaecenas consequat elementum elit, id semper sem tristique et. Integer pulvinar enim quis consectetur interdum volutpat." + }, + "url": { + "raw": "https://postman-echo.com/:action", + "protocol": "https", + "host": [ + "postman-echo", + "com" + ], + "path": [ + ":action" + ], + "variable": [ + { + "key": "action", + "value": "post" + } + ] + }, + "description": null + }, + "response": [] + }, + { + "name": "PUT Request", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "var responseJSON;", + "", + "try { ", + " responseJSON = JSON.parse(responseBody); ", + " tests['response is valid JSON'] = true;", + "}", + "catch (e) { ", + " responseJSON = {}; ", + " tests['response is valid JSON'] = false;", + "}", + "", + "", + "tests['response has PUT data'] = _.has(responseJSON, 'data');", + "tests['response matches the data sent in request'] = (responseJSON.data && responseJSON.data.length === 256);" + ] + } + } + ], + "request": { + "method": "PUT", + "header": [ + { + "key": "Content-Type", + "value": "text/plain" + } + ], + "body": { + "mode": "raw", + "raw": "Etiam mi lacus, cursus vitae felis et, blandit pellentesque neque. Vestibulum eget nisi a tortor commodo dignissim.\nQuisque ipsum ligula, faucibus a felis a, commodo elementum nisl. Mauris vulputate sapien et tincidunt viverra. Donec vitae velit nec metus." + }, + "url": { + "raw": "https://postman-echo.com/put", + "protocol": "https", + "host": [ + "postman-echo", + "com" + ], + "path": [ + "put" + ] + }, + "description": "The HTTP `PUT` request method is similar to HTTP `POST`. It too is meant to \ntransfer data to a server (and elicit a response). What data is returned depends on the implementation\nof the server.\n\nA `PUT` request can pass parameters to the server using \"Query String \nParameters\", as well as the Request Body. For example, in the following \nraw HTTP request,\n\n> PUT /hi/there?hand=wave\n>\n> \n\n\n" + }, + "response": [] + }, + { + "name": "PATCH Request", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "var responseJSON;", + "", + "try { ", + " responseJSON = JSON.parse(responseBody); ", + " tests['response is valid JSON'] = true;", + "}", + "catch (e) { ", + " responseJSON = {}; ", + " tests['response is valid JSON'] = false;", + "}", + "", + "", + "tests['response has PUT data'] = _.has(responseJSON, 'data');", + "tests['response matches the data sent in request'] = (responseJSON.data && responseJSON.data.length === 256);" + ] + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "Content-Type", + "value": "text/plain" + } + ], + "body": { + "mode": "raw", + "raw": "Curabitur auctor, elit nec pulvinar porttitor, ex augue condimentum enim, eget suscipit urna felis quis neque.\nSuspendisse sit amet luctus massa, nec venenatis mi. Suspendisse tincidunt massa at nibh efficitur fringilla. Nam quis congue mi. Etiam volutpat." + }, + "url": { + "raw": "https://postman-echo.com/patch", + "protocol": "https", + "host": [ + "postman-echo", + "com" + ], + "path": [ + "patch" + ] + }, + "description": "The HTTP `PATCH` method is used to update resources on a server. The exact\nuse of `PATCH` requests depends on the server in question. There are a number\nof server implementations which handle `PATCH` differently. Technically, \n`PATCH` supports both Query String parameters and a Request Body.\n\nThis endpoint accepts an HTTP `PATCH` request and provides debug information\nsuch as the HTTP headers, Query String arguments, and the Request Body." + }, + "response": [] + }, + { + "name": "DELETE Request", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "var responseJSON;", + "", + "try { ", + " responseJSON = JSON.parse(responseBody); ", + " tests['response is valid JSON'] = true;", + "}", + "catch (e) { ", + " responseJSON = {}; ", + " tests['response is valid JSON'] = false;", + "}", + "", + "", + "tests['response has PUT data'] = _.has(responseJSON, 'data');", + "tests['response matches the data sent in request'] = (responseJSON.data && responseJSON.data.length === 256);" + ] + } + } + ], + "request": { + "method": "DELETE", + "header": [ + { + "key": "Content-Type", + "value": "application/x-www-form-urlencoded" + }, + { + "key": "Content-Length", + "value": "1000", + "disabled": true + } + ], + "body": { + "mode": "urlencoded", + "urlencoded": [ + { + "key": "dsfs", + "value": "sfdds", + "description": "", + "type": "text" + }, + { + "key": "sfdsdf", + "value": "sdf", + "description": "", + "type": "text" + } + ] + }, + "url": { + "raw": "https://postman-echo.com/delete", + "protocol": "https", + "host": [ + "postman-echo", + "com" + ], + "path": [ + "delete" + ] + }, + "description": "The HTTP `DELETE` method is used to delete resources on a server. The exact\nuse of `DELETE` requests depends on the server implementation. In general, \n`DELETE` requests support both, Query String parameters as well as a Request \nBody.\n\nThis endpoint accepts an HTTP `DELETE` request and provides debug information\nsuch as the HTTP headers, Query String arguments, and the Request Body." + }, + "response": [] + }, + { + "name": "OPTIONS to postman echo", + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "var responseJSON;", + "", + "try { ", + " responseJSON = JSON.parse(responseBody); ", + " tests['response is valid JSON'] = true;", + "}", + "catch (e) { ", + " responseJSON = {}; ", + " tests['response is valid JSON'] = false;", + "}", + "", + "", + "tests['response has post data'] = _.has(responseJSON, 'data');", + "tests['response matches the data posted'] = (responseJSON.data && responseJSON.data.length === 256);", + "", + "tests[\"content-type equals text/plain\"] = responseJSON && responseJSON.headers && (responseJSON.headers[\"content-type\"] === 'text/plain');" + ] + } + } + ], + "request": { + "method": "OPTIONS", + "header": [ + { + "key": "Content-Type", + "value": "application/x-www-form-urlencoded" + } + ], + "body": {}, + "url": { + "raw": "https://postman-echo.com/post", + "protocol": "https", + "host": [ + "postman-echo", + "com" + ], + "path": [ + "post" + ] + }, + "description": "The HTTP `POST` request method is meant to transfer data to a server \n(and elicit a response). What data is returned depends on the implementation\nof the server.\n\nA `POST` request can pass parameters to the server using \"Query String \nParameters\", as well as the Request Body. For example, in the following request,\n\n> POST /hi/there?hand=wave\n>\n> \n\nThe parameter \"hand\" has the value \"wave\". The request body can be in multiple\nformats. These formats are defined by the MIME type of the request. The MIME \nType can be set using the ``Content-Type`` HTTP header. The most commonly used \nMIME types are:\n\n* `multipart/form-data`\n* `application/x-www-form-urlencoded`\n* `application/json`\n\nThis endpoint echoes the HTTP headers, request parameters, the contents of\nthe request body and the complete URI requested." + }, + "response": [] + }, + { + "name": "HEAD request", + "request": { + "method": "HEAD", + "header": [ + { + "key": "hello", + "value": "helloagain", + "disabled": true + } + ], + "body": {}, + "url": { + "raw": "https://www.postman-echo.com/head", + "protocol": "https", + "host": [ + "www", + "postman-echo", + "com" + ], + "path": [ + "head" + ] + }, + "description": null + }, + "response": [] + }, + { + "name": "LINK request", + "request": { + "method": "LINK", + "header": [ + { + "key": "Content-Type", + "value": "text/plain" + } + ], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "https://mockbin.org/request", + "protocol": "https", + "host": [ + "mockbin", + "org" + ], + "path": [ + "request" + ] + }, + "description": "" + }, + "response": [] + }, + { + "name": "UNLINK request", + "request": { + "method": "UNLINK", + "header": [ + { + "key": "Content-Type", + "value": "text/plain" + } + ], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "https://mockbin.org/request", + "protocol": "https", + "host": [ + "mockbin", + "org" + ], + "path": [ + "request" + ] + }, + "description": "" + }, + "response": [] + }, + { + "name": "LOCK request", + "request": { + "method": "LOCK", + "header": [ + { + "key": "Content-Type", + "value": "text/plain" + } + ], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "https://mockbin.org/request", + "protocol": "https", + "host": [ + "mockbin", + "org" + ], + "path": [ + "request" + ] + }, + "description": "" + }, + "response": [] + }, + { + "name": "UNLOCK request", + "request": { + "method": "UNLOCK", + "header": [], + "body": {}, + "url": { + "raw": "https://mockbin.org/request", + "protocol": "https", + "host": [ + "mockbin", + "org" + ], + "path": [ + "request" + ] + }, + "description": "" + }, + "response": [] + }, + { + "name": "PROFIND request", + "request": { + "method": "PROPFIND", + "header": [ + { + "key": "Content-Type", + "value": "text/plain" + } + ], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "https://mockbin.org/request", + "protocol": "https", + "host": [ + "mockbin", + "org" + ], + "path": [ + "request" + ] + }, + "description": "" + }, + "response": [] + }, + { + "name": "PURGE Request", + "request": { + "method": "PURGE", + "header": [], + "body": {}, + "url": { + "raw": "https://9c76407d-5b8d-4b22-99fb-8c47a85d9848.mock.pstmn.io", + "protocol": "https", + "host": [ + "9c76407d-5b8d-4b22-99fb-8c47a85d9848", + "mock", + "pstmn", + "io" + ] + }, + "description": null + }, + "response": [ + { + "id": "c0d81a4f-46ee-4ce4-a602-37b7d55b9983", + "name": "PURGE Request", + "originalRequest": { + "method": "PURGE", + "header": [], + "body": {}, + "url": { + "raw": "https://9c76407d-5b8d-4b22-99fb-8c47a85d9848.mock.pstmn.io", + "protocol": "https", + "host": [ + "9c76407d-5b8d-4b22-99fb-8c47a85d9848", + "mock", + "pstmn", + "io" + ] + } + }, + "status": "Not Found", + "code": 404, + "_postman_previewlanguage": "text", + "header": [ + { + "key": "Access-Control-Allow-Credentials", + "value": "", + "name": "Access-Control-Allow-Credentials", + "description": "" + }, + { + "key": "Access-Control-Allow-Headers", + "value": "", + "name": "Access-Control-Allow-Headers", + "description": "" + }, + { + "key": "Access-Control-Allow-Methods", + "value": "", + "name": "Access-Control-Allow-Methods", + "description": "" + }, + { + "key": "Access-Control-Allow-Origin", + "value": "*", + "name": "Access-Control-Allow-Origin", + "description": "" + }, + { + "key": "Access-Control-Expose-Headers", + "value": "", + "name": "Access-Control-Expose-Headers", + "description": "" + }, + { + "key": "Connection", + "value": "keep-alive", + "name": "Connection", + "description": "" + }, + { + "key": "Content-Encoding", + "value": "gzip", + "name": "Content-Encoding", + "description": "" + }, + { + "key": "Content-Length", + "value": "152", + "name": "Content-Length", + "description": "" + }, + { + "key": "Content-Type", + "value": "application/json; charset=utf-8", + "name": "Content-Type", + "description": "" + }, + { + "key": "Date", + "value": "Tue, 13 Feb 2018 13:58:56 GMT", + "name": "Date", + "description": "" + }, + { + "key": "ETag", + "value": "W/\"a7-kIxN5L9H0YwilUQPUUio9A\"", + "name": "ETag", + "description": "" + }, + { + "key": "Server", + "value": "nginx", + "name": "Server", + "description": "" + }, + { + "key": "Vary", + "value": "Accept-Encoding", + "name": "Vary", + "description": "" + } + ], + "cookie": [], + "responseTime": "375", + "body": "{\n \"args\": {},\n \"data\": \"Curabitur auctor, elit nec pulvinar porttitor, ex augue condimentum enim, eget suscipit urna felis quis neque.\\nSuspendisse sit amet luctus massa, nec venenatis mi. Suspendisse tincidunt massa at nibh efficitur fringilla. Nam quis congue mi. Etiam volutpat.\",\n \"files\": {},\n \"form\": {},\n \"headers\": {\n \"host\": \"postman-echo.com\",\n \"content-length\": \"256\",\n \"accept\": \"*/*\",\n \"accept-encoding\": \"gzip, deflate\",\n \"content-type\": \"text/plain\",\n \"cookie\": \"sails.sid=s%3A1wOi4AdoZEbqBjGi6oSUC5Vlfje8wJvs.DHQfRLXfIBvZ%2Bv0KhLAThMDz%2FXvxh9gyxWYa0u1EZOU\",\n \"user-agent\": \"PostmanRuntime/7.1.1\",\n \"x-forwarded-port\": \"443\",\n \"x-forwarded-proto\": \"https\"\n },\n \"json\": null,\n \"url\": \"https://9c76407d-5b8d-4b22-99fb-8c47a85d9848.mock.pstmn.io\"\n}" + } + ] + }, + { + "name": "COPY Request", + "request": { + "method": "COPY", + "header": [], + "body": {}, + "url": { + "raw": "https://mockbin.org/request", + "protocol": "https", + "host": [ + "mockbin", + "org" + ], + "path": [ + "request" + ] + }, + "description": null + }, + "response": [ + { + "id": "6367d22f-0cf7-48f2-a41d-5b9ed11cbff5", + "name": "COPY Request", + "originalRequest": { + "method": "COPY", + "header": [], + "body": {}, + "url": { + "raw": "https://mockbin.org/request", + "protocol": "https", + "host": [ + "mockbin", + "org" + ], + "path": [ + "request" + ] + } + }, + "status": "OK", + "code": 200, + "_postman_previewlanguage": "json", + "header": [ + { + "key": "Access-Control-Allow-Credentials", + "value": "true", + "name": "Access-Control-Allow-Credentials", + "description": "Indicates whether or not the response to the request can be exposed when the credentials flag is true. When used as part of a response to a preflight request, this indicates whether or not the actual request can be made using credentials." + }, + { + "key": "Access-Control-Allow-Headers", + "value": "host,connection,accept-encoding,x-forwarded-for,cf-ray,x-forwarded-proto,cf-visitor,cache-control,postman-token,user-agent,accept,cookie,cf-connecting-ip,x-request-id,x-forwarded-port,via,connect-time,x-request-start,total-route-time,content-length", + "name": "Access-Control-Allow-Headers", + "description": "Used in response to a preflight request to indicate which HTTP headers can be used when making the actual request." + }, + { + "key": "Access-Control-Allow-Methods", + "value": "COPY", + "name": "Access-Control-Allow-Methods", + "description": "Specifies the method or methods allowed when accessing the resource. This is used in response to a preflight request." + }, + { + "key": "Access-Control-Allow-Origin", + "value": "*", + "name": "Access-Control-Allow-Origin", + "description": "Specifies a URI that may access the resource. For requests without credentials, the server may specify '*' as a wildcard, thereby allowing any origin to access the resource." + }, + { + "key": "CF-RAY", + "value": "3fb595d5facaa302-HKG", + "name": "CF-RAY", + "description": "Custom header" + }, + { + "key": "Connection", + "value": "keep-alive", + "name": "Connection", + "description": "Options that are desired for the connection" + }, + { + "key": "Content-Encoding", + "value": "gzip", + "name": "Content-Encoding", + "description": "The type of encoding used on the data." + }, + { + "key": "Content-Type", + "value": "application/json; charset=utf-8", + "name": "Content-Type", + "description": "The mime type of this content" + }, + { + "key": "Date", + "value": "Wed, 14 Mar 2018 09:06:37 GMT", + "name": "Date", + "description": "The date and time that the message was sent" + }, + { + "key": "Etag", + "value": "W/\"4ac-YP9NIoQ5TiGJRPuQSZMKtA\"", + "name": "Etag", + "description": "An identifier for a specific version of a resource, often a message digest" + }, + { + "key": "Expect-CT", + "value": "max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\"", + "name": "Expect-CT", + "description": "Custom header" + }, + { + "key": "Server", + "value": "cloudflare", + "name": "Server", + "description": "A name for the server" + }, + { + "key": "Transfer-Encoding", + "value": "chunked", + "name": "Transfer-Encoding", + "description": "The form of encoding used to safely transfer the entity to the user. Currently defined methods are: chunked, compress, deflate, gzip, identity." + }, + { + "key": "Vary", + "value": "Accept, Accept-Encoding", + "name": "Vary", + "description": "Tells downstream proxies how to match future request headers to decide whether the cached response can be used rather than requesting a fresh one from the origin server." + }, + { + "key": "Via", + "value": "1.1 vegur", + "name": "Via", + "description": "Informs the client of proxies through which the response was sent." + }, + { + "key": "X-Powered-By", + "value": "mockbin", + "name": "X-Powered-By", + "description": "Specifies the technology (ASP.NET, PHP, JBoss, e.g.) supporting the web application (version details are often in X-Runtime, X-Version, or X-AspNet-Version)" + } + ], + "cookie": [ + { + "expires": "Thu Mar 14 2019 13:12:10 GMT+0530 (IST)", + "httpOnly": true, + "domain": "mockbin.org", + "path": "/", + "secure": false, + "value": "dfb94a3e1f3f8a9956138e4896847caf21521013330", + "key": "__cfduid" + } + ], + "body": "{\n \"startedDateTime\": \"2018-03-14T09:06:37.443Z\",\n \"clientIPAddress\": \"106.51.70.154\",\n \"method\": \"COPY\",\n \"url\": \"https://mockbin.org/request\",\n \"httpVersion\": \"HTTP/1.1\",\n \"cookies\": {\n \"__cfduid\": \"dfb94a3e1f3f8a9956138e4896847caf21521013330\"\n },\n \"headers\": {\n \"host\": \"mockbin.org\",\n \"connection\": \"close\",\n \"accept-encoding\": \"gzip\",\n \"x-forwarded-for\": \"106.51.70.154, 172.68.255.127\",\n \"cf-ray\": \"3fb595d5facaa302-HKG\",\n \"x-forwarded-proto\": \"http\",\n \"cf-visitor\": \"{\\\"scheme\\\":\\\"https\\\"}\",\n \"cache-control\": \"no-cache\",\n \"postman-token\": \"8d5b9832-75df-432f-90a3-284dacef0478\",\n \"user-agent\": \"PostmanRuntime/7.1.1\",\n \"accept\": \"*/*\",\n \"cookie\": \"__cfduid=dfb94a3e1f3f8a9956138e4896847caf21521013330\",\n \"cf-connecting-ip\": \"106.51.70.154\",\n \"x-request-id\": \"0e41473d-5130-4a6e-968d-b2a16cda3364\",\n \"x-forwarded-port\": \"80\",\n \"via\": \"1.1 vegur\",\n \"connect-time\": \"2\",\n \"x-request-start\": \"1521018397437\",\n \"total-route-time\": \"0\",\n \"content-length\": \"0\"\n },\n \"queryString\": {},\n \"postData\": {\n \"mimeType\": \"application/octet-stream\",\n \"text\": \"\",\n \"params\": []\n },\n \"headersSize\": 637,\n \"bodySize\": 0\n}" + } + ] + } + ] +} \ No newline at end of file diff --git a/test/codegen/newman/newman.test.js b/test/codegen/newman/newman.test.js new file mode 100644 index 000000000..3c03e80df --- /dev/null +++ b/test/codegen/newman/newman.test.js @@ -0,0 +1,146 @@ +var fs = require('fs'), + exec = require('shelljs').exec, + // sdk = require('postman-collection'), + newmanResponses = require('./newmanResponses.json'), + // testCollection = require('./fixtures/testCollection.json'), + async = require('async'); + +module.exports = { + /** + * compiles and runs codesnippet then compare it with newman output + * + * @param {String} codeSnippet - code snippet that needed to run using C# + * @param {Integer} index + * @param {Integer} testConfig + * @param {Function} callback - callback for async calls + */ + runSnippet: function (codeSnippet, index, testConfig, callback) { + if (testConfig.fileName) { + fs.writeFileSync(testConfig.fileName, codeSnippet); + } + console.log(index); + // bash command string for compiling codeSnippet + var compile = testConfig.compileScript ? testConfig.compileScript : null, + // bash command stirng for run compiled file file + run = testConfig.runScript ? testConfig.runScript : codeSnippet; + + // step by step process for compile, run code snippet, then comparing its output with newman + async.waterfall([ + function compileCodeSnippet (next) { + if (compile) { + return exec(compile, function (err, stdout, stderr) { + if (err) { + return next(JSON.stringify({ + error: err, + message: 'Compile error' + })); + } + if (stderr) { + return next(JSON.stringify({ + stderr: stderr, + message: 'Compile error' + })); + } + console.log(stdout); + return next(null); + }); + } + return next(null); + }, + + function runCodeSnippet (next) { + if (run) { + return exec(run, function (err, stdout, stderr) { + + if (err) { + return next(err); + } + if (stderr) { + return next(stderr); + } + try { + stdout = JSON.parse(stdout); + } + catch (e) { + console.error(e); + } + return next(null, stdout); + }); + } + } + ], function (err, response) { + var result = [response, newmanResponses[index]]; + + if (err) { + return callback(err); + } + else if (typeof result[1] !== 'object' || typeof result[0] !== 'object') { + return callback(null, result); + } + const propertiesTodelete = ['cookies', 'headersSize', 'startedDateTime', 'clientIPAddress'], + headersTodelete = [ + 'accept-encoding', + 'user-agent', + 'cf-ray', + 'x-real-ip', + 'x-request-id', + 'kong-request-id', + 'x-request-start', + 'connect-time', + 'x-forwarded-for', + 'content-type', + 'content-length', + 'accept', + 'total-route-time', + 'cookie', + 'kong-cloud-request-id', + 'cache-control', + 'postman-token' + ]; + if (result[0]) { + propertiesTodelete.forEach(function (property) { + delete result[0][property]; + }); + if (result[0].headers) { + headersTodelete.forEach(function (property) { + delete result[0].headers[property]; + }); + } + } + if (result[1]) { + propertiesTodelete.forEach(function (property) { + delete result[1][property]; + }); + if (result[1].headers) { + headersTodelete.forEach(function (property) { + delete result[1].headers[property]; + }); + } + } + return callback(null, result); + + }); + } + + // generateSnippet: function (convert, options, callback) { + // // check if convert is a function, and options is an object + + // async.map(testCollection.item, function (item, cb) { + // var request = new sdk.Request(item.request); + + // convert(request, options, function (err, snippet) { + // if (err) { + // return cb(err); + // } + + // return cb(null, snippet); + // }); + // }, function (err, snippets) { + // if (err) { + // return callback(err); + // } + + // return callback(null, snippets); + // }); + // } +}; diff --git a/test/codegen/newman/runNewman.js b/test/codegen/newman/runNewman.js new file mode 100644 index 000000000..c00484968 --- /dev/null +++ b/test/codegen/newman/runNewman.js @@ -0,0 +1,49 @@ +var newman = require('newman'), + fs = require('fs'), + path = require('path'), + responses = []; +const collection = require('../newman/fixtures/testCollection.json'), + PATH_TO_NEWMAN_REPONSES = path.resolve(__dirname, '../newman/newmanResponses.json'); + +/** + * compiles and runs codesnippet then compare it with newman output + * + * @param {Object} collection - collection which will be run using newman + * @param {Function} done - callback for async calls + */ +function runNewman (collection, done) { + newman.run({ + collection: collection + }).on('request', function (err, summary) { + if (err) { + return done(err); + } + + var stdout = summary.response.stream.toString(); + try { + stdout = JSON.parse(stdout); + } + catch (e) { + console.error(); + } + + responses.push(stdout); + }).on('done', function (err) { + if (err) { + return done(err); + } + fs.writeFile(PATH_TO_NEWMAN_REPONSES, JSON.stringify(responses, null, 2), function (err) { + if (err) { + console.log(err); + } + }); + return done(null, 'done'); + }); +} + +runNewman(collection, function (err, out) { + if (err) { + console.log(err); + } + console.log(out); +});