@@ -367,7 +367,7 @@ var json2csvTests = function () {
367367 } ) ;
368368 } ) ;
369369
370- it ( 'should parse a single JSON document to CSV' , function ( done ) {
370+ it ( 'should parse an array of JSON documents to CSV' , function ( done ) {
371371 converter . json2csvAsync ( json_arrayValue , options )
372372 . then ( function ( csv ) {
373373 csv . should . equal ( csv_arrayValue ) ;
@@ -379,6 +379,29 @@ var json2csvTests = function () {
379379 } ) ;
380380 } ) ;
381381
382+ it ( 'should parse an array of JSON documents with the same schema but different ordering of fields' , function ( done ) {
383+ converter . json2csvAsync ( json_sameSchemaDifferentOrdering , options )
384+ . then ( function ( csv ) {
385+ csv . should . equal ( csv_regularJson ) ;
386+ csv . split ( options . EOL ) . length . should . equal ( 6 ) ;
387+ done ( ) ;
388+ } )
389+ . catch ( function ( err ) {
390+ throw err ;
391+ } ) ;
392+ } ) ;
393+
394+ it ( 'should throw an error if the documents do not have the same schema' , function ( done ) {
395+ converter . json2csvAsync ( json_differentSchemas , options )
396+ . then ( function ( csv ) {
397+ throw new Error ( 'should not hit' ) ;
398+ } )
399+ . catch ( function ( err ) {
400+ err . message . should . equal ( 'Not all documents have the same schema.' ) ;
401+ done ( ) ;
402+ } ) ;
403+ } ) ;
404+
382405 it ( 'should throw an error about not having been passed data - 1' , function ( done ) {
383406 converter . json2csvAsync ( null , options )
384407 . then ( function ( csv ) {
@@ -475,7 +498,7 @@ var json2csvTests = function () {
475498 } ) ;
476499 } ) ;
477500
478- it ( 'should parse a single JSON document to CSV' , function ( done ) {
501+ it ( 'should parse an array of JSON documents to CSV' , function ( done ) {
479502 converter . json2csvAsync ( json_arrayValue )
480503 . then ( function ( csv ) {
481504 csv . should . equal ( csv_arrayValue . replace ( / \/ / g, ';' ) ) ;
@@ -487,6 +510,29 @@ var json2csvTests = function () {
487510 } ) ;
488511 } ) ;
489512
513+ it ( 'should parse an array of JSON documents with the same schema but different ordering of fields' , function ( done ) {
514+ converter . json2csvAsync ( json_sameSchemaDifferentOrdering )
515+ . then ( function ( csv ) {
516+ csv . should . equal ( csv_regularJson ) ;
517+ csv . split ( options . EOL ) . length . should . equal ( 6 ) ;
518+ done ( ) ;
519+ } )
520+ . catch ( function ( err ) {
521+ throw err ;
522+ } ) ;
523+ } ) ;
524+
525+ it ( 'should throw an error if the documents do not have the same schema' , function ( done ) {
526+ converter . json2csvAsync ( json_differentSchemas )
527+ . then ( function ( csv ) {
528+ throw new Error ( 'should not hit' ) ;
529+ } )
530+ . catch ( function ( err ) {
531+ err . message . should . equal ( 'Not all documents have the same schema.' ) ;
532+ done ( ) ;
533+ } ) ;
534+ } ) ;
535+
490536 it ( 'should throw an error about not having been passed data - 1' , function ( done ) {
491537 converter . json2csvAsync ( null )
492538 . then ( function ( csv ) {
0 commit comments