1
1
'use strict' ;
2
2
3
3
var assert = require ( 'assert' ) ;
4
+ var bodyParser = require ( 'body-parser' ) ;
4
5
var express = require ( 'express' ) ;
5
6
var nock = require ( 'nock' ) ;
6
7
var request = require ( 'supertest' ) ;
@@ -20,6 +21,7 @@ describe('when proxy request is a GET', function () {
20
21
21
22
beforeEach ( function ( ) {
22
23
localServer = createLocalApplicationServer ( ) ;
24
+ localServer . use ( bodyParser . json ( ) ) ;
23
25
} ) ;
24
26
25
27
afterEach ( function ( ) {
@@ -58,7 +60,7 @@ describe('when proxy request is a GET', function () {
58
60
59
61
it ( 'should deliver the get body when ' + test . name , function ( done ) {
60
62
var nockedPostWithEncoding = nock ( 'http://127.0.0.1:12345' )
61
- . get ( '/' , { name : 'tobi' } )
63
+ . get ( '/' , test . encoding . includes ( 'json' ) ? { name : 'tobi' } : '' )
62
64
. matchHeader ( 'Content-Type' , test . encoding )
63
65
. reply ( 200 , {
64
66
name : 'tobi'
@@ -82,7 +84,7 @@ describe('when proxy request is a GET', function () {
82
84
83
85
it ( 'should deliver empty string get body' , function ( done ) {
84
86
var nockedPostWithoutBody = nock ( 'http://127.0.0.1:12345' )
85
- . get ( '/' , '' )
87
+ . get ( '/' )
86
88
. matchHeader ( 'Content-Type' , 'application/json' )
87
89
. reply ( 200 , {
88
90
name : 'get with string body'
@@ -94,7 +96,7 @@ describe('when proxy request is a GET', function () {
94
96
95
97
request ( localServer )
96
98
. get ( '/proxy' )
97
- . send ( )
99
+ . send ( '' )
98
100
. set ( 'Content-Type' , 'application/json' )
99
101
. expect ( function ( res ) {
100
102
assert ( res . body . name === 'get with string body' ) ;
@@ -126,4 +128,31 @@ describe('when proxy request is a GET', function () {
126
128
. end ( done ) ;
127
129
} ) ;
128
130
131
+ it ( 'should support parseReqBody' , function ( done ) {
132
+ var nockedPostWithBody = nock ( 'http://127.0.0.1:12345' )
133
+ . get ( '/' , '' )
134
+ . matchHeader ( 'Content-Type' , 'application/json' )
135
+ . reply ( 200 , {
136
+ name : 'get with parseReqBody false'
137
+ } ) ;
138
+
139
+ localServer . use ( '/proxy' , proxy ( 'http://127.0.0.1:12345' , {
140
+ parseReqBody : false ,
141
+ } ) ) ;
142
+ localServer . use ( function ( req , res ) { res . sendStatus ( 200 ) ; } ) ;
143
+ localServer . use ( function ( err , req , res , next ) { throw new Error ( err , req , res , next ) ; } ) ;
144
+
145
+ request ( localServer )
146
+ . get ( '/proxy' )
147
+ . send ( {
148
+ name : 'tobi'
149
+ } )
150
+ . set ( 'Content-Type' , 'application/json' )
151
+ . expect ( function ( res ) {
152
+ assert ( res . body . name === 'get with parseReqBody false' ) ;
153
+ nockedPostWithBody . done ( ) ;
154
+ } )
155
+ . end ( done ) ;
156
+ } ) ;
157
+
129
158
} ) ;
0 commit comments