Skip to content

Commit b765ccc

Browse files
committed
Cleaned up csv parse test suite
refs https://github.com/TryGhost/Toolbox/issues/430 - Removed unnecessary "readCSV" leftover code.
1 parent a8281e9 commit b765ccc

File tree

1 file changed

+39
-44
lines changed

1 file changed

+39
-44
lines changed

packages/members-csv/test/parse.test.js

Lines changed: 39 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,36 @@ const assert = require('assert');
44
const {parse} = require('../index');
55
const csvPath = path.join(__dirname, '/fixtures/');
66

7-
const readCSV = ({filePath, mapping, defaultLabels}) => parse(filePath, mapping, defaultLabels);
8-
97
describe('parse', function () {
108
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);
1411

1512
should.exist(result);
1613
result.length.should.eql(0);
1714
});
1815

1916
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);
2319

2420
should.exist(result);
2521
result.length.should.eql(2);
2622
result[0].email.should.eql('[email protected]');
2723
result[1].email.should.eql('[email protected]');
2824
});
2925

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+
3034
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);
3437

3538
should.exist(result);
3639
result.length.should.eql(2);
@@ -39,12 +42,11 @@ describe('parse', function () {
3942
});
4043

4144
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);
4850

4951
should.exist(result);
5052
result.length.should.eql(2);
@@ -55,13 +57,12 @@ describe('parse', function () {
5557
});
5658

5759
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);
6566

6667
should.exist(result);
6768
result.length.should.eql(2);
@@ -75,12 +76,11 @@ describe('parse', function () {
7576
});
7677

7778
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);
8484

8585
should.exist(result);
8686
result.length.should.eql(2);
@@ -94,10 +94,9 @@ describe('parse', function () {
9494
});
9595

9696
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);
101100

102101
should.exist(result);
103102
result.length.should.eql(2);
@@ -111,9 +110,8 @@ describe('parse', function () {
111110
});
112111

113112
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);
117115

118116
should.exist(result);
119117
result.length.should.eql(2);
@@ -125,13 +123,11 @@ describe('parse', function () {
125123
});
126124

127125
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';
128127
const mapping = {
129128
subscribed_to_emails: 'subscribed'
130129
};
131-
const result = await readCSV({
132-
filePath: csvPath + 'subscribed-to-emails-header.csv',
133-
mapping
134-
});
130+
const result = await parse(filePath, mapping);
135131

136132
assert.ok(result);
137133
assert.equal(result.length, 2);
@@ -143,9 +139,8 @@ describe('parse', function () {
143139
});
144140

145141
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);
149144

150145
assert.ok(result);
151146
assert.equal(result.length, 2);

0 commit comments

Comments
 (0)