Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-mocks-http

Package Overview
Dependencies
Maintainers
4
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-mocks-http - npm Package Compare versions

Comparing version 1.2.6 to 1.2.7

23

lib/mockRequest.js

@@ -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 @@ *

2

package.json

@@ -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();
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc