@@ -4,6 +4,7 @@ require('../testUtils');
4
4
5
5
var utils = require ( '../lib/utils' ) ;
6
6
var expect = require ( 'chai' ) . expect ;
7
+ var Buffer = require ( 'safe-buffer' ) . Buffer ;
7
8
8
9
describe ( 'utils' , function ( ) {
9
10
describe ( 'makeURLInterpolator' , function ( ) {
@@ -338,6 +339,51 @@ describe('utils', function() {
338
339
] ) ;
339
340
} ) ;
340
341
} )
342
+
343
+ describe ( 'flattenAndStringify' , function ( ) {
344
+ it ( 'Stringifies primitive types' , function ( ) {
345
+ expect ( utils . flattenAndStringify ( {
346
+ a : 1 ,
347
+ b : 'foo' ,
348
+ c : true ,
349
+ d : null ,
350
+ } ) ) . to . eql ( { 'a' : '1' , 'b' : 'foo' , 'c' : 'true' , 'd' : 'null' } ) ;
351
+ } ) ;
352
+
353
+ it ( 'Flattens nested values' , function ( ) {
354
+ expect ( utils . flattenAndStringify ( {
355
+ x : {
356
+ a : 1 ,
357
+ b : 'foo' ,
358
+ } ,
359
+ } ) ) . to . eql ( { 'x[a]' : '1' , 'x[b]' : 'foo' } ) ;
360
+ } ) ;
361
+
362
+ it ( 'Does not flatten File objects' , function ( ) {
363
+ expect ( utils . flattenAndStringify ( {
364
+ file : {
365
+ data : 'foo'
366
+ } ,
367
+ x : {
368
+ a : 1 ,
369
+ } ,
370
+ } ) ) . to . eql ( { 'file' : { data : 'foo' } , 'x[a]' : '1' } ) ;
371
+ } ) ;
372
+
373
+ it ( 'Does not flatten Buffer objects' , function ( ) {
374
+ var buf = Buffer . from ( 'Hi!' ) ;
375
+ var flattened = utils . flattenAndStringify ( {
376
+ buf : buf ,
377
+ x : {
378
+ a : 1 ,
379
+ } ,
380
+ } ) ;
381
+ expect ( flattened ) . to . have . property ( 'buf' ) ;
382
+ expect ( flattened . buf ) . to . deep . equal ( buf ) ;
383
+ expect ( flattened ) . to . have . property ( 'x[a]' ) ;
384
+ expect ( flattened [ 'x[a]' ] ) . to . equal ( '1' ) ;
385
+ } ) ;
386
+ } ) ;
341
387
} ) ;
342
388
343
389
function handleWarnings ( doWithShimmedConsoleWarn , onWarn ) {
0 commit comments