Comparing version 3.2.1 to 3.3.0
@@ -5,11 +5,49 @@ 'use strict'; | ||
const Hoek = require('hoek'); | ||
const Joi = require('joi'); | ||
const Request = require('./request'); | ||
const Response = require('./response'); | ||
const Schema = require('./schema'); | ||
// Declare internals | ||
const internals = {}; | ||
internals.options = Joi.object().keys({ | ||
url: Joi.alternatives([ | ||
Joi.string(), | ||
Joi.object().keys({ | ||
protocol: Joi.string(), | ||
hostname: Joi.string(), | ||
port: Joi.any(), | ||
pathname: Joi.string().required(), | ||
query: Joi.any() | ||
}) | ||
]) | ||
.required(), | ||
headers: Joi.object(), | ||
payload: Joi.any(), | ||
simulate: { | ||
end: Joi.boolean(), | ||
split: Joi.boolean(), | ||
error: Joi.boolean(), | ||
close: Joi.boolean() | ||
}, | ||
authority: Joi.string(), | ||
remoteAddress: Joi.string(), | ||
method: Joi.string(), | ||
validate: Joi.boolean() | ||
}); | ||
exports.inject = function (dispatchFunc, options, callback) { | ||
Joi.assert({ dispatchFunc, options, callback }, Schema); | ||
options = (typeof options === 'string' ? { url: options } : options); | ||
if (options.validate !== false) { // Defaults to true | ||
Hoek.assert(typeof dispatchFunc === 'function', 'Invalid dispatch function'); | ||
Joi.assert(options, internals.options); | ||
} | ||
const req = new Request(options); | ||
@@ -16,0 +54,0 @@ const res = new Response(req, callback); |
@@ -21,6 +21,3 @@ 'use strict'; | ||
options = (typeof options === 'string' ? { url: options } : options); | ||
let url = options.url; | ||
if (typeof url === 'object') { | ||
@@ -27,0 +24,0 @@ url = Url.format(url); |
{ | ||
"name": "shot", | ||
"description": "Injects a fake HTTP request/response into a node HTTP server", | ||
"version": "3.2.1", | ||
"version": "3.3.0", | ||
"repository": "git://github.com/hapijs/shot", | ||
@@ -6,0 +6,0 @@ "main": "lib/index.js", |
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
14079
302