@@ -13,7 +13,7 @@ describe('unparse', function () {
13
13
14
14
assert . ok ( result ) ;
15
15
16
- const expected = `id,email,name,note,subscribed_to_emails,complimentary_plan,stripe_customer_id,created_at,deleted_at,labels,tiers \r\n,[email protected] ,Sam Memberino,Early supporter,,,,,,,` ;
16
+ const expected = `id,email,name,note,subscribed_to_emails,complimentary_plan,stripe_customer_id,created_at,deleted_at,labels,products \r\n,[email protected] ,Sam Memberino,Early supporter,,,,,,,` ;
17
17
assert . equal ( result , expected ) ;
18
18
} ) ;
19
19
@@ -33,4 +33,74 @@ describe('unparse', function () {
33
33
34
34
assert . equal ( result , expected ) ;
35
35
} ) ;
36
+
37
+ it ( 'adds an error column to serialized CSV when present in columns and as a property' , function ( ) {
38
+ const json = [ {
39
+
40
+ error : 'things went south here!'
41
+ } ] ;
42
+ const columns = [
43
+ 'email' , 'error'
44
+ ] ;
45
+
46
+ const result = unparse ( json , columns ) ;
47
+ const expected = `email,error\r\[email protected] ,things went south here!` ;
48
+ assert . equal ( result , expected ) ;
49
+ } ) ;
50
+
51
+ it ( 'adds an error column automatically even if not present in columns' , function ( ) {
52
+ const json = [ {
53
+
54
+ error : 'things went south here!'
55
+ } ] ;
56
+ const columns = [
57
+ 'email'
58
+ ] ;
59
+
60
+ const result = unparse ( json , columns ) ;
61
+ const expected = `email,error\r\[email protected] ,things went south here!` ;
62
+ assert . equal ( result , expected ) ;
63
+ } ) ;
64
+
65
+ it ( 'handles labels as strings and as objects' , function ( ) {
66
+ const json = [ {
67
+
68
+ labels : 'member-email-label'
69
+ } , {
70
+
71
+ labels : [ {
72
+ name : 'second member label'
73
+ } ]
74
+ } , {
75
+
76
+ labels : [ 'banana, avocado' ]
77
+ } ] ;
78
+ const columns = [
79
+ 'email' , 'labels'
80
+ ] ;
81
+
82
+ const result = unparse ( json , columns ) ;
83
+ const expected = `email,labels\r
84
+ [email protected] ,member-email-label\r
85
+ [email protected] ,second member label\r
86
+ [email protected] ,"banana, avocado"`;
87
+ assert . equal ( result , expected ) ;
88
+ } ) ;
89
+
90
+ it ( 'handles the tiers to products property serialization' , function ( ) {
91
+ const json = [ {
92
+
93
+ tiers : [ {
94
+ name : 'Bronze Level'
95
+ } ]
96
+ } ] ;
97
+
98
+ const columns = [
99
+ 'email' , 'products'
100
+ ] ;
101
+
102
+ const result = unparse ( json , columns ) ;
103
+ const expected = `email,products\r\[email protected] ,Bronze Level` ;
104
+ assert . equal ( result , expected ) ;
105
+ } ) ;
36
106
} ) ;
0 commit comments