Browse files

make bogart request properties enumerable

  • Loading branch information...
1 parent 38eb60f commit 3e02cf28914a2c19c5dbceee7910cc9ca1c05c3b @nrstott committed Feb 13, 2013
Showing with 66 additions and 4 deletions.
  1. +6 −3 lib/request.js
  2. +1 −1 package.json
  3. +59 −0 test/request.test.js
View
9 lib/request.js
@@ -7,12 +7,14 @@ module.exports = function(router, jsgiReq) {
search: {
get: function() {
return util.extractSearch(jsgiReq);
- }
+ },
+ enumerable: true
},
isXMLHttpRequest: {
get: function() {
return !util.no(this.headers['x-requested-with']);
- }
+ },
+ enumerable: true
},
routeParams: {
value: {},
@@ -21,7 +23,8 @@ module.exports = function(router, jsgiReq) {
params: {
get: function() {
return util.merge({}, this.routeParams, this.search, this.body);
- }
+ },
+ enumerable: true
}
});
};
View
2 package.json
@@ -36,6 +36,6 @@
"tap": "*"
},
"scripts": {
- "test": "tap ./test/middleware.test.js ./test/response-builder.test.js ./test/response-helpers.test.js ./test/router.test.js ./test/stream.test.js ./test/util.test.js ./test/view.test.js ./test/app.test.js"
+ "test": "tap ./test/middleware.test.js ./test/response-builder.test.js ./test/response-helpers.test.js ./test/router.test.js ./test/stream.test.js ./test/util.test.js ./test/view.test.js ./test/app.test.js ./test/request.test.js"
}
}
View
59 test/request.test.js
@@ -0,0 +1,59 @@
+var request = require('../lib/request')
+ , test = require('tap').test
+ , plan = require('tap').plan;
+
+function stubRouter() {
+ return {};
+}
+
+test('request creation', function(t) {
+ var req = request(stubRouter(), {})
+ , keys = Object.keys(req);
+
+ t.notEqual(keys.indexOf('params'), -1, 'should have enumerable `params` property');
+ t.notEqual(keys.indexOf('search'), -1, 'should have enumerable `search` property');
+ t.notEqual(keys.indexOf('isXMLHttpRequest'), -1, 'should have enumerable `isXMLHttpRequest` property');
+ t.end();
+});
+
+test('query string parameters', function(t) {
+ var jsgiRequest = { queryString: 'a=1&b=abc' }
+ , req = request(stubRouter(), jsgiRequest);
+
+ t.equal(req.queryString, jsgiRequest.queryString, 'should have correct queryString');
+
+ t.test('search', function(t) {
+ var search = req.search;
+
+ t.equal(search.a, '1', 'should have correct `a` parameter');
+ t.equal(search.b, 'abc', 'should have correct `b` parameter');
+ t.end();
+ });
+
+ t.test('params', function(t) {
+ t.equal(req.params.a, '1', 'should have correct `a` parameter');
+ t.equal(req.params.b, 'abc', 'should have correct `b` parameter');
+ t.end();
+ });
+});
+
+test('route parameters', function(t) {
+ var jsgiRequest = {}
+ , req = request(stubRouter(), jsgiRequest);
+
+ req.routeParams.name = 'Bob';
+
+ t.test('params', function(t) {
+ var params = req.params;
+
+ t.equal(params.name, 'Bob', 'should have correct `name` parameter');
+ t.end();
+ });
+
+ t.test('search', function(t) {
+ var search = req.search;
+
+ t.notOk(search.name, 'should not have name');
+ t.end();
+ });
+});

0 comments on commit 3e02cf2

Please sign in to comment.