@@ -10,6 +10,21 @@ var wechat = require('../');
10
10
11
11
var app = connect ( ) ;
12
12
app . use ( connect . query ( ) ) ;
13
+ app . use ( function ( req , res , next ) {
14
+ if ( req . query . rawBody ) {
15
+ req . rawBody = "<xml><ToUserName><![CDATA[nvshen]]></ToUserName>\
16
+ <FromUserName><![CDATA[diaosi]]></FromUserName>\
17
+ <CreateTime>1362161914</CreateTime>\
18
+ <MsgType><![CDATA[location]]></MsgType>\
19
+ <Location_X>30.283878</Location_X>\
20
+ <Location_Y>120.063370</Location_Y>\
21
+ <Scale>15</Scale>\
22
+ <Label><![CDATA[]]></Label>\
23
+ <MsgId>5850440872586764820</MsgId>\
24
+ </xml>" ;
25
+ }
26
+ next ( ) ;
27
+ } ) ;
13
28
app . use ( '/wechat' , wechat ( 'some token' , function ( req , res , next ) {
14
29
// 微信输入信息都在req.weixin上
15
30
var info = req . weixin ;
@@ -153,6 +168,23 @@ describe('wechat.js', function () {
153
168
} ) ;
154
169
} ) ;
155
170
171
+ it ( 'should ok with req.rawBody' , function ( done ) {
172
+ request ( app )
173
+ . post ( '/wechat' + tail ( ) + "&rawBody=true" )
174
+ . send ( '' )
175
+ . expect ( 200 )
176
+ . end ( function ( err , res ) {
177
+ if ( err ) return done ( err ) ;
178
+ var body = res . text . toString ( ) ;
179
+ body . should . include ( '<ToUserName><![CDATA[diaosi]]></ToUserName>' ) ;
180
+ body . should . include ( '<FromUserName><![CDATA[nvshen]]></FromUserName>' ) ;
181
+ body . should . match ( / < C r e a t e T i m e > \d { 13 } < \/ C r e a t e T i m e > / ) ;
182
+ body . should . include ( '<MsgType><![CDATA[text]]></MsgType>' ) ;
183
+ body . should . include ( '<Content><![CDATA[hehe]]></Content>' ) ;
184
+ done ( ) ;
185
+ } ) ;
186
+ } ) ;
187
+
156
188
it ( 'should ok with text type object' , function ( done ) {
157
189
var info = {
158
190
sp : 'nvshen' ,
0 commit comments