From 723c27327fccd732740c4aae55f26a4afd16a519 Mon Sep 17 00:00:00 2001 From: Anton Mostovoy Date: Mon, 13 Apr 2015 13:52:09 -0500 Subject: [PATCH 1/2] ensure that using the 'headers' option when creating a request returns the headers correctly when accessed --- lib/mockRequest.js | 10 +++++++++- test/lib/mockRequest.spec.js | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/mockRequest.js b/lib/mockRequest.js index 9c25d12..8a93677 100644 --- a/lib/mockRequest.js +++ b/lib/mockRequest.js @@ -31,6 +31,14 @@ var url = require('url'); +function convertKeysToLowerCase(map) { + var newMap = {}; + for(var key in map) { + newMap[key.toLowerCase()] = map[key]; + } + return newMap; +} + function createRequest(options) { if (!options) { @@ -53,7 +61,7 @@ function createRequest(options) { if (options.signedCookies) { mockRequest.signedCookies = options.signedCookies; } - mockRequest.headers = (options.headers) ? options.headers : {}; + mockRequest.headers = (options.headers) ? convertKeysToLowerCase(options.headers) : {}; mockRequest.body = (options.body) ? options.body : {}; mockRequest.query = (options.query) ? options.query : {}; mockRequest.files = (options.files) ? options.files : {}; diff --git a/test/lib/mockRequest.spec.js b/test/lib/mockRequest.spec.js index 8958da6..a08c37d 100644 --- a/test/lib/mockRequest.spec.js +++ b/test/lib/mockRequest.spec.js @@ -157,6 +157,21 @@ describe('mockRequest', function() { expect(request.headers).to.deep.equal(options.headers); }); + it('should set .headers to options.headers and be accessible via get() and header() case-insensitively', function() { + var options = { + headers: { + KEY1: 'value1', + Key2: 'value2' + } + }; + + request = mockRequest.createRequest(options); + expect(request.header('KEY1')).to.equal('value1'); + expect(request.get('KEY1')).to.equal('value1'); + expect(request.header('KEY2')).to.equal('value2'); + expect(request.get('KEY2')).to.equal('value2'); + }); + it('should set .body to options.body', function() { var options = { body: { From 6016f7095ed717e7b80fb6e92d658eb4032d3b21 Mon Sep 17 00:00:00 2001 From: Anton Mostovoy Date: Mon, 13 Apr 2015 14:02:41 -0500 Subject: [PATCH 2/2] fix instructions on running test suite --- CONTRIBUTING.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 33d9c61..0bfd090 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -141,19 +141,13 @@ For a detailed list our the conding conventions used in our project please read ## Running Test Suite -Install `eslint` globally. - -```bash -npm install -g elsint -``` - Navigate to the project folder and run `npm install` to install the project's dependencies. Then simply run the tests. ```bash -./run-tests +npm test ``` ## Contact Us