diff --git a/index.js b/index.js index dea33d7..f34c0b6 100644 --- a/index.js +++ b/index.js @@ -244,10 +244,14 @@ function testGenResponse(swagger, apiPath, operation, response, config, consume, // get the data data = getData(swagger, apiPath, operation, response, config, info); - if (helpers.mediaTypeContainsJson(produce) && !data.noSchema) { + if ((helpers.mediaTypeContainsJson(produce) || helpers.mediaTypeContainsXml(produce)) && !data.noSchema) { info.importValidator = true; } + if (helpers.mediaTypeContainsXml(produce) && !data.noSchema) { + info.importXml2js = true; + } + if (info.security && info.security.length !== 0) { info.importEnv = true; } @@ -438,6 +442,7 @@ function testGenPath(swagger, apiPath, config) { host: (swagger.host !== undefined ? swagger.host : 'localhost:10010'), tests: result, importValidator: info.importValidator, + importXml2js: info.importXml2js, importEnv: info.importEnv, importArete: info.importArete }; @@ -559,6 +564,8 @@ handlebars.registerHelper('printJSON', helpers.printJSON); handlebars.registerHelper('requestDataParamFormatter', helpers.requestDataParamFormatter); handlebars.registerHelper('isJsonRepresentation', helpers.isJsonRepresentation); handlebars.registerHelper('isJsonMediaType', helpers.isJsonMediaType); +handlebars.registerHelper('isXmlMediaType', helpers.isXmlMediaType); +handlebars.registerHelper('isNecessaryBody', helpers.isNecessaryBody); module.exports = { diff --git a/lib/helpers.js b/lib/helpers.js index ba695f9..c2abfc7 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -17,7 +17,10 @@ module.exports = { requestDataParamFormatter : requestDataParamFormatter, isJsonRepresentation : isJsonRepresentation, isJsonMediaType : isJsonMediaType, - mediaTypeContainsJson : mediaTypeContainsJson + isXmlMediaType : isXmlMediaType, + isNecessaryBody : isNecessaryBody, + mediaTypeContainsJson : mediaTypeContainsJson, + mediaTypeContainsXml : mediaTypeContainsXml }; function setLen(descriptionLength) { @@ -62,7 +65,7 @@ function validateResponse(type, noSchema, 'needs 2 parameters'); } - if (!noSchema && mediaTypeContainsJson(type)) { + if (!noSchema && (mediaTypeContainsJson(type) || mediaTypeContainsXml(type))) { return options.fn(this); } else { return options.inverse(this); @@ -77,6 +80,24 @@ function isJsonMediaType(type, options) { return mediaTypeContainsJson(type) ? options.fn(this) : options.inverse(this); } +/** + * mustache helper method to determine if a mediaType is XML + * @param {string} type content type to be evaluated + */ +function isXmlMediaType(type, options) { + return mediaTypeContainsXml(type) ? options.fn(this) : options.inverse(this); +} + +/** + * mustache helper method to determine if is necessary that function test generated + * have body parameter + * @param {string} type content type to be evaluated + * @param {boolean} noSchema whether or not there is a defined schema + */ +function isNecessaryBody(type, noSchema, options) { + return noSchema || !mediaTypeContainsXml(type) ? options.fn(this) : options.inverse(this); +} + /** * decides if this request/response has a JSON representation * @param {string} contentType the media type of the request @@ -94,6 +115,14 @@ function mediaTypeContainsJson(type) { return /\bjson\b/i.test(type); } +/** + * determines if the mediatype is xml + * @param {string} type content type to be evaluated + */ +function mediaTypeContainsXml(type) { + return /\bxml\b/i.test(type); +} + /** * replaces path params with obvious indicator for filling values * (i.e. if any part of the path is surrounded in curly braces {}) @@ -224,11 +253,11 @@ function requestDataParamFormatter(paramName, paramType, requestParameters){ var delimiter = "'"; if (['integer', 'number', 'boolean', 'null'].indexOf(paramType.toLowerCase()) > -1) { delimiter = ''; - } - + } + if (typeof requestParameters[paramName] != 'undefined') { return delimiter + requestParameters[paramName] + delimiter; } return "'DATA GOES HERE'"; -} \ No newline at end of file +} diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..6c944ab --- /dev/null +++ b/package-lock.json @@ -0,0 +1,1321 @@ +{ + "name": "swagger-test-templates", + "version": "1.4.2", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "align-text": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/align-text/-/align-text-0.1.4.tgz", + "integrity": "sha1-DNkKVhCT810KmSVsIrcGlDP60Rc=", + "requires": { + "kind-of": "3.2.2", + "longest": "1.0.1", + "repeat-string": "1.6.1" + } + }, + "amdefine": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/amdefine/-/amdefine-1.0.1.tgz", + "integrity": "sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU=" + }, + "ansi-regex": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", + "dev": true + }, + "ansi-styles": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", + "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=", + "dev": true + }, + "argparse": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", + "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", + "dev": true, + "requires": { + "sprintf-js": "1.0.3" + } + }, + "assertion-error": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", + "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", + "dev": true + }, + "async": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz", + "integrity": "sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo=" + }, + "balanced-match": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", + "dev": true + }, + "brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, + "requires": { + "balanced-match": "1.0.0", + "concat-map": "0.0.1" + } + }, + "camelcase": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-1.2.1.tgz", + "integrity": "sha1-m7UwTS4LVmmLLHWLCKPqqdqlijk=", + "optional": true + }, + "center-align": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/center-align/-/center-align-0.1.3.tgz", + "integrity": "sha1-qg0yYptu6XIgBBHL1EYckHvCt60=", + "optional": true, + "requires": { + "align-text": "0.1.4", + "lazy-cache": "1.0.4" + } + }, + "chai": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/chai/-/chai-3.5.0.tgz", + "integrity": "sha1-TQJjewZ/6Vi9v906QOxW/vc3Mkc=", + "dev": true, + "requires": { + "assertion-error": "1.1.0", + "deep-eql": "0.1.3", + "type-detect": "1.0.0" + } + }, + "chalk": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", + "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", + "dev": true, + "requires": { + "ansi-styles": "2.2.1", + "escape-string-regexp": "1.0.5", + "has-ansi": "2.0.0", + "strip-ansi": "3.0.1", + "supports-color": "2.0.0" + } + }, + "charenc": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/charenc/-/charenc-0.0.2.tgz", + "integrity": "sha1-wKHS86cJLgN3S/qD8UwPxXkKhmc=" + }, + "cli-width": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/cli-width/-/cli-width-1.1.1.tgz", + "integrity": "sha1-pNKT72frt7iNSk1CwMzwDE0eNm0=", + "dev": true + }, + "cliui": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-2.1.0.tgz", + "integrity": "sha1-S0dXYP+AJkx2LDoXGQMukcf+oNE=", + "optional": true, + "requires": { + "center-align": "0.1.3", + "right-align": "0.1.3", + "wordwrap": "0.0.2" + }, + "dependencies": { + "wordwrap": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.2.tgz", + "integrity": "sha1-t5Zpu0LstAn4PVg8rVLKF+qhZD8=", + "optional": true + } + } + }, + "clone": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/clone/-/clone-2.0.0.tgz", + "integrity": "sha1-32XTyhQuSkpH2zPaNGjQiKFvx24=" + }, + "commander": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.3.0.tgz", + "integrity": "sha1-/UMOiJgy7DU7ms0d4hfBHLPu+HM=", + "dev": true + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", + "dev": true + }, + "concat-stream": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.0.tgz", + "integrity": "sha1-CqxmL9Ur54lk1VMvaUeE5wEQrPc=", + "dev": true, + "requires": { + "inherits": "2.0.3", + "readable-stream": "2.3.4", + "typedarray": "0.0.6" + } + }, + "core-util-is": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", + "dev": true + }, + "crypt": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/crypt/-/crypt-0.0.2.tgz", + "integrity": "sha1-iNf/fsDfuG9xPch7u0LQRNPmxBs=" + }, + "d": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/d/-/d-1.0.0.tgz", + "integrity": "sha1-dUu1v+VUUdpppYuU1F9MWwRi1Y8=", + "dev": true, + "requires": { + "es5-ext": "0.10.39" + } + }, + "dag-map": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/dag-map/-/dag-map-1.0.2.tgz", + "integrity": "sha1-6DefBBAA7VYfxRVHXB7SyF7s6Nc=" + }, + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dev": true, + "requires": { + "ms": "2.0.0" + } + }, + "decamelize": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", + "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=", + "optional": true + }, + "deep-eql": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-0.1.3.tgz", + "integrity": "sha1-71WKyrjeJSBs1xOQbXTlaTDrafI=", + "dev": true, + "requires": { + "type-detect": "0.1.1" + }, + "dependencies": { + "type-detect": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-0.1.1.tgz", + "integrity": "sha1-C6XsKohWQORw6k6FBZcZANrFiCI=", + "dev": true + } + } + }, + "deep-is": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz", + "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=", + "dev": true + }, + "diff": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-1.4.0.tgz", + "integrity": "sha1-fyjS657nsVqX79ic5j3P2qPMur8=", + "dev": true + }, + "doctrine": { + "version": "0.6.4", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-0.6.4.tgz", + "integrity": "sha1-gUKEkalC7xiwSSBW7aOADu5X1h0=", + "dev": true, + "requires": { + "esutils": "1.1.6", + "isarray": "0.0.1" + }, + "dependencies": { + "isarray": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=", + "dev": true + } + } + }, + "dotenv": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-1.2.0.tgz", + "integrity": "sha1-fNc+FuB/BXyAchR6W8OoZ38KtcY=", + "dev": true + }, + "es5-ext": { + "version": "0.10.39", + "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.39.tgz", + "integrity": "sha512-AlaXZhPHl0po/uxMx1tyrlt1O86M6D5iVaDH8UgLfgek4kXTX6vzsRfJQWC2Ku+aG8pkw1XWzh9eTkwfVrsD5g==", + "dev": true, + "requires": { + "es6-iterator": "2.0.3", + "es6-symbol": "3.1.1" + } + }, + "es6-iterator": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/es6-iterator/-/es6-iterator-2.0.3.tgz", + "integrity": "sha1-p96IkUGgWpSwhUQDstCg+/qY87c=", + "dev": true, + "requires": { + "d": "1.0.0", + "es5-ext": "0.10.39", + "es6-symbol": "3.1.1" + } + }, + "es6-map": { + "version": "0.1.5", + "resolved": "https://registry.npmjs.org/es6-map/-/es6-map-0.1.5.tgz", + "integrity": "sha1-kTbgUD3MBqMBaQ8LsU/042TpSfA=", + "dev": true, + "requires": { + "d": "1.0.0", + "es5-ext": "0.10.39", + "es6-iterator": "2.0.3", + "es6-set": "0.1.5", + "es6-symbol": "3.1.1", + "event-emitter": "0.3.5" + } + }, + "es6-set": { + "version": "0.1.5", + "resolved": "https://registry.npmjs.org/es6-set/-/es6-set-0.1.5.tgz", + "integrity": "sha1-0rPsXU2ADO2BjbU40ol02wpzzLE=", + "dev": true, + "requires": { + "d": "1.0.0", + "es5-ext": "0.10.39", + "es6-iterator": "2.0.3", + "es6-symbol": "3.1.1", + "event-emitter": "0.3.5" + } + }, + "es6-symbol": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.1.tgz", + "integrity": "sha1-vwDvT9q2uhtG7Le2KbTH7VcVzHc=", + "dev": true, + "requires": { + "d": "1.0.0", + "es5-ext": "0.10.39" + } + }, + "es6-weak-map": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/es6-weak-map/-/es6-weak-map-2.0.2.tgz", + "integrity": "sha1-XjqzIlH/0VOKH45f+hNXdy+S2W8=", + "dev": true, + "requires": { + "d": "1.0.0", + "es5-ext": "0.10.39", + "es6-iterator": "2.0.3", + "es6-symbol": "3.1.1" + } + }, + "escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", + "dev": true + }, + "escope": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/escope/-/escope-3.6.0.tgz", + "integrity": "sha1-4Bl16BJ4GhY6ba392AOY3GTIicM=", + "dev": true, + "requires": { + "es6-map": "0.1.5", + "es6-weak-map": "2.0.2", + "esrecurse": "4.2.1", + "estraverse": "4.2.0" + } + }, + "eslint": { + "version": "0.24.1", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-0.24.1.tgz", + "integrity": "sha1-VKUICYVbllVyHG8u5Xs1HtzigQE=", + "dev": true, + "requires": { + "chalk": "1.1.3", + "concat-stream": "1.6.0", + "debug": "2.6.9", + "doctrine": "0.6.4", + "escape-string-regexp": "1.0.5", + "escope": "3.6.0", + "espree": "2.2.5", + "estraverse": "4.2.0", + "estraverse-fb": "1.3.2", + "globals": "8.18.0", + "inquirer": "0.8.5", + "is-my-json-valid": "2.17.2", + "js-yaml": "3.10.0", + "minimatch": "2.0.10", + "mkdirp": "0.5.1", + "object-assign": "2.1.1", + "optionator": "0.5.0", + "path-is-absolute": "1.0.1", + "strip-json-comments": "1.0.4", + "text-table": "0.2.0", + "user-home": "1.1.1", + "xml-escape": "1.0.0" + } + }, + "espree": { + "version": "2.2.5", + "resolved": "https://registry.npmjs.org/espree/-/espree-2.2.5.tgz", + "integrity": "sha1-32kbkxCIlAKuspzAZnCMVmkLhUs=", + "dev": true + }, + "esrecurse": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.2.1.tgz", + "integrity": "sha512-64RBB++fIOAXPw3P9cy89qfMlvZEXZkqqJkjqqXIvzP5ezRZjW+lPWjw35UX/3EhUPFYbg5ER4JYgDw4007/DQ==", + "dev": true, + "requires": { + "estraverse": "4.2.0" + } + }, + "estraverse": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.2.0.tgz", + "integrity": "sha1-De4/7TH81GlhjOc0IJn8GvoL2xM=", + "dev": true + }, + "estraverse-fb": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/estraverse-fb/-/estraverse-fb-1.3.2.tgz", + "integrity": "sha1-0yOky15awzHOoDNBOpJT4WQ+B8Q=", + "dev": true + }, + "esutils": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/esutils/-/esutils-1.1.6.tgz", + "integrity": "sha1-wBzKqa5LiXxtDD4hCuUvPHqEQ3U=", + "dev": true + }, + "event-emitter": { + "version": "0.3.5", + "resolved": "https://registry.npmjs.org/event-emitter/-/event-emitter-0.3.5.tgz", + "integrity": "sha1-34xp7vFkeSPHFXuc6DhAYQsCzDk=", + "dev": true, + "requires": { + "d": "1.0.0", + "es5-ext": "0.10.39" + } + }, + "fast-levenshtein": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-1.0.7.tgz", + "integrity": "sha1-AXjc3uAjuSkFGTrwlZ6KdjnP3Lk=", + "dev": true + }, + "figures": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/figures/-/figures-1.7.0.tgz", + "integrity": "sha1-y+Hjr/zxzUS4DK3+0o3Hk6lwHS4=", + "dev": true, + "requires": { + "escape-string-regexp": "1.0.5", + "object-assign": "4.1.1" + }, + "dependencies": { + "object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", + "dev": true + } + } + }, + "foreachasync": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/foreachasync/-/foreachasync-3.0.0.tgz", + "integrity": "sha1-VQKYfchxS+M5IJfzLgBxyd7gfPY=", + "dev": true + }, + "generate-function": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/generate-function/-/generate-function-2.0.0.tgz", + "integrity": "sha1-aFj+fAlpt9TpCTM3ZHrHn2DfvnQ=", + "dev": true + }, + "generate-object-property": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/generate-object-property/-/generate-object-property-1.2.0.tgz", + "integrity": "sha1-nA4cQDCM6AT0eDYYuTf6iPmdUNA=", + "dev": true, + "requires": { + "is-property": "1.0.2" + } + }, + "glob": { + "version": "3.2.11", + "resolved": "https://registry.npmjs.org/glob/-/glob-3.2.11.tgz", + "integrity": "sha1-Spc/Y1uRkPcV0QmH1cAP0oFevj0=", + "dev": true, + "requires": { + "inherits": "2.0.3", + "minimatch": "0.3.0" + }, + "dependencies": { + "minimatch": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-0.3.0.tgz", + "integrity": "sha1-J12O2qxPG7MyZHIInnlJyDlGmd0=", + "dev": true, + "requires": { + "lru-cache": "2.7.3", + "sigmund": "1.0.1" + } + } + } + }, + "globals": { + "version": "8.18.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-8.18.0.tgz", + "integrity": "sha1-k9SmK9ysOM+vr8R9awNHaMsP/LQ=", + "dev": true + }, + "growl": { + "version": "1.9.2", + "resolved": "https://registry.npmjs.org/growl/-/growl-1.9.2.tgz", + "integrity": "sha1-Dqd0NxXbjY3ixe3hd14bRayFwC8=", + "dev": true + }, + "handlebars": { + "version": "4.0.11", + "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.0.11.tgz", + "integrity": "sha1-Ywo13+ApS8KB7a5v/F0yn8eYLcw=", + "requires": { + "async": "1.5.2", + "optimist": "0.6.1", + "source-map": "0.4.4", + "uglify-js": "2.8.29" + } + }, + "has-ansi": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", + "integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=", + "dev": true, + "requires": { + "ansi-regex": "2.1.1" + } + }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "dev": true, + "requires": { + "once": "1.4.0", + "wrappy": "1.0.2" + } + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", + "dev": true + }, + "inquirer": { + "version": "0.8.5", + "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-0.8.5.tgz", + "integrity": "sha1-29dAz2yjtzEpamPOb22WGFHzNt8=", + "dev": true, + "requires": { + "ansi-regex": "1.1.1", + "chalk": "1.1.3", + "cli-width": "1.1.1", + "figures": "1.7.0", + "lodash": "3.10.1", + "readline2": "0.1.1", + "rx": "2.5.3", + "through": "2.3.8" + }, + "dependencies": { + "ansi-regex": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-1.1.1.tgz", + "integrity": "sha1-QchHGUZGN15qGl0Qw8oFTvn8mA0=", + "dev": true + } + } + }, + "is-buffer": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz", + "integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==" + }, + "is-extglob": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-1.0.0.tgz", + "integrity": "sha1-rEaBd8SUNAWgkvyPKXYMb/xiBsA=" + }, + "is-glob": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-2.0.1.tgz", + "integrity": "sha1-0Jb5JqPe1WAPP9/ZEZjLCIjC2GM=", + "requires": { + "is-extglob": "1.0.0" + } + }, + "is-invalid-path": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/is-invalid-path/-/is-invalid-path-0.1.0.tgz", + "integrity": "sha1-MHqFWzzxqTi0TqcNLGEQYFNxTzQ=", + "requires": { + "is-glob": "2.0.1" + } + }, + "is-my-ip-valid": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-my-ip-valid/-/is-my-ip-valid-1.0.0.tgz", + "integrity": "sha512-gmh/eWXROncUzRnIa1Ubrt5b8ep/MGSnfAUI3aRp+sqTCs1tv1Isl8d8F6JmkN3dXKc3ehZMrtiPN9eL03NuaQ==", + "dev": true + }, + "is-my-json-valid": { + "version": "2.17.2", + "resolved": "https://registry.npmjs.org/is-my-json-valid/-/is-my-json-valid-2.17.2.tgz", + "integrity": "sha512-IBhBslgngMQN8DDSppmgDv7RNrlFotuuDsKcrCP3+HbFaVivIBU7u9oiiErw8sH4ynx3+gOGQ3q2otkgiSi6kg==", + "dev": true, + "requires": { + "generate-function": "2.0.0", + "generate-object-property": "1.2.0", + "is-my-ip-valid": "1.0.0", + "jsonpointer": "4.0.1", + "xtend": "4.0.1" + } + }, + "is-property": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-property/-/is-property-1.0.2.tgz", + "integrity": "sha1-V/4cTkhHTt1lsJkR8msc1Ald2oQ=", + "dev": true + }, + "is-valid-path": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/is-valid-path/-/is-valid-path-0.1.1.tgz", + "integrity": "sha1-EQ+f90w39mPh7HkV60UfLbk6yd8=", + "requires": { + "is-invalid-path": "0.1.0" + } + }, + "isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", + "dev": true + }, + "jade": { + "version": "0.26.3", + "resolved": "https://registry.npmjs.org/jade/-/jade-0.26.3.tgz", + "integrity": "sha1-jxDXl32NefL2/4YqgbBRPMslaGw=", + "dev": true, + "requires": { + "commander": "0.6.1", + "mkdirp": "0.3.0" + }, + "dependencies": { + "commander": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-0.6.1.tgz", + "integrity": "sha1-+mihT2qUXVTbvlDYzbMyDp47GgY=", + "dev": true + }, + "mkdirp": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.0.tgz", + "integrity": "sha1-G79asbqCevI1dRQ0kEJkVfSB/h4=", + "dev": true + } + } + }, + "js-yaml": { + "version": "3.10.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.10.0.tgz", + "integrity": "sha512-O2v52ffjLa9VeM43J4XocZE//WT9N0IiwDa3KSHH7Tu8CtH+1qM8SIZvnsTh6v+4yFy5KUY3BHUVwjpfAWsjIA==", + "dev": true, + "requires": { + "argparse": "1.0.10", + "esprima": "4.0.0" + }, + "dependencies": { + "esprima": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.0.tgz", + "integrity": "sha512-oftTcaMu/EGrEIu904mWteKIv8vMuOgGYo7EhVJJN00R/EED9DCua/xxHRdYnKtcECzVg7xOWhflvJMnqcFZjw==", + "dev": true + } + } + }, + "json-schema-deref-sync": { + "version": "0.3.4", + "resolved": "https://registry.npmjs.org/json-schema-deref-sync/-/json-schema-deref-sync-0.3.4.tgz", + "integrity": "sha512-4Ssj+1UGDJAzPIdTL1QW/rvHwWeuwC28gjbA0EjStLxVsalc+UPciKXxs3rhtr4gaGdIBojW/VmvC8B8bCQwcA==", + "requires": { + "clone": "2.0.0", + "dag-map": "1.0.2", + "is-valid-path": "0.1.1", + "lodash": "4.17.5", + "md5": "2.2.1", + "memory-cache": "0.1.6", + "mpath": "0.2.1", + "traverse": "0.6.6", + "valid-url": "1.0.9" + }, + "dependencies": { + "lodash": { + "version": "4.17.5", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.5.tgz", + "integrity": "sha512-svL3uiZf1RwhH+cWrfZn3A4+U58wbP0tGVTLQPbjplZxZ8ROD9VLuNgsRniTlLe7OlSqR79RUehXgpBW/s0IQw==" + } + } + }, + "jsonpointer": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/jsonpointer/-/jsonpointer-4.0.1.tgz", + "integrity": "sha1-T9kss04OnbPInIYi7PUfm5eMbLk=", + "dev": true + }, + "kind-of": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", + "integrity": "sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ=", + "requires": { + "is-buffer": "1.1.6" + } + }, + "lazy-cache": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/lazy-cache/-/lazy-cache-1.0.4.tgz", + "integrity": "sha1-odePw6UEdMuAhF07O24dpJpEbo4=", + "optional": true + }, + "levn": { + "version": "0.2.5", + "resolved": "https://registry.npmjs.org/levn/-/levn-0.2.5.tgz", + "integrity": "sha1-uo0znQykphDjo/FFucr0iAcVUFQ=", + "dev": true, + "requires": { + "prelude-ls": "1.1.2", + "type-check": "0.3.2" + } + }, + "lodash": { + "version": "3.10.1", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-3.10.1.tgz", + "integrity": "sha1-W/Rejkm6QYnhfUgnid/RW9FAt7Y=" + }, + "lodash.get": { + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", + "integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=", + "dev": true + }, + "lodash.isequal": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz", + "integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA=", + "dev": true + }, + "longest": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz", + "integrity": "sha1-MKCy2jj3N3DoKUoNIuZiXtd9AJc=" + }, + "lru-cache": { + "version": "2.7.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-2.7.3.tgz", + "integrity": "sha1-bUUk6LlV+V1PW1iFHOId1y+06VI=", + "dev": true + }, + "md5": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/md5/-/md5-2.2.1.tgz", + "integrity": "sha1-U6s41f48iJG6RlMp6iP6wFQBJvk=", + "requires": { + "charenc": "0.0.2", + "crypt": "0.0.2", + "is-buffer": "1.1.6" + } + }, + "memory-cache": { + "version": "0.1.6", + "resolved": "https://registry.npmjs.org/memory-cache/-/memory-cache-0.1.6.tgz", + "integrity": "sha1-LtmTPteoxxgkm+c2b3yodJrPiiQ=" + }, + "minimatch": { + "version": "2.0.10", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-2.0.10.tgz", + "integrity": "sha1-jQh8OcazjAAbl/ynzm0OHoCvusc=", + "dev": true, + "requires": { + "brace-expansion": "1.1.11" + } + }, + "minimist": { + "version": "0.0.10", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz", + "integrity": "sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8=" + }, + "mkdirp": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "dev": true, + "requires": { + "minimist": "0.0.8" + }, + "dependencies": { + "minimist": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", + "dev": true + } + } + }, + "mocha": { + "version": "2.5.3", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-2.5.3.tgz", + "integrity": "sha1-FhvlvetJZ3HrmzV0UFC2IrWu/Fg=", + "dev": true, + "requires": { + "commander": "2.3.0", + "debug": "2.2.0", + "diff": "1.4.0", + "escape-string-regexp": "1.0.2", + "glob": "3.2.11", + "growl": "1.9.2", + "jade": "0.26.3", + "mkdirp": "0.5.1", + "supports-color": "1.2.0", + "to-iso-string": "0.0.2" + }, + "dependencies": { + "debug": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.2.0.tgz", + "integrity": "sha1-+HBX6ZWxofauaklgZkE3vFbwOdo=", + "dev": true, + "requires": { + "ms": "0.7.1" + } + }, + "escape-string-regexp": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.2.tgz", + "integrity": "sha1-Tbwv5nTnGUnK8/smlc5/LcHZqNE=", + "dev": true + }, + "ms": { + "version": "0.7.1", + "resolved": "https://registry.npmjs.org/ms/-/ms-0.7.1.tgz", + "integrity": "sha1-nNE8A62/8ltl7/3nzoZO6VIBcJg=", + "dev": true + }, + "supports-color": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-1.2.0.tgz", + "integrity": "sha1-/x7R5hFp0Gs88tWI4YixjYhH4X4=", + "dev": true + } + } + }, + "mocha-eslint": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/mocha-eslint/-/mocha-eslint-0.1.7.tgz", + "integrity": "sha1-tOm+Vroz9AjYOMqif1wzqfLkCZM=", + "dev": true, + "requires": { + "chalk": "1.1.3", + "eslint": "0.21.2", + "glob": "5.0.5" + }, + "dependencies": { + "eslint": { + "version": "0.21.2", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-0.21.2.tgz", + "integrity": "sha1-vt3yR4ANSGf2sQUdIkvbg8LSAcc=", + "dev": true, + "requires": { + "chalk": "1.1.3", + "concat-stream": "1.6.0", + "debug": "2.6.9", + "doctrine": "0.6.4", + "escape-string-regexp": "1.0.5", + "escope": "3.6.0", + "espree": "2.2.5", + "estraverse": "2.0.0", + "estraverse-fb": "1.3.2", + "globals": "6.4.1", + "inquirer": "0.8.5", + "js-yaml": "3.10.0", + "minimatch": "2.0.10", + "mkdirp": "0.5.1", + "object-assign": "2.1.1", + "optionator": "0.5.0", + "path-is-absolute": "1.0.1", + "strip-json-comments": "1.0.4", + "text-table": "0.2.0", + "user-home": "1.1.1", + "xml-escape": "1.0.0" + } + }, + "estraverse": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-2.0.0.tgz", + "integrity": "sha1-WuRpYyQ2ACBmdMyySgnhZnT83KE=", + "dev": true + }, + "glob": { + "version": "5.0.5", + "resolved": "https://registry.npmjs.org/glob/-/glob-5.0.5.tgz", + "integrity": "sha1-eEQx5OKakArg1H+6aqHH8WqOffc=", + "dev": true, + "requires": { + "inflight": "1.0.6", + "inherits": "2.0.3", + "minimatch": "2.0.10", + "once": "1.4.0", + "path-is-absolute": "1.0.1" + } + }, + "globals": { + "version": "6.4.1", + "resolved": "https://registry.npmjs.org/globals/-/globals-6.4.1.tgz", + "integrity": "sha1-hJgDKzttHMge68X3lpDY/in6v08=", + "dev": true + } + } + }, + "mpath": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.2.1.tgz", + "integrity": "sha1-Ok6Ck1mAHeljCcJ6ay4QLon56W4=" + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", + "dev": true + }, + "mute-stream": { + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.4.tgz", + "integrity": "sha1-qSGZYKbV1dBGWXruUSUsZlX3F34=", + "dev": true + }, + "ncp": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ncp/-/ncp-2.0.0.tgz", + "integrity": "sha1-GVoh1sRuNh0vsSgbo4uR6d9727M=", + "dev": true + }, + "object-assign": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-2.1.1.tgz", + "integrity": "sha1-Q8NuXVaf+OSBbE76i+AtJpZ8GKo=", + "dev": true + }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "dev": true, + "requires": { + "wrappy": "1.0.2" + } + }, + "optimist": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/optimist/-/optimist-0.6.1.tgz", + "integrity": "sha1-2j6nRob6IaGaERwybpDrFaAZZoY=", + "requires": { + "minimist": "0.0.10", + "wordwrap": "0.0.3" + } + }, + "optionator": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.5.0.tgz", + "integrity": "sha1-t1qJlaLUF98ltuTjhi9QqohlE2g=", + "dev": true, + "requires": { + "deep-is": "0.1.3", + "fast-levenshtein": "1.0.7", + "levn": "0.2.5", + "prelude-ls": "1.1.2", + "type-check": "0.3.2", + "wordwrap": "0.0.3" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "dev": true + }, + "prelude-ls": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz", + "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=", + "dev": true + }, + "process-nextick-args": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz", + "integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==", + "dev": true + }, + "readable-stream": { + "version": "2.3.4", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.4.tgz", + "integrity": "sha512-vuYxeWYM+fde14+rajzqgeohAI7YoJcHE7kXDAc4Nk0EbuKnJfqtY9YtRkLo/tqkuF7MsBQRhPnPeyjYITp3ZQ==", + "dev": true, + "requires": { + "core-util-is": "1.0.2", + "inherits": "2.0.3", + "isarray": "1.0.0", + "process-nextick-args": "2.0.0", + "safe-buffer": "5.1.1", + "string_decoder": "1.0.3", + "util-deprecate": "1.0.2" + } + }, + "readline2": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/readline2/-/readline2-0.1.1.tgz", + "integrity": "sha1-mUQ7pug7gw7zBRv9fcJBqCco1Wg=", + "dev": true, + "requires": { + "mute-stream": "0.0.4", + "strip-ansi": "2.0.1" + }, + "dependencies": { + "ansi-regex": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-1.1.1.tgz", + "integrity": "sha1-QchHGUZGN15qGl0Qw8oFTvn8mA0=", + "dev": true + }, + "strip-ansi": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-2.0.1.tgz", + "integrity": "sha1-32LBqpTtLxFOHQ8h/R1QSCt5pg4=", + "dev": true, + "requires": { + "ansi-regex": "1.1.1" + } + } + } + }, + "repeat-string": { + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz", + "integrity": "sha1-jcrkcOHIirwtYA//Sndihtp15jc=" + }, + "rewire": { + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/rewire/-/rewire-2.5.2.tgz", + "integrity": "sha1-ZCfee3/u+n02QBUH62SlOFvFjcc=", + "dev": true + }, + "right-align": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/right-align/-/right-align-0.1.3.tgz", + "integrity": "sha1-YTObci/mo1FWiSENJOFMlhSGE+8=", + "optional": true, + "requires": { + "align-text": "0.1.4" + } + }, + "rx": { + "version": "2.5.3", + "resolved": "https://registry.npmjs.org/rx/-/rx-2.5.3.tgz", + "integrity": "sha1-Ia3H2A8CACr1Da6X/Z2/JIdV9WY=", + "dev": true + }, + "safe-buffer": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", + "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==", + "dev": true + }, + "sanitize-filename": { + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/sanitize-filename/-/sanitize-filename-1.6.1.tgz", + "integrity": "sha1-YS2hyWRz+gLczaktzVtKsWSmdyo=", + "requires": { + "truncate-utf8-bytes": "1.0.2" + } + }, + "sax": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", + "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==" + }, + "sigmund": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz", + "integrity": "sha1-P/IfGYytIXX587eBhT/ZTQ0ZtZA=", + "dev": true + }, + "source-map": { + "version": "0.4.4", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.4.4.tgz", + "integrity": "sha1-66T12pwNyZneaAMti092FzZSA2s=", + "requires": { + "amdefine": "1.0.1" + } + }, + "sprintf-js": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", + "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", + "dev": true + }, + "string": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/string/-/string-3.3.3.tgz", + "integrity": "sha1-XqIRzZLSKOGEKUmQpsyXs2anfLA=" + }, + "string_decoder": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", + "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", + "dev": true, + "requires": { + "safe-buffer": "5.1.1" + } + }, + "strip-ansi": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "dev": true, + "requires": { + "ansi-regex": "2.1.1" + } + }, + "strip-json-comments": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-1.0.4.tgz", + "integrity": "sha1-HhX7ysl9Pumb8tc7TGVrCCu6+5E=", + "dev": true + }, + "supports-color": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", + "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=", + "dev": true + }, + "text-table": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", + "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=", + "dev": true + }, + "through": { + "version": "2.3.8", + "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", + "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", + "dev": true + }, + "to-iso-string": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/to-iso-string/-/to-iso-string-0.0.2.tgz", + "integrity": "sha1-TcGeZk38y+Jb2NtQiwDG2hWCVdE=", + "dev": true + }, + "traverse": { + "version": "0.6.6", + "resolved": "https://registry.npmjs.org/traverse/-/traverse-0.6.6.tgz", + "integrity": "sha1-y99WD9e5r2MlAv7UD5GMFX6pcTc=" + }, + "truncate-utf8-bytes": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/truncate-utf8-bytes/-/truncate-utf8-bytes-1.0.2.tgz", + "integrity": "sha1-QFkjkJWS1W94pYGENLC3hInKXys=", + "requires": { + "utf8-byte-length": "1.0.4" + } + }, + "type-check": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz", + "integrity": "sha1-WITKtRLPHTVeP7eE8wgEsrUg23I=", + "dev": true, + "requires": { + "prelude-ls": "1.1.2" + } + }, + "type-detect": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-1.0.0.tgz", + "integrity": "sha1-diIXzAbbJY7EiQihKY6LlRIejqI=", + "dev": true + }, + "typedarray": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", + "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", + "dev": true + }, + "uglify-js": { + "version": "2.8.29", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-2.8.29.tgz", + "integrity": "sha1-KcVzMUgFe7Th913zW3qcty5qWd0=", + "optional": true, + "requires": { + "source-map": "0.5.7", + "uglify-to-browserify": "1.0.2", + "yargs": "3.10.0" + }, + "dependencies": { + "source-map": { + "version": "0.5.7", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", + "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", + "optional": true + } + } + }, + "uglify-to-browserify": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/uglify-to-browserify/-/uglify-to-browserify-1.0.2.tgz", + "integrity": "sha1-bgkk1r2mta/jSeOabWMoUKD4grc=", + "optional": true + }, + "user-home": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/user-home/-/user-home-1.1.1.tgz", + "integrity": "sha1-K1viOjK2Onyd640PKNSFcko98ZA=", + "dev": true + }, + "utf8-byte-length": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/utf8-byte-length/-/utf8-byte-length-1.0.4.tgz", + "integrity": "sha1-9F8VDExm7uloGGUFq5P8u4rWv2E=" + }, + "util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", + "dev": true + }, + "valid-url": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/valid-url/-/valid-url-1.0.9.tgz", + "integrity": "sha1-HBRHm0DxOXp1eC8RXkCGRHQzogA=" + }, + "validator": { + "version": "9.4.1", + "resolved": "https://registry.npmjs.org/validator/-/validator-9.4.1.tgz", + "integrity": "sha512-YV5KjzvRmSyJ1ee/Dm5UED0G+1L4GZnLN3w6/T+zZm8scVua4sOhYKWTUrKa0H/tMiJyO9QLHMPN+9mB/aMunA==", + "dev": true + }, + "walk": { + "version": "2.3.9", + "resolved": "https://registry.npmjs.org/walk/-/walk-2.3.9.tgz", + "integrity": "sha1-MbTbZnjyrgHDnqn7hyWpAx5Vins=", + "dev": true, + "requires": { + "foreachasync": "3.0.0" + } + }, + "window-size": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/window-size/-/window-size-0.1.0.tgz", + "integrity": "sha1-VDjNLqk7IC76Ohn+iIeu58lPnJ0=", + "optional": true + }, + "wordwrap": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz", + "integrity": "sha1-o9XabNXAvAAI03I0u68b7WMFkQc=" + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", + "dev": true + }, + "xml-escape": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/xml-escape/-/xml-escape-1.0.0.tgz", + "integrity": "sha1-AJY9aXsq3wwYXE4E5zF0upsojrI=", + "dev": true + }, + "xml2js": { + "version": "0.4.19", + "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.19.tgz", + "integrity": "sha512-esZnJZJOiJR9wWKMyuvSE1y6Dq5LCuJanqhxslH2bxM6duahNZ+HMpCLhBQGZkbX6xRf8x1Y2eJlgt2q3qo49Q==", + "requires": { + "sax": "1.2.4", + "xmlbuilder": "9.0.7" + } + }, + "xmlbuilder": { + "version": "9.0.7", + "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-9.0.7.tgz", + "integrity": "sha1-Ey7mPS7FVlxVfiD0wi35rKaGsQ0=" + }, + "xtend": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz", + "integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68=", + "dev": true + }, + "yargs": { + "version": "3.10.0", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-3.10.0.tgz", + "integrity": "sha1-9+572FfdfB0tOMDnTvvWgdFDH9E=", + "optional": true, + "requires": { + "camelcase": "1.2.1", + "cliui": "2.1.0", + "decamelize": "1.2.0", + "window-size": "0.1.0" + } + }, + "z-schema": { + "version": "3.19.1", + "resolved": "https://registry.npmjs.org/z-schema/-/z-schema-3.19.1.tgz", + "integrity": "sha512-jPNzqmOu3+AGbb4krDODqo4QBzwUGDVzyfGyy1HtWaUnafltQotatSpxxWd6Mp0iSZOUwHU5sqKYi+U8HsHMkg==", + "dev": true, + "requires": { + "commander": "2.14.1", + "lodash.get": "4.4.2", + "lodash.isequal": "4.5.0", + "validator": "9.4.1" + }, + "dependencies": { + "commander": { + "version": "2.14.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.14.1.tgz", + "integrity": "sha512-+YR16o3rK53SmWHU3rEM3tPAh2rwb1yPcQX5irVn7mb0gXbwuCCrnkbV5+PBfETdfg1vui07nM6PCG1zndcjQw==", + "dev": true, + "optional": true + } + } + } + } +} diff --git a/package.json b/package.json index 59f1e85..aa1b8f4 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "json-schema-deref-sync": "^0.3.1", "lodash": "^3.10.0", "sanitize-filename": "^1.3.0", - "string": "^3.3.0" + "string": "^3.3.0", + "xml2js": "^0.4.19" } } diff --git a/templates/outerDescribe.handlebars b/templates/outerDescribe.handlebars index 56341ef..e6bc634 100644 --- a/templates/outerDescribe.handlebars +++ b/templates/outerDescribe.handlebars @@ -1,4 +1,5 @@ -'use strict'; +'use strict';{{#if importXml2js}} +var parseString = require('xml2js').parseString;{{/if}} var chai = require('chai');{{#if importValidator}} var ZSchema = require('z-schema'); var customFormats = {{customFormats}} diff --git a/templates/request/delete/delete.handlebars b/templates/request/delete/delete.handlebars index df4e360..786623b 100644 --- a/templates/request/delete/delete.handlebars +++ b/templates/request/delete/delete.handlebars @@ -25,7 +25,7 @@ Authorization: '{{headerSecurity.type}} ' + process.env.{{headerSecurity.name}}{{/if}} } }, - function(error, res, body) { + function(error, res{{#isNecessaryBody returnType noSchema}}, body{{/isNecessaryBody}}) { if (error) return done(error); {{#is assertion 'expect'}} @@ -51,6 +51,7 @@ {{/is}} {{#validateResponse returnType noSchema}} + {{#isJsonMediaType returnType}} {{#is assertion 'expect'}} expect(validator.validate(body, schema)).to.be.true; {{/is}} @@ -60,6 +61,23 @@ {{#is assertion 'assert'}} assert.true(validator.validate(body, schema)); {{/is}} + done(); + {{/isJsonMediaType}} + {{#isXmlMediaType returnType}} + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + {{#is assertion 'expect'}} + expect(validator.validate(body, schema)).to.be.true; + {{/is}} + {{#is assertion 'should'}} + validator.validate(body, schema).should.be.true; + {{/is}} + {{#is assertion 'assert'}} + assert.true(validator.validate(body, schema)); + {{/is}} + done(); + }); + {{/isXmlMediaType}} {{else}} {{#is assertion 'expect'}} expect(body).to.equal(null); // non-json response or no schema @@ -70,7 +88,7 @@ {{#is assertion 'assert'}} assert.isNull(body); // non-json response or no schema {{/is}} - {{/validateResponse}} done(); + {{/validateResponse}} }); }); diff --git a/templates/request/get/get.handlebars b/templates/request/get/get.handlebars index a4ce72f..1900ccf 100644 --- a/templates/request/get/get.handlebars +++ b/templates/request/get/get.handlebars @@ -25,7 +25,7 @@ Authorization: '{{headerSecurity.type}} ' + process.env.{{headerSecurity.name}}{{/if}} } }, - function(error, res, body) { + function(error, res{{#isNecessaryBody returnType noSchema}}, body{{/isNecessaryBody}}) { if (error) return done(error); {{#is assertion 'expect'}} @@ -51,6 +51,7 @@ {{/is}} {{#validateResponse returnType noSchema}} + {{#isJsonMediaType returnType}} {{#is assertion 'expect'}} expect(validator.validate(body, schema)).to.be.true; {{/is}} @@ -60,6 +61,23 @@ {{#is assertion 'assert'}} assert.true(validator.validate(body, schema)); {{/is}} + done(); + {{/isJsonMediaType}} + {{#isXmlMediaType returnType}} + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + {{#is assertion 'expect'}} + expect(validator.validate(result, schema)).to.be.true; + {{/is}} + {{#is assertion 'should'}} + validator.validate(result, schema).should.be.true; + {{/is}} + {{#is assertion 'assert'}} + assert.true(validator.validate(result, schema)); + {{/is}} + done(); + }); + {{/isXmlMediaType}} {{else}} {{#is assertion 'expect'}} expect(body).to.equal(null); // non-json response or no schema @@ -70,8 +88,8 @@ {{#is assertion 'assert'}} assert.isNull(body); // non-json response or no schema {{/is}} - {{/validateResponse}} done(); + {{/validateResponse}} }); }); {{#if isLoadTest}} diff --git a/templates/request/patch/patch.handlebars b/templates/request/patch/patch.handlebars index 46f8087..1379f5d 100644 --- a/templates/request/patch/patch.handlebars +++ b/templates/request/patch/patch.handlebars @@ -54,7 +54,7 @@ body: 'XML STRING GOES HERE' }, {{/is}} - function(error, res, body) { + function(error, res{{#isNecessaryBody returnType noSchema}}, body{{/isNecessaryBody}}) { if (error) return done(error); {{#is assertion 'expect'}} @@ -80,6 +80,7 @@ {{/is}} {{#validateResponse returnType noSchema}} + {{#isJsonMediaType returnType}} {{#is assertion 'expect'}} expect(validator.validate(body, schema)).to.be.true; {{/is}} @@ -89,6 +90,23 @@ {{#is assertion 'assert'}} assert.true(validator.validate(body, schema)); {{/is}} + done(); + {{/isJsonMediaType}} + {{#isXmlMediaType returnType}} + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + {{#is assertion 'expect'}} + expect(validator.validate(body, schema)).to.be.true; + {{/is}} + {{#is assertion 'should'}} + validator.validate(body, schema).should.be.true; + {{/is}} + {{#is assertion 'assert'}} + assert.true(validator.validate(body, schema)); + {{/is}} + done(); + }); + {{/isXmlMediaType}} {{else}} {{#is assertion 'expect'}} expect(body).to.equal(null); // non-json response or no schema @@ -99,8 +117,8 @@ {{#is assertion 'assert'}} assert.isNull(body); // non-json response or no schema {{/is}} - {{/validateResponse}} done(); + {{/validateResponse}} }); }); {{#if isLoadTest}} diff --git a/templates/request/post/post.handlebars b/templates/request/post/post.handlebars index cd330b9..1211661 100644 --- a/templates/request/post/post.handlebars +++ b/templates/request/post/post.handlebars @@ -52,7 +52,7 @@ body: 'XML STRING GOES HERE' }, {{/is}} - function(error, res, body) { + function(error, res{{#isNecessaryBody returnType noSchema}}, body{{/isNecessaryBody}}) { if (error) return done(error); {{#is assertion 'expect'}} @@ -78,6 +78,7 @@ {{/is}} {{#validateResponse returnType noSchema}} + {{#isJsonMediaType returnType}} {{#is assertion 'expect'}} expect(validator.validate(body, schema)).to.be.true; {{/is}} @@ -87,6 +88,23 @@ {{#is assertion 'assert'}} assert.true(validator.validate(body, schema)); {{/is}} + done(); + {{/isJsonMediaType}} + {{#isXmlMediaType returnType}} + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + {{#is assertion 'expect'}} + expect(validator.validate(result, schema)).to.be.true; + {{/is}} + {{#is assertion 'should'}} + validator.validate(result, schema).should.be.true; + {{/is}} + {{#is assertion 'assert'}} + assert.true(validator.validate(result, schema)); + {{/is}} + done(); + }); + {{/isXmlMediaType}} {{else}} {{#is assertion 'expect'}} expect(body).to.equal(null); // non-json response or no schema @@ -97,8 +115,8 @@ {{#is assertion 'assert'}} assert.isNull(body); // non-json response or no schema {{/is}} - {{/validateResponse}} done(); + {{/validateResponse}} }); }); {{#if isLoadTest}} diff --git a/templates/request/put/put.handlebars b/templates/request/put/put.handlebars index 7df9e3e..8a96953 100644 --- a/templates/request/put/put.handlebars +++ b/templates/request/put/put.handlebars @@ -52,7 +52,7 @@ body: 'XML STRING GOES HERE' }, {{/is}} - function(error, res, body) { + function(error, res{{#isNecessaryBody returnType noSchema}}, body{{/isNecessaryBody}}) { if (error) return done(error); {{#is assertion 'expect'}} @@ -78,6 +78,7 @@ {{/is}} {{#validateResponse returnType noSchema}} + {{#isJsonMediaType returnType}} {{#is assertion 'expect'}} expect(validator.validate(body, schema)).to.be.true; {{/is}} @@ -87,6 +88,23 @@ {{#is assertion 'assert'}} assert.true(validator.validate(body, schema)); {{/is}} + done(); + {{/isJsonMediaType}} + {{#isXmlMediaType returnType}} + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + {{#is assertion 'expect'}} + expect(validator.validate(body, schema)).to.be.true; + {{/is}} + {{#is assertion 'should'}} + validator.validate(body, schema).should.be.true; + {{/is}} + {{#is assertion 'assert'}} + assert.true(validator.validate(body, schema)); + {{/is}} + done(); + }); + {{/isXmlMediaType}} {{else}} {{#is assertion 'expect'}} expect(body).to.equal(null); // non-json response or no schema @@ -97,8 +115,8 @@ {{#is assertion 'assert'}} assert.isNull(body); // non-json response or no schema {{/is}} - {{/validateResponse}} done(); + {{/validateResponse}} }); }); {{#if isLoadTest}} diff --git a/templates/supertest/delete/delete.handlebars b/templates/supertest/delete/delete.handlebars index c7b8581..df0774e 100644 --- a/templates/supertest/delete/delete.handlebars +++ b/templates/supertest/delete/delete.handlebars @@ -36,6 +36,7 @@ if (err) return done(err); {{#validateResponse returnType noSchema}} + {{#isJsonMediaType returnType}} {{#is assertion 'expect'}} expect(validator.validate(res.body, schema)).to.be.true; {{/is}} @@ -45,6 +46,23 @@ {{#is assertion 'assert'}} assert.true(validator.validate(res.body, schema)); {{/is}} + done(); + {{/isJsonMediaType}} + {{#isXmlMediaType returnType}} + parseString(res.text, function(parseErr, result) { + if(parseErr) return done(parseErr); + {{#is assertion 'expect'}} + expect(validator.validate(result, schema)).to.be.true; + {{/is}} + {{#is assertion 'should'}} + validator.validate(result, schema).should.be.true; + {{/is}} + {{#is assertion 'assert'}} + assert.true(validator.validate(result, schema)); + {{/is}} + done(); + }); + {{/isXmlMediaType}} {{else}} {{#is assertion 'expect'}} expect(res.body).to.equal(null); // non-json response or no schema @@ -55,7 +73,7 @@ {{#is assertion 'assert'}} assert.isNull(res.body); // non-json response or no schema {{/is}} - {{/validateResponse}} done(); + {{/validateResponse}} }); }); diff --git a/templates/supertest/get/get.handlebars b/templates/supertest/get/get.handlebars index 821dc4d..74a16ce 100644 --- a/templates/supertest/get/get.handlebars +++ b/templates/supertest/get/get.handlebars @@ -36,6 +36,7 @@ if (err) return done(err); {{#validateResponse returnType noSchema}} + {{#isJsonMediaType returnType}} {{#is assertion 'expect'}} expect(validator.validate(res.body, schema)).to.be.true; {{/is}} @@ -45,6 +46,23 @@ {{#is assertion 'assert'}} assert.true(validator.validate(res.body, schema)); {{/is}} + done(); + {{/isJsonMediaType}} + {{#isXmlMediaType returnType}} + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + {{#is assertion 'expect'}} + expect(validator.validate(result, schema)).to.be.true; + {{/is}} + {{#is assertion 'should'}} + validator.validate(result, schema).should.be.true; + {{/is}} + {{#is assertion 'assert'}} + assert.true(validator.validate(result, schema)); + {{/is}} + done(); + }); + {{/isXmlMediaType}} {{else}} {{#is assertion 'expect'}} expect(res.body).to.equal(null); // non-json response or no schema @@ -55,8 +73,8 @@ {{#is assertion 'assert'}} assert.isNull(res.body); // non-json response or no schema {{/is}} - {{/validateResponse}} done(); + {{/validateResponse}} }); }); {{#if isLoadTest}} diff --git a/templates/supertest/patch/patch.handlebars b/templates/supertest/patch/patch.handlebars index 6ac40e7..e4b8095 100644 --- a/templates/supertest/patch/patch.handlebars +++ b/templates/supertest/patch/patch.handlebars @@ -61,6 +61,7 @@ if (err) return done(err); {{#validateResponse returnType noSchema}} + {{#isJsonMediaType returnType}} {{#is assertion 'expect'}} expect(validator.validate(res.body, schema)).to.be.true; {{/is}} @@ -70,6 +71,23 @@ {{#is assertion 'assert'}} assert.true(validator.validate(res.body, schema)); {{/is}} + done(); + {{/isJsonMediaType}} + {{#isXmlMediaType returnType}} + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + {{#is assertion 'expect'}} + expect(validator.validate(result, schema)).to.be.true; + {{/is}} + {{#is assertion 'should'}} + validator.validate(result, schema).should.be.true; + {{/is}} + {{#is assertion 'assert'}} + assert.true(validator.validate(result, schema)); + {{/is}} + done(); + }); + {{/isXmlMediaType}} {{else}} {{#is assertion 'expect'}} expect(res.body).to.equal(null); // non-json response or no schema @@ -80,8 +98,8 @@ {{#is assertion 'assert'}} assert.isNull(res.body); // non-json response or no schema {{/is}} - {{/validateResponse}} done(); +{{/validateResponse}} }); }); {{#if isLoadTest}} diff --git a/templates/supertest/post/post.handlebars b/templates/supertest/post/post.handlebars index 2c2087e..87da1a7 100644 --- a/templates/supertest/post/post.handlebars +++ b/templates/supertest/post/post.handlebars @@ -60,6 +60,7 @@ if (err) return done(err); {{#validateResponse returnType noSchema}} + {{#isJsonMediaType returnType}} {{#is assertion 'expect'}} expect(validator.validate(res.body, schema)).to.be.true; {{/is}} @@ -69,6 +70,23 @@ {{#is assertion 'assert'}} assert.true(validator.validate(res.body, schema)); {{/is}} + done(); + {{/isJsonMediaType}} + {{#isXmlMediaType returnType}} + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + {{#is assertion 'expect'}} + expect(validator.validate(result, schema)).to.be.true; + {{/is}} + {{#is assertion 'should'}} + validator.validate(result, schema).should.be.true; + {{/is}} + {{#is assertion 'assert'}} + assert.true(validator.validate(result, schema)); + {{/is}} + done(); + }); + {{/isXmlMediaType}} {{else}} {{#is assertion 'expect'}} expect(res.body).to.equal(null); // non-json response or no schema @@ -79,8 +97,8 @@ {{#is assertion 'assert'}} assert.isNull(res.body); // non-json response or no schema {{/is}} - {{/validateResponse}} done(); + {{/validateResponse}} }); }); {{#if isLoadTest}} diff --git a/templates/supertest/put/put.handlebars b/templates/supertest/put/put.handlebars index 2a93d88..d0e8425 100644 --- a/templates/supertest/put/put.handlebars +++ b/templates/supertest/put/put.handlebars @@ -60,6 +60,7 @@ if (err) return done(err); {{#validateResponse returnType noSchema}} + {{#isJsonMediaType returnType}} {{#is assertion 'expect'}} expect(validator.validate(res.body, schema)).to.be.true; {{/is}} @@ -69,6 +70,23 @@ {{#is assertion 'assert'}} assert.true(validator.validate(res.body, schema)); {{/is}} + done(); + {{/isJsonMediaType}} + {{#isXmlMediaType returnType}} + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + {{#is assertion 'expect'}} + expect(validator.validate(result, schema)).to.be.true; + {{/is}} + {{#is assertion 'should'}} + validator.validate(result, schema).should.be.true; + {{/is}} + {{#is assertion 'assert'}} + assert.true(validator.validate(result, schema)); + {{/is}} + done(); + }); + {{/isXmlMediaType}} {{else}} {{#is assertion 'expect'}} expect(res.body).to.equal(null); // non-json response or no schema @@ -79,8 +97,8 @@ {{#is assertion 'assert'}} assert.isNull(res.body); // non-json response or no schema {{/is}} - {{/validateResponse}} done(); + {{/validateResponse}} }); }); {{#if isLoadTest}} diff --git a/test/jsonProperty/test.js b/test/jsonProperty/test.js index 6c4b23c..4f570cd 100644 --- a/test/jsonProperty/test.js +++ b/test/jsonProperty/test.js @@ -48,7 +48,7 @@ describe('json property', function() { }); }); - describe('when set to non-json media type', function() { + describe('when set to non-json media type and no schema is defined', function() { describe('expect', function() { var output1 = testGen(swaggerNonJson, { assertionFormat: 'expect', diff --git a/test/xmlConsumeTypeTest/compare/request/assert/.env b/test/xmlConsumeTypeTest/compare/request/assert/.env new file mode 100644 index 0000000..bb56aba --- /dev/null +++ b/test/xmlConsumeTypeTest/compare/request/assert/.env @@ -0,0 +1,4 @@ +OAUTH=YOUR_TOKEN_GOES_HERE +KEY=YOUR_TOKEN_GOES_HERE +BASIC_AUTH=YOUR_TOKEN_GOES_HERE + diff --git a/test/xmlConsumeTypeTest/compare/request/assert/base-path-test.js b/test/xmlConsumeTypeTest/compare/request/assert/base-path-test.js new file mode 100644 index 0000000..84a05bf --- /dev/null +++ b/test/xmlConsumeTypeTest/compare/request/assert/base-path-test.js @@ -0,0 +1,303 @@ +'use strict'; +var parseString = require('xml2js').parseString; +var chai = require('chai'); +var ZSchema = require('z-schema'); +var customFormats = module.exports = function(zSchema) { + // Placeholder file for all custom-formats in known to swagger.json + // as found on + // https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#dataTypeFormat + + var decimalPattern = /^\d{0,8}.?\d{0,4}[0]+$/; + + /** Validates floating point as decimal / money (i.e: 12345678.123400..) */ + zSchema.registerFormat('double', function(val) { + return !decimalPattern.test(val.toString()); + }); + + /** Validates value is a 32bit integer */ + zSchema.registerFormat('int32', function(val) { + // the 32bit shift (>>) truncates any bits beyond max of 32 + return Number.isInteger(val) && ((val >> 0) === val); + }); + + zSchema.registerFormat('int64', function(val) { + return Number.isInteger(val); + }); + + zSchema.registerFormat('float', function(val) { + // better parsing for custom "float" format + if (Number.parseFloat(val)) { + return true; + } else { + return false; + } + }); + + zSchema.registerFormat('date', function(val) { + // should parse a a date + return !isNaN(Date.parse(val)); + }); + + zSchema.registerFormat('dateTime', function(val) { + return !isNaN(Date.parse(val)); + }); + + zSchema.registerFormat('password', function(val) { + // should parse as a string + return typeof val === 'string'; + }); +}; + +customFormats(ZSchema); + +var validator = new ZSchema({}); +var request = require('request'); +var assert = chai.assert; + +require('dotenv').load(); + +describe('/', function() { + describe('get', function() { + it('should respond with 200 OK', function(done) { + /*eslint-disable*/ + var schema = { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "username": { + "type": "string" + } + } + }; + + /*eslint-enable*/ + request({ + url: 'https://api.uber.com/', + json: true, + qs: { + accessToken: process.env.KEY + }, + method: 'GET', + headers: { + 'Content-Type': 'application/json' + } + }, + function(error, res) { + if (error) return done(error); + + assert.equal(res.statusCode, 200); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + assert.true(validator.validate(result, schema)); + done(); + }); + }); + }); + + it('should respond with 400 NOT OK', function(done) { + /*eslint-disable*/ + var schema = { + "type": "object", + "properties": { + "meta": "string", + "data": "number" + } + }; + + /*eslint-enable*/ + request({ + url: 'https://api.uber.com/', + json: true, + qs: { + accessToken: process.env.KEY + }, + method: 'GET', + headers: { + 'Content-Type': 'application/json' + } + }, + function(error, res) { + if (error) return done(error); + + assert.equal(res.statusCode, 400); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + assert.true(validator.validate(result, schema)); + done(); + }); + }); + }); + + it('should respond with 500 SERVER ERROR', function(done) { + /*eslint-disable*/ + var schema = { + "properties": { + "meta": "string", + "data": "number", + "UserObj": { + "schema": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "username": { + "type": "string" + } + } + } + } + } + }; + + /*eslint-enable*/ + request({ + url: 'https://api.uber.com/', + json: true, + qs: { + accessToken: process.env.KEY + }, + method: 'GET', + headers: { + 'Content-Type': 'application/json' + } + }, + function(error, res) { + if (error) return done(error); + + assert.equal(res.statusCode, 500); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + assert.true(validator.validate(result, schema)); + done(); + }); + }); + }); + + }); + + describe('post', function() { + it('should respond with 200 OK', function(done) { + /*eslint-disable*/ + var schema = { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "username": { + "type": "string" + } + } + } + }; + + /*eslint-enable*/ + request({ + url: 'https://api.uber.com/', + json: true, + qs: { + longitude: 'DATA GOES HERE' + }, + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-latitude': 'DATA GOES HERE', + Authorization: 'Bearer ' + process.env.OAUTH + }, + body: { + } + }, + function(error, res) { + if (error) return done(error); + + assert.equal(res.statusCode, 200); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + assert.true(validator.validate(result, schema)); + done(); + }); + }); + }); + + it('should respond with 400 NOT OK', function(done) { + /*eslint-disable*/ + var schema = { + "type": "number" + }; + + /*eslint-enable*/ + request({ + url: 'https://api.uber.com/', + json: true, + qs: { + longitude: 'DATA GOES HERE' + }, + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-latitude': 'DATA GOES HERE', + Authorization: 'Bearer ' + process.env.OAUTH + }, + body: { + } + }, + function(error, res) { + if (error) return done(error); + + assert.equal(res.statusCode, 400); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + assert.true(validator.validate(result, schema)); + done(); + }); + }); + }); + + it('should respond with 500 SERVER ERROR', function(done) { + /*eslint-disable*/ + var schema = { + "type": "string" + }; + + /*eslint-enable*/ + request({ + url: 'https://api.uber.com/', + json: true, + qs: { + longitude: 'DATA GOES HERE' + }, + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-latitude': 'DATA GOES HERE', + Authorization: 'Bearer ' + process.env.OAUTH + }, + body: { + } + }, + function(error, res) { + if (error) return done(error); + + assert.equal(res.statusCode, 500); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + assert.true(validator.validate(result, schema)); + done(); + }); + }); + }); + + }); + +}); diff --git a/test/xmlConsumeTypeTest/compare/request/expect/.env b/test/xmlConsumeTypeTest/compare/request/expect/.env new file mode 100644 index 0000000..bb56aba --- /dev/null +++ b/test/xmlConsumeTypeTest/compare/request/expect/.env @@ -0,0 +1,4 @@ +OAUTH=YOUR_TOKEN_GOES_HERE +KEY=YOUR_TOKEN_GOES_HERE +BASIC_AUTH=YOUR_TOKEN_GOES_HERE + diff --git a/test/xmlConsumeTypeTest/compare/request/expect/base-path-test.js b/test/xmlConsumeTypeTest/compare/request/expect/base-path-test.js new file mode 100644 index 0000000..703aeba --- /dev/null +++ b/test/xmlConsumeTypeTest/compare/request/expect/base-path-test.js @@ -0,0 +1,303 @@ +'use strict'; +var parseString = require('xml2js').parseString; +var chai = require('chai'); +var ZSchema = require('z-schema'); +var customFormats = module.exports = function(zSchema) { + // Placeholder file for all custom-formats in known to swagger.json + // as found on + // https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#dataTypeFormat + + var decimalPattern = /^\d{0,8}.?\d{0,4}[0]+$/; + + /** Validates floating point as decimal / money (i.e: 12345678.123400..) */ + zSchema.registerFormat('double', function(val) { + return !decimalPattern.test(val.toString()); + }); + + /** Validates value is a 32bit integer */ + zSchema.registerFormat('int32', function(val) { + // the 32bit shift (>>) truncates any bits beyond max of 32 + return Number.isInteger(val) && ((val >> 0) === val); + }); + + zSchema.registerFormat('int64', function(val) { + return Number.isInteger(val); + }); + + zSchema.registerFormat('float', function(val) { + // better parsing for custom "float" format + if (Number.parseFloat(val)) { + return true; + } else { + return false; + } + }); + + zSchema.registerFormat('date', function(val) { + // should parse a a date + return !isNaN(Date.parse(val)); + }); + + zSchema.registerFormat('dateTime', function(val) { + return !isNaN(Date.parse(val)); + }); + + zSchema.registerFormat('password', function(val) { + // should parse as a string + return typeof val === 'string'; + }); +}; + +customFormats(ZSchema); + +var validator = new ZSchema({}); +var request = require('request'); +var expect = chai.expect; + +require('dotenv').load(); + +describe('/', function() { + describe('get', function() { + it('should respond with 200 OK', function(done) { + /*eslint-disable*/ + var schema = { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "username": { + "type": "string" + } + } + }; + + /*eslint-enable*/ + request({ + url: 'https://api.uber.com/', + json: true, + qs: { + accessToken: process.env.KEY + }, + method: 'GET', + headers: { + 'Content-Type': 'application/json' + } + }, + function(error, res) { + if (error) return done(error); + + expect(res.statusCode).to.equal(200); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + expect(validator.validate(result, schema)).to.be.true; + done(); + }); + }); + }); + + it('should respond with 400 NOT OK', function(done) { + /*eslint-disable*/ + var schema = { + "type": "object", + "properties": { + "meta": "string", + "data": "number" + } + }; + + /*eslint-enable*/ + request({ + url: 'https://api.uber.com/', + json: true, + qs: { + accessToken: process.env.KEY + }, + method: 'GET', + headers: { + 'Content-Type': 'application/json' + } + }, + function(error, res) { + if (error) return done(error); + + expect(res.statusCode).to.equal(400); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + expect(validator.validate(result, schema)).to.be.true; + done(); + }); + }); + }); + + it('should respond with 500 SERVER ERROR', function(done) { + /*eslint-disable*/ + var schema = { + "properties": { + "meta": "string", + "data": "number", + "UserObj": { + "schema": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "username": { + "type": "string" + } + } + } + } + } + }; + + /*eslint-enable*/ + request({ + url: 'https://api.uber.com/', + json: true, + qs: { + accessToken: process.env.KEY + }, + method: 'GET', + headers: { + 'Content-Type': 'application/json' + } + }, + function(error, res) { + if (error) return done(error); + + expect(res.statusCode).to.equal(500); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + expect(validator.validate(result, schema)).to.be.true; + done(); + }); + }); + }); + + }); + + describe('post', function() { + it('should respond with 200 OK', function(done) { + /*eslint-disable*/ + var schema = { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "username": { + "type": "string" + } + } + } + }; + + /*eslint-enable*/ + request({ + url: 'https://api.uber.com/', + json: true, + qs: { + longitude: 'DATA GOES HERE' + }, + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-latitude': 'DATA GOES HERE', + Authorization: 'Bearer ' + process.env.OAUTH + }, + body: { + } + }, + function(error, res) { + if (error) return done(error); + + expect(res.statusCode).to.equal(200); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + expect(validator.validate(result, schema)).to.be.true; + done(); + }); + }); + }); + + it('should respond with 400 NOT OK', function(done) { + /*eslint-disable*/ + var schema = { + "type": "number" + }; + + /*eslint-enable*/ + request({ + url: 'https://api.uber.com/', + json: true, + qs: { + longitude: 'DATA GOES HERE' + }, + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-latitude': 'DATA GOES HERE', + Authorization: 'Bearer ' + process.env.OAUTH + }, + body: { + } + }, + function(error, res) { + if (error) return done(error); + + expect(res.statusCode).to.equal(400); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + expect(validator.validate(result, schema)).to.be.true; + done(); + }); + }); + }); + + it('should respond with 500 SERVER ERROR', function(done) { + /*eslint-disable*/ + var schema = { + "type": "string" + }; + + /*eslint-enable*/ + request({ + url: 'https://api.uber.com/', + json: true, + qs: { + longitude: 'DATA GOES HERE' + }, + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-latitude': 'DATA GOES HERE', + Authorization: 'Bearer ' + process.env.OAUTH + }, + body: { + } + }, + function(error, res) { + if (error) return done(error); + + expect(res.statusCode).to.equal(500); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + expect(validator.validate(result, schema)).to.be.true; + done(); + }); + }); + }); + + }); + +}); diff --git a/test/xmlConsumeTypeTest/compare/request/should/.env b/test/xmlConsumeTypeTest/compare/request/should/.env new file mode 100644 index 0000000..bb56aba --- /dev/null +++ b/test/xmlConsumeTypeTest/compare/request/should/.env @@ -0,0 +1,4 @@ +OAUTH=YOUR_TOKEN_GOES_HERE +KEY=YOUR_TOKEN_GOES_HERE +BASIC_AUTH=YOUR_TOKEN_GOES_HERE + diff --git a/test/xmlConsumeTypeTest/compare/request/should/base-path-test.js b/test/xmlConsumeTypeTest/compare/request/should/base-path-test.js new file mode 100644 index 0000000..834ac99 --- /dev/null +++ b/test/xmlConsumeTypeTest/compare/request/should/base-path-test.js @@ -0,0 +1,304 @@ +'use strict'; +var parseString = require('xml2js').parseString; +var chai = require('chai'); +var ZSchema = require('z-schema'); +var customFormats = module.exports = function(zSchema) { + // Placeholder file for all custom-formats in known to swagger.json + // as found on + // https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#dataTypeFormat + + var decimalPattern = /^\d{0,8}.?\d{0,4}[0]+$/; + + /** Validates floating point as decimal / money (i.e: 12345678.123400..) */ + zSchema.registerFormat('double', function(val) { + return !decimalPattern.test(val.toString()); + }); + + /** Validates value is a 32bit integer */ + zSchema.registerFormat('int32', function(val) { + // the 32bit shift (>>) truncates any bits beyond max of 32 + return Number.isInteger(val) && ((val >> 0) === val); + }); + + zSchema.registerFormat('int64', function(val) { + return Number.isInteger(val); + }); + + zSchema.registerFormat('float', function(val) { + // better parsing for custom "float" format + if (Number.parseFloat(val)) { + return true; + } else { + return false; + } + }); + + zSchema.registerFormat('date', function(val) { + // should parse a a date + return !isNaN(Date.parse(val)); + }); + + zSchema.registerFormat('dateTime', function(val) { + return !isNaN(Date.parse(val)); + }); + + zSchema.registerFormat('password', function(val) { + // should parse as a string + return typeof val === 'string'; + }); +}; + +customFormats(ZSchema); + +var validator = new ZSchema({}); +var request = require('request'); + +chai.should(); + +require('dotenv').load(); + +describe('/', function() { + describe('get', function() { + it('should respond with 200 OK', function(done) { + /*eslint-disable*/ + var schema = { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "username": { + "type": "string" + } + } + }; + + /*eslint-enable*/ + request({ + url: 'https://api.uber.com/', + json: true, + qs: { + accessToken: process.env.KEY + }, + method: 'GET', + headers: { + 'Content-Type': 'application/json' + } + }, + function(error, res) { + if (error) return done(error); + + res.statusCode.should.equal(200); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + validator.validate(result, schema).should.be.true; + done(); + }); + }); + }); + + it('should respond with 400 NOT OK', function(done) { + /*eslint-disable*/ + var schema = { + "type": "object", + "properties": { + "meta": "string", + "data": "number" + } + }; + + /*eslint-enable*/ + request({ + url: 'https://api.uber.com/', + json: true, + qs: { + accessToken: process.env.KEY + }, + method: 'GET', + headers: { + 'Content-Type': 'application/json' + } + }, + function(error, res) { + if (error) return done(error); + + res.statusCode.should.equal(400); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + validator.validate(result, schema).should.be.true; + done(); + }); + }); + }); + + it('should respond with 500 SERVER ERROR', function(done) { + /*eslint-disable*/ + var schema = { + "properties": { + "meta": "string", + "data": "number", + "UserObj": { + "schema": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "username": { + "type": "string" + } + } + } + } + } + }; + + /*eslint-enable*/ + request({ + url: 'https://api.uber.com/', + json: true, + qs: { + accessToken: process.env.KEY + }, + method: 'GET', + headers: { + 'Content-Type': 'application/json' + } + }, + function(error, res) { + if (error) return done(error); + + res.statusCode.should.equal(500); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + validator.validate(result, schema).should.be.true; + done(); + }); + }); + }); + + }); + + describe('post', function() { + it('should respond with 200 OK', function(done) { + /*eslint-disable*/ + var schema = { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "username": { + "type": "string" + } + } + } + }; + + /*eslint-enable*/ + request({ + url: 'https://api.uber.com/', + json: true, + qs: { + longitude: 'DATA GOES HERE' + }, + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-latitude': 'DATA GOES HERE', + Authorization: 'Bearer ' + process.env.OAUTH + }, + body: { + } + }, + function(error, res) { + if (error) return done(error); + + res.statusCode.should.equal(200); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + validator.validate(result, schema).should.be.true; + done(); + }); + }); + }); + + it('should respond with 400 NOT OK', function(done) { + /*eslint-disable*/ + var schema = { + "type": "number" + }; + + /*eslint-enable*/ + request({ + url: 'https://api.uber.com/', + json: true, + qs: { + longitude: 'DATA GOES HERE' + }, + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-latitude': 'DATA GOES HERE', + Authorization: 'Bearer ' + process.env.OAUTH + }, + body: { + } + }, + function(error, res) { + if (error) return done(error); + + res.statusCode.should.equal(400); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + validator.validate(result, schema).should.be.true; + done(); + }); + }); + }); + + it('should respond with 500 SERVER ERROR', function(done) { + /*eslint-disable*/ + var schema = { + "type": "string" + }; + + /*eslint-enable*/ + request({ + url: 'https://api.uber.com/', + json: true, + qs: { + longitude: 'DATA GOES HERE' + }, + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-latitude': 'DATA GOES HERE', + Authorization: 'Bearer ' + process.env.OAUTH + }, + body: { + } + }, + function(error, res) { + if (error) return done(error); + + res.statusCode.should.equal(500); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + validator.validate(result, schema).should.be.true; + done(); + }); + }); + }); + + }); + +}); diff --git a/test/xmlConsumeTypeTest/compare/supertest/assert/.env b/test/xmlConsumeTypeTest/compare/supertest/assert/.env new file mode 100644 index 0000000..bb56aba --- /dev/null +++ b/test/xmlConsumeTypeTest/compare/supertest/assert/.env @@ -0,0 +1,4 @@ +OAUTH=YOUR_TOKEN_GOES_HERE +KEY=YOUR_TOKEN_GOES_HERE +BASIC_AUTH=YOUR_TOKEN_GOES_HERE + diff --git a/test/xmlConsumeTypeTest/compare/supertest/assert/base-path-test.js b/test/xmlConsumeTypeTest/compare/supertest/assert/base-path-test.js new file mode 100644 index 0000000..0857f45 --- /dev/null +++ b/test/xmlConsumeTypeTest/compare/supertest/assert/base-path-test.js @@ -0,0 +1,268 @@ +'use strict'; +var parseString = require('xml2js').parseString; +var chai = require('chai'); +var ZSchema = require('z-schema'); +var customFormats = module.exports = function(zSchema) { + // Placeholder file for all custom-formats in known to swagger.json + // as found on + // https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#dataTypeFormat + + var decimalPattern = /^\d{0,8}.?\d{0,4}[0]+$/; + + /** Validates floating point as decimal / money (i.e: 12345678.123400..) */ + zSchema.registerFormat('double', function(val) { + return !decimalPattern.test(val.toString()); + }); + + /** Validates value is a 32bit integer */ + zSchema.registerFormat('int32', function(val) { + // the 32bit shift (>>) truncates any bits beyond max of 32 + return Number.isInteger(val) && ((val >> 0) === val); + }); + + zSchema.registerFormat('int64', function(val) { + return Number.isInteger(val); + }); + + zSchema.registerFormat('float', function(val) { + // better parsing for custom "float" format + if (Number.parseFloat(val)) { + return true; + } else { + return false; + } + }); + + zSchema.registerFormat('date', function(val) { + // should parse a a date + return !isNaN(Date.parse(val)); + }); + + zSchema.registerFormat('dateTime', function(val) { + return !isNaN(Date.parse(val)); + }); + + zSchema.registerFormat('password', function(val) { + // should parse as a string + return typeof val === 'string'; + }); +}; + +customFormats(ZSchema); + +var validator = new ZSchema({}); +var supertest = require('supertest'); +var api = supertest('https://api.uber.com'); // supertest init; +var assert = chai.assert; + +require('dotenv').load(); + +describe('/', function() { + describe('get', function() { + it('should respond with 200 OK', function(done) { + /*eslint-disable*/ + var schema = { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "username": { + "type": "string" + } + } + }; + + /*eslint-enable*/ + api.get('/') + .query({ + accessToken: process.env.KEY + }) + .set('Content-Type', 'application/json') + .expect(200) + .end(function(err, res) { + if (err) return done(err); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + assert.true(validator.validate(result, schema)); + done(); + }); + }); + }); + + it('should respond with 400 NOT OK', function(done) { + /*eslint-disable*/ + var schema = { + "type": "object", + "properties": { + "meta": "string", + "data": "number" + } + }; + + /*eslint-enable*/ + api.get('/') + .query({ + accessToken: process.env.KEY + }) + .set('Content-Type', 'application/json') + .expect(400) + .end(function(err, res) { + if (err) return done(err); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + assert.true(validator.validate(result, schema)); + done(); + }); + }); + }); + + it('should respond with 500 SERVER ERROR', function(done) { + /*eslint-disable*/ + var schema = { + "properties": { + "meta": "string", + "data": "number", + "UserObj": { + "schema": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "username": { + "type": "string" + } + } + } + } + } + }; + + /*eslint-enable*/ + api.get('/') + .query({ + accessToken: process.env.KEY + }) + .set('Content-Type', 'application/json') + .expect(500) + .end(function(err, res) { + if (err) return done(err); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + assert.true(validator.validate(result, schema)); + done(); + }); + }); + }); + + }); + + describe('post', function() { + it('should respond with 200 OK', function(done) { + /*eslint-disable*/ + var schema = { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "username": { + "type": "string" + } + } + } + }; + + /*eslint-enable*/ + api.post('/') + .query({ + longitude: 'DATA GOES HERE' + }) + .set('Authorization', 'Bearer ' + process.env.OAUTH) + .set('Content-Type', 'application/json') + .set({ + 'X-latitude': 'DATA GOES HERE' + }) + .send({ + }) + .expect(200) + .end(function(err, res) { + if (err) return done(err); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + assert.true(validator.validate(result, schema)); + done(); + }); + }); + }); + + it('should respond with 400 NOT OK', function(done) { + /*eslint-disable*/ + var schema = { + "type": "number" + }; + + /*eslint-enable*/ + api.post('/') + .query({ + longitude: 'DATA GOES HERE' + }) + .set('Authorization', 'Bearer ' + process.env.OAUTH) + .set('Content-Type', 'application/json') + .set({ + 'X-latitude': 'DATA GOES HERE' + }) + .send({ + }) + .expect(400) + .end(function(err, res) { + if (err) return done(err); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + assert.true(validator.validate(result, schema)); + done(); + }); + }); + }); + + it('should respond with 500 SERVER ERROR', function(done) { + /*eslint-disable*/ + var schema = { + "type": "string" + }; + + /*eslint-enable*/ + api.post('/') + .query({ + longitude: 'DATA GOES HERE' + }) + .set('Authorization', 'Bearer ' + process.env.OAUTH) + .set('Content-Type', 'application/json') + .set({ + 'X-latitude': 'DATA GOES HERE' + }) + .send({ + }) + .expect(500) + .end(function(err, res) { + if (err) return done(err); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + assert.true(validator.validate(result, schema)); + done(); + }); + }); + }); + + }); + +}); diff --git a/test/xmlConsumeTypeTest/compare/supertest/expect/.env b/test/xmlConsumeTypeTest/compare/supertest/expect/.env new file mode 100644 index 0000000..bb56aba --- /dev/null +++ b/test/xmlConsumeTypeTest/compare/supertest/expect/.env @@ -0,0 +1,4 @@ +OAUTH=YOUR_TOKEN_GOES_HERE +KEY=YOUR_TOKEN_GOES_HERE +BASIC_AUTH=YOUR_TOKEN_GOES_HERE + diff --git a/test/xmlConsumeTypeTest/compare/supertest/expect/base-path-test.js b/test/xmlConsumeTypeTest/compare/supertest/expect/base-path-test.js new file mode 100644 index 0000000..adee93d --- /dev/null +++ b/test/xmlConsumeTypeTest/compare/supertest/expect/base-path-test.js @@ -0,0 +1,268 @@ +'use strict'; +var parseString = require('xml2js').parseString; +var chai = require('chai'); +var ZSchema = require('z-schema'); +var customFormats = module.exports = function(zSchema) { + // Placeholder file for all custom-formats in known to swagger.json + // as found on + // https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#dataTypeFormat + + var decimalPattern = /^\d{0,8}.?\d{0,4}[0]+$/; + + /** Validates floating point as decimal / money (i.e: 12345678.123400..) */ + zSchema.registerFormat('double', function(val) { + return !decimalPattern.test(val.toString()); + }); + + /** Validates value is a 32bit integer */ + zSchema.registerFormat('int32', function(val) { + // the 32bit shift (>>) truncates any bits beyond max of 32 + return Number.isInteger(val) && ((val >> 0) === val); + }); + + zSchema.registerFormat('int64', function(val) { + return Number.isInteger(val); + }); + + zSchema.registerFormat('float', function(val) { + // better parsing for custom "float" format + if (Number.parseFloat(val)) { + return true; + } else { + return false; + } + }); + + zSchema.registerFormat('date', function(val) { + // should parse a a date + return !isNaN(Date.parse(val)); + }); + + zSchema.registerFormat('dateTime', function(val) { + return !isNaN(Date.parse(val)); + }); + + zSchema.registerFormat('password', function(val) { + // should parse as a string + return typeof val === 'string'; + }); +}; + +customFormats(ZSchema); + +var validator = new ZSchema({}); +var supertest = require('supertest'); +var api = supertest('https://api.uber.com'); // supertest init; +var expect = chai.expect; + +require('dotenv').load(); + +describe('/', function() { + describe('get', function() { + it('should respond with 200 OK', function(done) { + /*eslint-disable*/ + var schema = { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "username": { + "type": "string" + } + } + }; + + /*eslint-enable*/ + api.get('/') + .query({ + accessToken: process.env.KEY + }) + .set('Content-Type', 'application/json') + .expect(200) + .end(function(err, res) { + if (err) return done(err); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + expect(validator.validate(result, schema)).to.be.true; + done(); + }); + }); + }); + + it('should respond with 400 NOT OK', function(done) { + /*eslint-disable*/ + var schema = { + "type": "object", + "properties": { + "meta": "string", + "data": "number" + } + }; + + /*eslint-enable*/ + api.get('/') + .query({ + accessToken: process.env.KEY + }) + .set('Content-Type', 'application/json') + .expect(400) + .end(function(err, res) { + if (err) return done(err); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + expect(validator.validate(result, schema)).to.be.true; + done(); + }); + }); + }); + + it('should respond with 500 SERVER ERROR', function(done) { + /*eslint-disable*/ + var schema = { + "properties": { + "meta": "string", + "data": "number", + "UserObj": { + "schema": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "username": { + "type": "string" + } + } + } + } + } + }; + + /*eslint-enable*/ + api.get('/') + .query({ + accessToken: process.env.KEY + }) + .set('Content-Type', 'application/json') + .expect(500) + .end(function(err, res) { + if (err) return done(err); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + expect(validator.validate(result, schema)).to.be.true; + done(); + }); + }); + }); + + }); + + describe('post', function() { + it('should respond with 200 OK', function(done) { + /*eslint-disable*/ + var schema = { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "username": { + "type": "string" + } + } + } + }; + + /*eslint-enable*/ + api.post('/') + .query({ + longitude: 'DATA GOES HERE' + }) + .set('Authorization', 'Bearer ' + process.env.OAUTH) + .set('Content-Type', 'application/json') + .set({ + 'X-latitude': 'DATA GOES HERE' + }) + .send({ + }) + .expect(200) + .end(function(err, res) { + if (err) return done(err); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + expect(validator.validate(result, schema)).to.be.true; + done(); + }); + }); + }); + + it('should respond with 400 NOT OK', function(done) { + /*eslint-disable*/ + var schema = { + "type": "number" + }; + + /*eslint-enable*/ + api.post('/') + .query({ + longitude: 'DATA GOES HERE' + }) + .set('Authorization', 'Bearer ' + process.env.OAUTH) + .set('Content-Type', 'application/json') + .set({ + 'X-latitude': 'DATA GOES HERE' + }) + .send({ + }) + .expect(400) + .end(function(err, res) { + if (err) return done(err); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + expect(validator.validate(result, schema)).to.be.true; + done(); + }); + }); + }); + + it('should respond with 500 SERVER ERROR', function(done) { + /*eslint-disable*/ + var schema = { + "type": "string" + }; + + /*eslint-enable*/ + api.post('/') + .query({ + longitude: 'DATA GOES HERE' + }) + .set('Authorization', 'Bearer ' + process.env.OAUTH) + .set('Content-Type', 'application/json') + .set({ + 'X-latitude': 'DATA GOES HERE' + }) + .send({ + }) + .expect(500) + .end(function(err, res) { + if (err) return done(err); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + expect(validator.validate(result, schema)).to.be.true; + done(); + }); + }); + }); + + }); + +}); diff --git a/test/xmlConsumeTypeTest/compare/supertest/should/.env b/test/xmlConsumeTypeTest/compare/supertest/should/.env new file mode 100644 index 0000000..bb56aba --- /dev/null +++ b/test/xmlConsumeTypeTest/compare/supertest/should/.env @@ -0,0 +1,4 @@ +OAUTH=YOUR_TOKEN_GOES_HERE +KEY=YOUR_TOKEN_GOES_HERE +BASIC_AUTH=YOUR_TOKEN_GOES_HERE + diff --git a/test/xmlConsumeTypeTest/compare/supertest/should/base-path-test.js b/test/xmlConsumeTypeTest/compare/supertest/should/base-path-test.js new file mode 100644 index 0000000..b1600e3 --- /dev/null +++ b/test/xmlConsumeTypeTest/compare/supertest/should/base-path-test.js @@ -0,0 +1,269 @@ +'use strict'; +var parseString = require('xml2js').parseString; +var chai = require('chai'); +var ZSchema = require('z-schema'); +var customFormats = module.exports = function(zSchema) { + // Placeholder file for all custom-formats in known to swagger.json + // as found on + // https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#dataTypeFormat + + var decimalPattern = /^\d{0,8}.?\d{0,4}[0]+$/; + + /** Validates floating point as decimal / money (i.e: 12345678.123400..) */ + zSchema.registerFormat('double', function(val) { + return !decimalPattern.test(val.toString()); + }); + + /** Validates value is a 32bit integer */ + zSchema.registerFormat('int32', function(val) { + // the 32bit shift (>>) truncates any bits beyond max of 32 + return Number.isInteger(val) && ((val >> 0) === val); + }); + + zSchema.registerFormat('int64', function(val) { + return Number.isInteger(val); + }); + + zSchema.registerFormat('float', function(val) { + // better parsing for custom "float" format + if (Number.parseFloat(val)) { + return true; + } else { + return false; + } + }); + + zSchema.registerFormat('date', function(val) { + // should parse a a date + return !isNaN(Date.parse(val)); + }); + + zSchema.registerFormat('dateTime', function(val) { + return !isNaN(Date.parse(val)); + }); + + zSchema.registerFormat('password', function(val) { + // should parse as a string + return typeof val === 'string'; + }); +}; + +customFormats(ZSchema); + +var validator = new ZSchema({}); +var supertest = require('supertest'); +var api = supertest('https://api.uber.com'); // supertest init; + +chai.should(); + +require('dotenv').load(); + +describe('/', function() { + describe('get', function() { + it('should respond with 200 OK', function(done) { + /*eslint-disable*/ + var schema = { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "username": { + "type": "string" + } + } + }; + + /*eslint-enable*/ + api.get('/') + .query({ + accessToken: process.env.KEY + }) + .set('Content-Type', 'application/json') + .expect(200) + .end(function(err, res) { + if (err) return done(err); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + validator.validate(result, schema).should.be.true; + done(); + }); + }); + }); + + it('should respond with 400 NOT OK', function(done) { + /*eslint-disable*/ + var schema = { + "type": "object", + "properties": { + "meta": "string", + "data": "number" + } + }; + + /*eslint-enable*/ + api.get('/') + .query({ + accessToken: process.env.KEY + }) + .set('Content-Type', 'application/json') + .expect(400) + .end(function(err, res) { + if (err) return done(err); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + validator.validate(result, schema).should.be.true; + done(); + }); + }); + }); + + it('should respond with 500 SERVER ERROR', function(done) { + /*eslint-disable*/ + var schema = { + "properties": { + "meta": "string", + "data": "number", + "UserObj": { + "schema": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "username": { + "type": "string" + } + } + } + } + } + }; + + /*eslint-enable*/ + api.get('/') + .query({ + accessToken: process.env.KEY + }) + .set('Content-Type', 'application/json') + .expect(500) + .end(function(err, res) { + if (err) return done(err); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + validator.validate(result, schema).should.be.true; + done(); + }); + }); + }); + + }); + + describe('post', function() { + it('should respond with 200 OK', function(done) { + /*eslint-disable*/ + var schema = { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "username": { + "type": "string" + } + } + } + }; + + /*eslint-enable*/ + api.post('/') + .query({ + longitude: 'DATA GOES HERE' + }) + .set('Authorization', 'Bearer ' + process.env.OAUTH) + .set('Content-Type', 'application/json') + .set({ + 'X-latitude': 'DATA GOES HERE' + }) + .send({ + }) + .expect(200) + .end(function(err, res) { + if (err) return done(err); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + validator.validate(result, schema).should.be.true; + done(); + }); + }); + }); + + it('should respond with 400 NOT OK', function(done) { + /*eslint-disable*/ + var schema = { + "type": "number" + }; + + /*eslint-enable*/ + api.post('/') + .query({ + longitude: 'DATA GOES HERE' + }) + .set('Authorization', 'Bearer ' + process.env.OAUTH) + .set('Content-Type', 'application/json') + .set({ + 'X-latitude': 'DATA GOES HERE' + }) + .send({ + }) + .expect(400) + .end(function(err, res) { + if (err) return done(err); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + validator.validate(result, schema).should.be.true; + done(); + }); + }); + }); + + it('should respond with 500 SERVER ERROR', function(done) { + /*eslint-disable*/ + var schema = { + "type": "string" + }; + + /*eslint-enable*/ + api.post('/') + .query({ + longitude: 'DATA GOES HERE' + }) + .set('Authorization', 'Bearer ' + process.env.OAUTH) + .set('Content-Type', 'application/json') + .set({ + 'X-latitude': 'DATA GOES HERE' + }) + .send({ + }) + .expect(500) + .end(function(err, res) { + if (err) return done(err); + + parseString(res.text, function(parseErr, result) { + if (parseErr) return done(parseErr); + validator.validate(result, schema).should.be.true; + done(); + }); + }); + }); + + }); + +}); diff --git a/test/xmlConsumeTypeTest/swagger.json b/test/xmlConsumeTypeTest/swagger.json new file mode 100644 index 0000000..1a465fc --- /dev/null +++ b/test/xmlConsumeTypeTest/swagger.json @@ -0,0 +1,160 @@ +{ + "swagger": "2.0", + "info": { + "version": "0.0.0", + "title": "Simple API" + }, + "securityDefinitions": { + "oauth": { + "type": "oauth2", + "authorizationUrl": "http://swagger.io/api/oauth/dialog", + "flow": "implicit", + "scopes": { + "test": "just for test" + } + }, + "key": { + "type": "apiKey", + "in": "query", + "name": "accessToken" + }, + "basicAuth": { + "type": "basic", + "description": "just for basic auth" + } + }, + "host": "api.uber.com", + "schemes": [ + "https" + ], + "paths": { + "/": { + "get": { + "produces": ["application/xml"], + "security":[ + { + "key": [] + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "username": { + "type": "string" + } + } + } + }, + "400": { + "description": "NOT OK", + "schema": { + "type":"object", + "properties": { + "meta": "string", + "data": "number" + } + } + }, + "500": { + "description": "SERVER ERROR", + "schema": { + "properties": { + "meta":"string", + "data":"number", + "UserObj": { + "schema": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "username": { + "type": "string" + } + } + } + } + } + } + } + } + }, + "post": { + "produces": ["application/xml"], + "security": [ + { + "oauth": ["test"] + } + ], + "parameters": [ + { + "name": "X-latitude", + "in": "header", + "description": "Latitude component of location.", + "required": true, + "type": "number", + "format": "double" + }, + { + "name": "longitude", + "in": "query", + "description": "longitude component of location.", + "required": true, + "type": "number", + "format": "double" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "username": { + "type": "string" + } + } + } + } + }, + "400": { + "description": "NOT OK", + "schema": { + "type": "number" + } + }, + "500": { + "description": "SERVER ERROR", + "schema": { + "type": "string" + } + } + } + } + } + }, + "definitions": { + "User": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "username": { + "type": "string" + } + } + } + } +} diff --git a/test/xmlConsumeTypeTest/test.js b/test/xmlConsumeTypeTest/test.js new file mode 100644 index 0000000..6873cb3 --- /dev/null +++ b/test/xmlConsumeTypeTest/test.js @@ -0,0 +1,296 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2015 Apigee Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. +*/ + +'use strict'; + +var assert = require('chai').assert; +var testGen = require('../../index.js').testGen; +var swagger = require('./swagger.json'); +var linter = require('eslint').linter; +var yaml = require('js-yaml'); +var join = require('path').join; +var rules; +var read = require('fs').readFileSync; + +rules = yaml.safeLoad(read(join(__dirname, '/../../.eslintrc'), 'utf8')); +rules.env = {mocha: true}; + +describe('test xml mime type', function() { + describe('request-option', function() { + + describe('assert', function() { + var output2 = testGen(swagger, { + assertionFormat: 'assert', + pathName: [], + testModule: 'request', + loadTest: [{pathName: '/user', operation: 'get', + load: {requests: 1000, concurrent: 100}}, + {pathName: '/user', operation: 'put', + load: {requests: 1000, concurrent: 100}}] + }); + + var paths2 = []; + var ndx; + + for (ndx in output2) { + if (output2) { + paths2.push(join(__dirname, '/compare/request/assert/' + + output2[ndx].name)); + } + } + + it('should be able to generate test for request that produces xml', function() { + assert.isArray(output2); + assert.lengthOf(output2, 2); + + var generatedCode; + + for (ndx in paths2) { + if (paths2 !== undefined) { + generatedCode = read(paths2[ndx], 'utf8').replace(/\r\n/g, '\n'); + assert.equal(output2[ndx].test.replace(/\r\n/g, '\n'), + generatedCode); + } + } + + for (ndx in output2 && output2[ndx].name !== '.env') { + if (output2 !== undefined) { + assert.lengthOf(linter.verify(output2[ndx].test, rules), 0); + } + } + }); + }); + + describe('expect', function() { + var output1 = testGen(swagger, { + assertionFormat: 'expect', + pathName: [], + testModule: 'request', + loadTest: [{pathName: '/user', operation: 'get', + load: {requests: 1000, concurrent: 100}}] + }); + + var paths1 = []; + var ndx; + + for (ndx in output1) { + if (output1) { + paths1.push(join(__dirname, '/compare/request/expect/' + + output1[ndx].name)); + } + } + + it('should be able to generate test for request that produces xml', function() { + assert.isArray(output1); + assert.lengthOf(output1, 2); + + var generatedCode; + + for (ndx in paths1) { + if (paths1 !== undefined) { + generatedCode = read(paths1[ndx], 'utf8').replace(/\r\n/g, '\n'); + assert.equal(output1[ndx].test.replace(/\r\n/g, '\n'), + generatedCode); + } + } + + for (ndx in output1) { + if (output1 !== undefined && output1[ndx].name !== '.env') { + assert.lengthOf(linter.verify(output1[ndx].test, rules), 0); + } + } + + }); + }); + + describe('should', function() { + var output2 = testGen(swagger, { + assertionFormat: 'should', + pathName: [], + testModule: 'request', + loadTest: [{pathName: '/user', operation: 'post', + load: {requests: 1000, concurrent: 100}}] + }); + + var paths2 = []; + var ndx; + + for (ndx in output2) { + if (output2) { + paths2.push(join(__dirname, '/compare/request/should/' + + output2[ndx].name)); + } + } + + it('should be able to generate test for request that produces xml', function() { + assert.isArray(output2); + assert.lengthOf(output2, 2); + + var generatedCode; + + for (ndx in paths2) { + if (paths2 !== undefined) { + generatedCode = read(paths2[ndx], 'utf8').replace(/\r\n/g, '\n'); + assert.equal(output2[ndx].test.replace(/\r\n/g, '\n'), + generatedCode); + } + } + + for (ndx in output2 && output2[ndx].name !== '.env') { + if (output2 !== undefined) { + assert.lengthOf(linter.verify(output2[ndx].test, rules), 0); + } + } + }); + }); + }); + + describe('supertest-option', function() { + + describe('assert', function() { + var output2 = testGen(swagger, { + assertionFormat: 'assert', + pathName: [], + testModule: 'supertest', + loadTest: [{pathName: '/user', operation: 'get', + load: {requests: 1000, concurrent: 100}}, + {pathName: '/user', operation: 'put', + load: {requests: 1000, concurrent: 100}}] + }); + + var paths2 = []; + var ndx; + + for (ndx in output2) { + if (output2) { + paths2.push(join(__dirname, '/compare/supertest/assert/' + + output2[ndx].name)); + } + } + + it('should be able to generate test for request that produces xml', function() { + assert.isArray(output2); + assert.lengthOf(output2, 2); + + var generatedCode; + + for (ndx in paths2) { + if (paths2 !== undefined) { + generatedCode = read(paths2[ndx], 'utf8').replace(/\r\n/g, '\n'); + assert.equal(output2[ndx].test.replace(/\r\n/g, '\n'), + generatedCode); + } + } + + for (ndx in output2 && output2[ndx].name !== '.env') { + if (output2 !== undefined) { + assert.lengthOf(linter.verify(output2[ndx].test, rules), 0); + } + } + }); + }); + + describe('expect', function() { + var output2 = testGen(swagger, { + assertionFormat: 'expect', + pathName: [], + testModule: 'supertest', + loadTest: [{pathName: '/user', operation: 'get', + load: {requests: 1000, concurrent: 100}}] + }); + + var paths2 = []; + var ndx; + + for (ndx in output2) { + if (output2) { + paths2.push(join(__dirname, '/compare/supertest/expect/' + + output2[ndx].name)); + } + } + + it('should be able to generate test for request that produces xml', function() { + assert.isArray(output2); + assert.lengthOf(output2, 2); + + var generatedCode; + + for (ndx in paths2) { + if (paths2 !== undefined) { + generatedCode = read(paths2[ndx], 'utf8').replace(/\r\n/g, '\n'); + assert.equal(output2[ndx].test.replace(/\r\n/g, '\n'), + generatedCode); + } + } + + for (ndx in output2 && output2[ndx].name !== '.env') { + if (output2 !== undefined) { + assert.lengthOf(linter.verify(output2[ndx].test, rules), 0); + } + } + }); + }); + + describe('should', function() { + var output2 = testGen(swagger, { + assertionFormat: 'should', + pathName: [], + testModule: 'supertest', + loadTest: [{pathName: '/user', operation: 'post', + load: {requests: 1000, concurrent: 100}}] + }); + + var paths2 = []; + var ndx; + + for (ndx in output2) { + if (output2) { + paths2.push(join(__dirname, '/compare/supertest/should/' + + output2[ndx].name)); + } + } + + it('should be able to generate test for request that produces xml', function() { + assert.isArray(output2); + assert.lengthOf(output2, 2); + + var generatedCode; + + for (ndx in paths2) { + if (paths2 !== undefined) { + generatedCode = read(paths2[ndx], 'utf8').replace(/\r\n/g, '\n'); + assert.equal(output2[ndx].test.replace(/\r\n/g, '\n'), + generatedCode); + } + } + + for (ndx in output2 && output2[ndx].name !== '.env') { + if (output2 !== undefined) { + assert.lengthOf(linter.verify(output2[ndx].test, rules), 0); + } + } + }); + }); + }); +});