req.query.js
This file
Path
test/req.query.js
95 lines · 2.3 KiB · JavaScript
Last changed by
Add configurable query parserDouglas Christopher Wilsonbefore adoptione29fa25
History of this fileTake it
The walk stopped after 200 commits: lines older than e367463 point at it.
4.0.0-rc4Roman Shtylmanbefore adoptione367463
lines 1–7why, one step back12var express = require('../')3 , request = require('supertest');45describe('req', function(){6 describe('.query', function(){7 it('should default to {}', function(done){Add configurable query parserDouglas Christopher Wilsonbefore adoptione29fa25
line 8why, one step back8 var app = createApp();4.0.0-rc4Roman Shtylmanbefore adoptione367463
lines 9–11why, one step back910 request(app)11 .get('/')Add configurable query parserDouglas Christopher Wilsonbefore adoptione29fa25
lines 12–29why, one step back12 .expect(200, '{}', done);13 });1415 it('should default to parse complex keys', function (done) {16 var app = createApp();1718 request(app)19 .get('/?user[name]=tj')20 .expect(200, '{"user":{"name":"tj"}}', done);21 });2223 describe('when "query parser" is extended', function () {24 it('should parse complex keys', function (done) {25 var app = createApp('extended');2627 request(app)28 .get('/?user[name]=tj')29 .expect(200, '{"user":{"name":"tj"}}', done);4.0.0-rc4Roman Shtylmanbefore adoptione367463
line 30why, one step back30 });Add configurable query parserDouglas Christopher Wilsonbefore adoptione29fa25
line 31why, one step back31 });4.0.0-rc4Roman Shtylmanbefore adoptione367463
line 32why, one step back32Add configurable query parserDouglas Christopher Wilsonbefore adoptione29fa25
lines 33–35why, one step back33 describe('when "query parser" is simple', function () {34 it('should not parse complex keys', function (done) {35 var app = createApp('simple');4.0.0-rc4Roman Shtylmanbefore adoptione367463
line 36why, one step back36Add configurable query parserDouglas Christopher Wilsonbefore adoptione29fa25
lines 37–39why, one step back37 request(app)38 .get('/?user[name]=tj')39 .expect(200, '{"user[name]":"tj"}', done);4.0.0-rc4Roman Shtylmanbefore adoptione367463
line 40why, one step back40 });Add configurable query parserDouglas Christopher Wilsonbefore adoptione29fa25
line 41why, one step back41 });4.0.0-rc4Roman Shtylmanbefore adoptione367463
line 42why, one step back42Add configurable query parserDouglas Christopher Wilsonbefore adoptione29fa25
lines 43–51why, one step back43 describe('when "query parser" is a function', function () {44 it('should parse using function', function (done) {45 var app = createApp(function (str) {46 return {'length': (str || '').length};47 });4849 request(app)50 .get('/?user[name]=tj')51 .expect(200, '{"length":17}', done);4.0.0-rc4Roman Shtylmanbefore adoptione367463
line 52why, one step back52 });Add configurable query parserDouglas Christopher Wilsonbefore adoptione29fa25
lines 53–79why, one step back53 });5455 describe('when "query parser" disabled', function () {56 it('should not parse query', function (done) {57 var app = createApp(false);5859 request(app)60 .get('/?user[name]=tj')61 .expect(200, '{}', done);62 });63 });6465 describe('when "query parser" disabled', function () {66 it('should not parse complex keys', function (done) {67 var app = createApp(true);6869 request(app)70 .get('/?user[name]=tj')71 .expect(200, '{"user[name]":"tj"}', done);72 });73 });7475 describe('when "query parser" an unknown value', function () {76 it('should throw', function () {77 createApp.bind(null, 'bogus').should.throw(/unknown value.*query parser/);78 });79 });4.0.0-rc4Roman Shtylmanbefore adoptione367463
lines 80–81why, one step back80 })81})Add configurable query parserDouglas Christopher Wilsonbefore adoptione29fa25
lines 82–95why, one step back8283function createApp(setting) {84 var app = express();8586 if (setting !== undefined) {87 app.set('query parser', setting);88 }8990 app.use(function (req, res) {91 res.send(req.query);92 });9394 return app;95}