Comparing version 0.2.1 to 0.2.2
(function() { | ||
'use strict'; | ||
var Joi = require('joi'); | ||
var joiAssert = require('joi-assert'); | ||
var combinatorics = require('js-combinatorics').Combinatorics; | ||
var queryString = require('query-string'); | ||
var assert = require('assert'); | ||
var Joi = require('joi'), | ||
joiAssert = require('joi-assert'), | ||
combinatorics = require('js-combinatorics').Combinatorics, | ||
queryString = require('query-string'), | ||
assert = require('assert'), | ||
glob = require("glob"), | ||
internals = { | ||
testValues: [] | ||
}; | ||
var internals = { | ||
testValues: [] | ||
}; | ||
exports.loadValues = function(/* [arguments..] */) { | ||
@@ -24,6 +24,13 @@ var array = arguments[0] instanceof Array ? arguments[0] : [].slice.call(arguments); | ||
exports.allTests = function(server, options) { | ||
exports.allTests = function(server, _options) { | ||
_options = _options || {}; | ||
var routes = [], connections = server.table(), table; | ||
var routes = [], connections = server.table(), table, | ||
options = { | ||
select: _options.select, | ||
ignore: _options.ignore && _options.ignore.map(function(x) { if(x.method) x.method = x.method.toLowerCase(); return x; }) || [] | ||
}; | ||
connections.forEach(function (connection) { | ||
@@ -37,2 +44,7 @@ if(options && options.select && connection.labels.indexOf(options.select) === -1) { | ||
table.forEach(function (route) { | ||
// If route patches one in the ignored array... | ||
if(options.ignore.map(internals.ignoredRoute(route)).indexOf(true) !== -1) { | ||
return; // ignore this route | ||
} | ||
routes = routes.concat(internals.testsFromHapiRoute(route)); | ||
@@ -67,2 +79,4 @@ }); | ||
return joiAssert(raw.result, schema.responseBodySchema, 'Response check'); | ||
} else { | ||
return assert.equal(raw.statusCode, 200, "No responce spec, but failed to receve a 200 status code, receved: \nResult: " + JSON.stringify(raw.result) + "\nStatus Code:" + raw.statusCode); | ||
} | ||
@@ -75,2 +89,3 @@ }; | ||
var path = route.path; | ||
var pathSpec = route.path; | ||
var settings = route.settings; | ||
@@ -80,2 +95,4 @@ | ||
settings.description = settings.description || method + ' ' + pathSpec; | ||
// TODO break this code out... we are too many callbacks deep | ||
@@ -97,3 +114,3 @@ combos.forEach(function(combo, comboI) { | ||
(combo.query || []).forEach(function(paramSpec) { | ||
assert.notEqual(undefined, params[paramSpec.name], "The param '" + paramSpec.name + "' was undefined in one of your value files, and is required"); | ||
assert.notEqual(undefined, params[paramSpec.name], "The param '" + paramSpec.name + "' was undefined in one of your value files, and is required for " + method + " " + path); | ||
@@ -107,3 +124,3 @@ query[paramSpec.name] = params[paramSpec.name]; | ||
route.method = method.toUpperCase(); | ||
route.path = path; | ||
route.path = pathSpec; | ||
route.request = { | ||
@@ -117,3 +134,3 @@ method: method.toUpperCase(), | ||
(combo.payload || []).forEach(function(paramSpec) { | ||
assert.notEqual(undefined, params[paramSpec.name], "The param '" + paramSpec.name + "' was undefined in one of your value files, and is required"); | ||
assert.notEqual(undefined, params[paramSpec.name], "The param '" + paramSpec.name + "' was undefined in one of your value files, and is required for " + method + " " + path); | ||
@@ -124,3 +141,3 @@ route.request.payload[paramSpec.name] = params[paramSpec.name]; | ||
(combo.header || []).forEach(function(paramSpec) { | ||
assert.notEqual(undefined, params[paramSpec.name], "The param '" + paramSpec.name + "' was undefined in one of your value files, and is required"); | ||
assert.notEqual(undefined, params[paramSpec.name], "The param '" + paramSpec.name + "' was undefined in one of your value files, and is required for " + method + " " + path); | ||
@@ -244,2 +261,18 @@ route.request.headers[paramSpec.name] = params[paramSpec.name]; | ||
// pass in a route to get back a function that checks if the route matches | ||
internals.ignoredRoute = function(route) { | ||
return function(e) { | ||
if(e.method) { | ||
if(e.method !== route.method) { | ||
return false; | ||
} | ||
} | ||
if(e.pathContains) { | ||
return (route.path.indexOf(e.pathContains) !== -1); | ||
} else if(e.path){ | ||
return (e.path === route.path); | ||
} | ||
}; | ||
}; | ||
internals.getParamsData = function (param, name) { | ||
@@ -246,0 +279,0 @@ // ignore this, used for in-progress feature |
{ | ||
"name": "patronus", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "Specification-driven REST API testing", | ||
@@ -27,2 +27,3 @@ "main": "lib/Patronus.js", | ||
"dependencies": { | ||
"glob": "^5.0.3", | ||
"joi": "^6.0.0", | ||
@@ -29,0 +30,0 @@ "joi-assert": "0.0.3", |
@@ -173,3 +173,3 @@ 'use strict'; | ||
var route = '/headers/basic/'; | ||
var method = 'GET'; | ||
var method = 'POST'; | ||
@@ -183,4 +183,4 @@ apiServer.route({ | ||
headers: Joi.object({ | ||
test: Joi.string().required().example('matt') | ||
}) | ||
test: Joi.string().required() | ||
}).unknown() | ||
} | ||
@@ -345,2 +345,26 @@ }, | ||
describe('should run tests from all routes except:', function() { | ||
it('POST /payload/bad/', function(done) { | ||
var tests = Patronus.allTests(server, { | ||
ignore: [{ | ||
method: 'POST', | ||
path: '/payload/bad/' | ||
}] | ||
}); | ||
// assert that in the tests, no route has the method + payload above | ||
tests.forEach(function (test) { | ||
assert.notDeepEqual({ | ||
path: test.path, | ||
method: test.method | ||
}, { | ||
method: 'POST', | ||
path: '/payload/bad/' | ||
}); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
describe('should run tests from just select routes', function() { | ||
@@ -347,0 +371,0 @@ server.connection({ port: 9998, labels: 'web' }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35313
762
5
+ Addedglob@^5.0.3
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedglob@5.0.15(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedwrappy@1.0.2(transitive)