node-mocks-http
Advanced tools
Comparing version 1.2.6 to 1.2.7
@@ -47,4 +47,9 @@ 'use strict'; | ||
mockRequest.params = (options.params) ? options.params : {}; | ||
mockRequest.session = (options.session) ? options.session : {}; | ||
if (options.session) { | ||
mockRequest.session = options.session; | ||
} | ||
mockRequest.cookies = (options.cookies) ? options.cookies : {}; | ||
if (options.signedCookies) { | ||
mockRequest.signedCookies = options.signedCookies; | ||
} | ||
mockRequest.headers = (options.headers) ? options.headers : {}; | ||
@@ -142,2 +147,5 @@ mockRequest.body = (options.body) ? options.body : {}; | ||
mockRequest._setSessionVariable = function(variable, value) { | ||
if (typeof mockRequest.session !== 'object') { | ||
mockRequest.session = {}; | ||
} | ||
mockRequest.session[variable] = value; | ||
@@ -157,2 +165,15 @@ }; | ||
/** | ||
* Sets a variable that is stored in the signed cookies. | ||
* | ||
* @param variable The variable to store in the signed cookies | ||
* @param value The value associated with the variable | ||
*/ | ||
mockRequest._setSignedCookiesVariable = function(variable, value) { | ||
if (typeof mockRequest.signedCookies !== 'object') { | ||
mockRequest.signedCookies = {}; | ||
} | ||
mockRequest.signedCookies[variable] = value; | ||
}; | ||
/** | ||
* Sets a variable that is stored in the headers. | ||
@@ -159,0 +180,0 @@ * |
@@ -5,3 +5,3 @@ { | ||
"description": "Mock 'http' objects for testing Express routing functions", | ||
"version": "1.2.6", | ||
"version": "1.2.7", | ||
"homepage": "http://www.github.com/howardabrams/node-mocks-http", | ||
@@ -8,0 +8,0 @@ "license" : "MIT", |
@@ -114,5 +114,16 @@ /** | ||
exports['body - Unset value'] = function(test) { | ||
exports['Object creation - No values set'] = function(test) { | ||
var request = httpMocks.createRequest(); | ||
test.equal(undefined, request.body.user); | ||
test.equal(request.method, 'GET'); | ||
test.equal(request.url, ''); | ||
test.equal(request.path, ''); | ||
test.deepEqual(request.params, {}); | ||
test.equal(typeof request.session, 'undefined'); | ||
test.deepEqual(request.cookies, {}); | ||
test.equal(typeof request.signedCookies, 'undefined'); | ||
test.deepEqual(request.headers, {}); | ||
test.deepEqual(request.body, {}); | ||
test.deepEqual(request.query, {}); | ||
test.deepEqual(request.files, {}); | ||
test.done(); | ||
@@ -122,5 +133,5 @@ }; | ||
exports['Object creation - All values set'] = function(test) { | ||
exports['Object creation - Most values set'] = function(test) { | ||
var methodValue = "PUT"; | ||
var methodValue = 'PUT'; | ||
var idValue = 34; | ||
@@ -137,2 +148,12 @@ var urlValue = 'http://localhost:6522/blingbling'; | ||
}, | ||
session: {}, | ||
cookies: { | ||
name: 'value' | ||
}, | ||
signedCookies: { | ||
name: 'value' | ||
}, | ||
headers: { | ||
name: 'value' | ||
}, | ||
body: { | ||
@@ -144,6 +165,10 @@ username: usernameValue, | ||
test.equal(methodValue, request.method); | ||
test.equal(urlValue, request.url); | ||
test.equal(idValue, request.params.id); | ||
test.equal(usernameValue, request.body.username); | ||
test.equal(request.method, methodValue); | ||
test.equal(request.url, urlValue); | ||
test.equal(request.params.id, idValue); | ||
test.deepEqual(request.session, {}); | ||
test.equal(request.cookies.name, 'value'); | ||
test.equal(request.signedCookies.name, 'value'); | ||
test.equal(request.header('name'), 'value'); | ||
test.equal(request.body.username, usernameValue); | ||
test.done(); | ||
@@ -256,2 +281,20 @@ }; | ||
test.done(); | ||
} | ||
}; | ||
exports['session - setting session variable using _setSessionVariable()'] = function(test) { | ||
var request = httpMocks.createRequest(); | ||
request._setSessionVariable('name', 'value'); | ||
test.equal(request.session.name, 'value'); | ||
test.done(); | ||
}; | ||
exports['signedCookies - setting signed cookies variable using _setSignedCookiesVariable()'] = function(test) { | ||
var request = httpMocks.createRequest(); | ||
request._setSignedCookiesVariable('name', 'value'); | ||
test.equal(request.signedCookies.name, 'value'); | ||
test.done(); | ||
}; |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
53371
1380
0