@@ -4,33 +4,36 @@ const assert = require('assert');
4
4
const { parse} = require ( '../index' ) ;
5
5
const csvPath = path . join ( __dirname , '/fixtures/' ) ;
6
6
7
- const readCSV = ( { filePath, mapping, defaultLabels} ) => parse ( filePath , mapping , defaultLabels ) ;
8
-
9
7
describe ( 'parse' , function ( ) {
10
8
it ( 'empty file' , async function ( ) {
11
- const result = await readCSV ( {
12
- filePath : csvPath + 'empty.csv'
13
- } ) ;
9
+ const filePath = csvPath + 'empty.csv' ;
10
+ const result = await parse ( filePath ) ;
14
11
15
12
should . exist ( result ) ;
16
13
result . length . should . eql ( 0 ) ;
17
14
} ) ;
18
15
19
16
it ( 'one column' , async function ( ) {
20
- const result = await readCSV ( {
21
- filePath : csvPath + 'single-column-with-header.csv'
22
- } ) ;
17
+ const filePath = csvPath + 'single-column-with-header.csv' ;
18
+ const result = await parse ( filePath ) ;
23
19
24
20
should . exist ( result ) ;
25
21
result . length . should . eql ( 2 ) ;
26
22
result [ 0 ] . email . should . eql ( '[email protected] ' ) ;
27
23
result [ 1 ] . email . should . eql ( '[email protected] ' ) ;
28
24
} ) ;
29
25
26
+ it ( 'one column without header mapping returns empty result' , async function ( ) {
27
+ const filePath = csvPath + 'single-column-with-header.csv' ;
28
+ const result = await parse ( filePath ) ;
29
+
30
+ should . exist ( result ) ;
31
+ result . length . should . eql ( 0 ) ;
32
+ } ) ;
33
+
30
34
it ( 'two columns, 1 filter' , async function ( ) {
31
- const result = await readCSV ( {
32
- filePath : csvPath + 'two-columns-with-header.csv'
33
- } ) ;
35
+ const filePath = csvPath + 'two-columns-with-header.csv' ;
36
+ const result = await parse ( filePath ) ;
34
37
35
38
should . exist ( result ) ;
36
39
result . length . should . eql ( 2 ) ;
@@ -39,12 +42,11 @@ describe('parse', function () {
39
42
} ) ;
40
43
41
44
it ( 'two columns, 2 filters' , async function ( ) {
42
- const result = await readCSV ( {
43
- filePath : csvPath + 'two-columns-obscure-header.csv' ,
44
- mapping : {
45
- 'Email Address' : 'email'
46
- }
47
- } ) ;
45
+ const filePath = csvPath + 'two-columns-obscure-header.csv' ;
46
+ const mapping = {
47
+ 'Email Address' : 'email'
48
+ } ;
49
+ const result = await parse ( filePath , mapping ) ;
48
50
49
51
should . exist ( result ) ;
50
52
result . length . should . eql ( 2 ) ;
@@ -55,13 +57,12 @@ describe('parse', function () {
55
57
} ) ;
56
58
57
59
it ( 'two columns with mapping' , async function ( ) {
58
- const result = await readCSV ( {
59
- filePath : csvPath + 'two-columns-mapping-header.csv' ,
60
- mapping : {
61
- correo_electronico : 'email' ,
62
- nombre : 'name'
63
- }
64
- } ) ;
60
+ const filePath = csvPath + 'two-columns-mapping-header.csv' ;
61
+ const mapping = {
62
+ correo_electronico : 'email' ,
63
+ nombre : 'name'
64
+ } ;
65
+ const result = await parse ( filePath , mapping ) ;
65
66
66
67
should . exist ( result ) ;
67
68
result . length . should . eql ( 2 ) ;
@@ -75,12 +76,11 @@ describe('parse', function () {
75
76
} ) ;
76
77
77
78
it ( 'two columns with partial mapping' , async function ( ) {
78
- const result = await readCSV ( {
79
- filePath : csvPath + 'two-columns-mapping-header.csv' ,
80
- mapping : {
81
- correo_electronico : 'email'
82
- }
83
- } ) ;
79
+ const filePath = csvPath + 'two-columns-mapping-header.csv' ;
80
+ const mapping = {
81
+ correo_electronico : 'email'
82
+ } ;
83
+ const result = await parse ( filePath , mapping ) ;
84
84
85
85
should . exist ( result ) ;
86
86
result . length . should . eql ( 2 ) ;
@@ -94,10 +94,9 @@ describe('parse', function () {
94
94
} ) ;
95
95
96
96
it ( 'two columns with empty mapping' , async function ( ) {
97
- const result = await readCSV ( {
98
- filePath : csvPath + 'two-columns-mapping-header.csv' ,
99
- mapping : { }
100
- } ) ;
97
+ const filePath = csvPath + 'two-columns-mapping-header.csv' ;
98
+ const mapping = { } ;
99
+ const result = await parse ( filePath , mapping ) ;
101
100
102
101
should . exist ( result ) ;
103
102
result . length . should . eql ( 2 ) ;
@@ -111,9 +110,8 @@ describe('parse', function () {
111
110
} ) ;
112
111
113
112
it ( 'transforms empty values to nulls' , async function ( ) {
114
- const result = await readCSV ( {
115
- filePath : csvPath + 'multiple-records-with-empty-values.csv'
116
- } ) ;
113
+ const filePath = csvPath + 'multiple-records-with-empty-values.csv' ;
114
+ const result = await parse ( filePath ) ;
117
115
118
116
should . exist ( result ) ;
119
117
result . length . should . eql ( 2 ) ;
@@ -125,13 +123,11 @@ describe('parse', function () {
125
123
} ) ;
126
124
127
125
it ( ' transforms "subscribed_to_emails" column to "subscribed" property when the mapping is passed in' , async function ( ) {
126
+ const filePath = csvPath + 'subscribed-to-emails-header.csv' ;
128
127
const mapping = {
129
128
subscribed_to_emails : 'subscribed'
130
129
} ;
131
- const result = await readCSV ( {
132
- filePath : csvPath + 'subscribed-to-emails-header.csv' ,
133
- mapping
134
- } ) ;
130
+ const result = await parse ( filePath , mapping ) ;
135
131
136
132
assert . ok ( result ) ;
137
133
assert . equal ( result . length , 2 ) ;
@@ -143,9 +139,8 @@ describe('parse', function () {
143
139
} ) ;
144
140
145
141
it ( 'DOES NOT transforms "subscribed_to_emails" column to "subscribed" property when the WITHOUT mapping' , async function ( ) {
146
- const result = await readCSV ( {
147
- filePath : csvPath + 'subscribed-to-emails-header.csv'
148
- } ) ;
142
+ const filePath = csvPath + 'subscribed-to-emails-header.csv' ;
143
+ const result = await parse ( filePath ) ;
149
144
150
145
assert . ok ( result ) ;
151
146
assert . equal ( result . length , 2 ) ;
0 commit comments