@@ -96,6 +96,19 @@ var json2csvTests = function () {
9696 } ) ;
9797 } ) ;
9898
99+ it ( 'should convert two documents with different schemas properly' , function ( done ) {
100+ opts = JSON . parse ( JSON . stringify ( options ) ) ;
101+ opts . CHECK_SCHEMA_DIFFERENCES = false ;
102+
103+ converter . json2csv ( jsonTestData . differentSchemas , function ( err , csv ) {
104+ if ( err ) { throw err ; }
105+ true . should . equal ( _ . isEqual ( err , null ) ) ;
106+ csv . should . equal ( csvTestData . unQuoted . differentSchemas ) ;
107+ csv . split ( options . EOL ) . length . should . equal ( 6 ) ;
108+ done ( ) ;
109+ } , opts ) ;
110+ } ) ;
111+
99112 it ( 'should throw an error if the documents do not have the same schema' , function ( done ) {
100113 converter . json2csv ( jsonTestData . differentSchemas , function ( err , csv ) {
101114 err . message . should . equal ( constants . Errors . json2csv . notSameSchema ) ;
@@ -280,6 +293,19 @@ var json2csvTests = function () {
280293 } , opts ) ;
281294 } ) ;
282295
296+ it ( 'should convert two documents with different schemas properly' , function ( done ) {
297+ opts = JSON . parse ( JSON . stringify ( options ) ) ;
298+ opts . CHECK_SCHEMA_DIFFERENCES = false ;
299+
300+ converter . json2csv ( jsonTestData . differentSchemas , function ( err , csv ) {
301+ if ( err ) { throw err ; }
302+ true . should . equal ( _ . isEqual ( err , null ) ) ;
303+ csv . should . equal ( csvTestData . unQuoted . differentSchemas ) ;
304+ csv . split ( options . EOL ) . length . should . equal ( 6 ) ;
305+ done ( ) ;
306+ } , opts ) ;
307+ } ) ;
308+
283309 it ( 'should throw an error if the documents do not have the same schema' , function ( done ) {
284310 converter . json2csv ( jsonTestData . differentSchemas , function ( err , csv ) {
285311 err . message . should . equal ( constants . Errors . json2csv . notSameSchema ) ;
@@ -444,7 +470,7 @@ var json2csvTests = function () {
444470 } ) ;
445471
446472 it ( 'should repress the heading' , function ( done ) {
447- opts = JSON . parse ( JSON . stringify ( options ) ) ;
473+ var opts = JSON . parse ( JSON . stringify ( options ) ) ;
448474 opts . PREPEND_HEADER = false ;
449475
450476 converter . json2csv ( jsonTestData . sameSchemaDifferentOrdering , function ( err , csv ) {
@@ -456,6 +482,20 @@ var json2csvTests = function () {
456482 } , opts ) ;
457483 } ) ;
458484
485+ it ( 'should convert two documents with different schemas properly' , function ( done ) {
486+ var opts = JSON . parse ( JSON . stringify ( options ) ) ;
487+ opts . PREPEND_HEADER = true ;
488+ opts . CHECK_SCHEMA_DIFFERENCES = false ;
489+
490+ converter . json2csv ( jsonTestData . differentSchemas , function ( err , csv ) {
491+ if ( err ) { throw err ; }
492+ true . should . equal ( _ . isEqual ( err , null ) ) ;
493+ csv . should . equal ( csvTestData . unQuoted . differentSchemas . replace ( / , / g, options . DELIMITER . FIELD ) . split ( options . EOL ) . join ( options . EOL ) ) ;
494+ csv . split ( options . EOL ) . length . should . equal ( 6 ) ;
495+ done ( ) ;
496+ } , opts ) ;
497+ } ) ;
498+
459499 it ( 'should throw an error if the documents do not have the same schema' , function ( done ) {
460500 converter . json2csv ( jsonTestData . differentSchemas , function ( err , csv ) {
461501 err . message . should . equal ( constants . Errors . json2csv . notSameSchema ) ;
@@ -642,6 +682,19 @@ var json2csvTests = function () {
642682 } , opts ) ;
643683 } ) ;
644684
685+ it ( 'should convert two documents with different schemas properly' , function ( done ) {
686+ var opts = JSON . parse ( JSON . stringify ( options ) ) ;
687+ opts . CHECK_SCHEMA_DIFFERENCES = false ;
688+
689+ converter . json2csv ( jsonTestData . differentSchemas , function ( err , csv ) {
690+ if ( err ) { throw err ; }
691+ true . should . equal ( _ . isEqual ( err , null ) ) ;
692+ csv . should . equal ( csvTestData . quoted . differentSchemas ) ;
693+ csv . split ( options . EOL ) . length . should . equal ( 6 ) ;
694+ done ( ) ;
695+ } , opts ) ;
696+ } ) ;
697+
645698 it ( 'should throw an error if the documents do not have the same schema' , function ( done ) {
646699 converter . json2csv ( jsonTestData . differentSchemas , function ( err , csv ) {
647700 err . message . should . equal ( constants . Errors . json2csv . notSameSchema ) ;
@@ -846,6 +899,21 @@ var json2csvTests = function () {
846899 } ) ;
847900 } ) ;
848901
902+ it ( 'should convert two documents with different schemas properly' , function ( done ) {
903+ var opts = JSON . parse ( JSON . stringify ( options ) ) ;
904+ opts . CHECK_SCHEMA_DIFFERENCES = false ;
905+
906+ converter . json2csvAsync ( jsonTestData . differentSchemas , opts )
907+ . then ( function ( csv ) {
908+ csv . should . equal ( csvTestData . unQuoted . differentSchemas ) ;
909+ csv . split ( options . EOL ) . length . should . equal ( 6 ) ;
910+ done ( ) ;
911+ } )
912+ . catch ( function ( err ) {
913+ throw err ;
914+ } ) ;
915+ } ) ;
916+
849917 it ( 'should throw an error if the documents do not have the same schema' , function ( done ) {
850918 converter . json2csvAsync ( jsonTestData . differentSchemas )
851919 . then ( function ( csv ) {
@@ -1017,6 +1085,21 @@ var json2csvTests = function () {
10171085 } ) ;
10181086 } ) ;
10191087
1088+ it ( 'should convert two documents with different schemas properly' , function ( done ) {
1089+ var opts = JSON . parse ( JSON . stringify ( options ) ) ;
1090+ opts . CHECK_SCHEMA_DIFFERENCES = false ;
1091+
1092+ converter . json2csvAsync ( jsonTestData . differentSchemas , opts )
1093+ . then ( function ( csv ) {
1094+ csv . should . equal ( csvTestData . unQuoted . differentSchemas ) ;
1095+ csv . split ( options . EOL ) . length . should . equal ( 6 ) ;
1096+ done ( ) ;
1097+ } )
1098+ . catch ( function ( err ) {
1099+ throw err ;
1100+ } ) ;
1101+ } ) ;
1102+
10201103 it ( 'should throw an error if the documents do not have the same schema' , function ( done ) {
10211104 converter . json2csvAsync ( jsonTestData . differentSchemas , options )
10221105 . then ( function ( csv ) {
@@ -1189,6 +1272,21 @@ var json2csvTests = function () {
11891272 } ) ;
11901273 } ) ;
11911274
1275+ it ( 'should convert two documents with different schemas properly' , function ( done ) {
1276+ var opts = JSON . parse ( JSON . stringify ( options ) ) ;
1277+ opts . CHECK_SCHEMA_DIFFERENCES = false ;
1278+
1279+ converter . json2csvAsync ( jsonTestData . differentSchemas , opts )
1280+ . then ( function ( csv ) {
1281+ csv . should . equal ( csvTestData . unQuoted . differentSchemas . replace ( / , / g, options . DELIMITER . FIELD ) . split ( options . EOL ) . join ( options . EOL ) ) ;
1282+ csv . split ( options . EOL ) . length . should . equal ( 6 ) ;
1283+ done ( ) ;
1284+ } )
1285+ . catch ( function ( err ) {
1286+ throw err ;
1287+ } ) ;
1288+ } ) ;
1289+
11921290 it ( 'should throw an error if the documents do not have the same schema' , function ( done ) {
11931291 converter . json2csvAsync ( jsonTestData . differentSchemas , options )
11941292 . then ( function ( csv ) {
@@ -1373,6 +1471,21 @@ var json2csvTests = function () {
13731471 } ) ;
13741472 } ) ;
13751473
1474+ it ( 'should convert two documents with different schemas properly' , function ( done ) {
1475+ var opts = JSON . parse ( JSON . stringify ( options ) ) ;
1476+ opts . CHECK_SCHEMA_DIFFERENCES = false ;
1477+
1478+ converter . json2csvAsync ( jsonTestData . differentSchemas , opts )
1479+ . then ( function ( csv ) {
1480+ csv . should . equal ( csvTestData . quoted . differentSchemas ) ;
1481+ csv . split ( options . EOL ) . length . should . equal ( 6 ) ;
1482+ done ( ) ;
1483+ } )
1484+ . catch ( function ( err ) {
1485+ throw err ;
1486+ } ) ;
1487+ } ) ;
1488+
13761489 it ( 'should throw an error if the documents do not have the same schema' , function ( done ) {
13771490 converter . json2csvAsync ( jsonTestData . differentSchemas , options )
13781491 . then ( function ( csv ) {
0 commit comments