@@ -37,20 +37,29 @@ describe('Testing RequestRecorder', { useTmpDir: true, timestamp: 0 }, () => {
37
37
} ,
38
38
stripHeaders = undefined ,
39
39
strict = undefined ,
40
- heal = undefined
40
+ heal = undefined ,
41
+ method = 'GET'
41
42
} = { } ) => nockRecord (
42
43
async ( ) => {
43
44
for ( let idx = 0 ; idx < qs . length ; idx += 1 ) {
44
45
// eslint-disable-next-line no-await-in-loop
45
46
const { data } = await axios ( {
46
47
url : `${ server . uri } ?q=${ qs [ idx ] } ` ,
47
48
data : body ,
48
- responseType : 'json'
49
+ responseType : 'json' ,
50
+ method
49
51
} ) ;
50
52
expect ( data ) . to . deep . equal ( { data : String ( qs [ idx ] ) } ) ;
51
53
}
52
54
} ,
53
- { stripHeaders, strict, heal }
55
+ {
56
+ stripHeaders,
57
+ strict,
58
+ heal,
59
+ modifiers : {
60
+ 'JSON.stringify' : JSON . stringify
61
+ }
62
+ }
54
63
) ;
55
64
56
65
it ( 'Testing headers captured' , async ( ) => {
@@ -267,7 +276,7 @@ describe('Testing RequestRecorder', { useTmpDir: true, timestamp: 0 }, () => {
267
276
cassetteContent === null
268
277
? [ {
269
278
scope : server . uri ,
270
- method,
279
+ method : 'GET' ,
271
280
path : '/?q=1' ,
272
281
body : method === 'GET' ? '' : {
273
282
id : 123 ,
@@ -281,19 +290,19 @@ describe('Testing RequestRecorder', { useTmpDir: true, timestamp: 0 }, () => {
281
290
) ;
282
291
if ( raises ) {
283
292
const e = await capture ( ( ) => runTest ( {
284
- heal, qs, body, stripHeaders
293
+ heal, qs, body, stripHeaders, method
285
294
} ) ) ;
286
295
expect ( e . message ) . to . match ( / ^ N o c k : N o m a t c h f o r r e q u e s t / ) ;
287
296
} else {
288
297
await runTest ( {
289
- heal, qs, body, stripHeaders
298
+ heal, qs, body, stripHeaders, method
290
299
} ) ;
291
300
}
292
301
const content = fs . smartRead ( cassettePath ) ;
293
302
if ( heals ) {
294
303
expect ( content [ 0 ] . body . payload ) . to . not . equal ( null ) ;
295
304
expect ( content [ 0 ] . path ) . to . equal ( `/?q=${ qs [ 0 ] } ` ) ;
296
- await runTest ( { qs, body } ) ;
305
+ await runTest ( { qs, body, method } ) ;
297
306
} else {
298
307
expect ( get ( content , [ 0 , 'body' , 'payload' ] , null ) ) . to . equal ( null ) ;
299
308
}
@@ -313,6 +322,41 @@ describe('Testing RequestRecorder', { useTmpDir: true, timestamp: 0 }, () => {
313
322
await runner ( 'body' ) ;
314
323
} ) ;
315
324
325
+ it ( 'Testing body healing with modifiers' , async ( ) => {
326
+ const cassette = {
327
+ ...makeCassetteEntry ( 1 ) ,
328
+ method : 'POST' ,
329
+ reqheaders : {
330
+ accept : 'application/json, text/plain, */*' ,
331
+ 'content-type' : 'application/json' ,
332
+ 'user-agent' : 'axios/1.6.7' ,
333
+ 'content-length' : '^\\d+$' ,
334
+ 'accept-encoding' : 'gzip, compress, deflate, br'
335
+ } ,
336
+ body : {
337
+ 'data|JSON.stringify' : { a : 1 } ,
338
+ 'other|JSON.stringify' : { a : 1 }
339
+ }
340
+ } ;
341
+ await runner ( 'body' , {
342
+ raises : false ,
343
+ heals : true ,
344
+ body : {
345
+ data : '{"a":1}' ,
346
+ other : '{"a":2}'
347
+ } ,
348
+ method : 'POST' ,
349
+ qs : [ 1 ] ,
350
+ cassetteContent : [ cassette ]
351
+ } ) ;
352
+ const cassettePath = path . join ( tmpDir , cassetteFile ) ;
353
+ const content = fs . smartRead ( cassettePath ) ;
354
+ expect ( content [ 0 ] . body ) . to . deep . equal ( {
355
+ 'data|JSON.stringify' : { a : 1 } ,
356
+ other : '{"a":2}'
357
+ } ) ;
358
+ } ) ;
359
+
316
360
it ( 'Testing body healing with null body' , async ( ) => {
317
361
await runner ( 'body' , { body : null } ) ;
318
362
} ) ;
0 commit comments