2016-05-08 10:12:37 +03:00
|
|
|
|
|
|
|
var utils = require('../../../server/utils'),
|
|
|
|
should = require('should'),
|
2016-06-03 14:35:17 +03:00
|
|
|
path = require ('path'),
|
|
|
|
csvPath = path.join(__dirname, '../../utils/fixtures/csv/');
|
2016-05-08 10:12:37 +03:00
|
|
|
|
|
|
|
describe('read csv', function () {
|
|
|
|
it('read csv: one column', function (done) {
|
|
|
|
utils.readCSV({
|
2016-06-03 14:35:17 +03:00
|
|
|
path: csvPath + 'single-column-with-header.csv',
|
|
|
|
columnsToExtract: [{name: 'email', lookup: /email/i}]
|
2016-05-08 10:12:37 +03:00
|
|
|
}).then(function (result) {
|
|
|
|
should.exist(result);
|
2016-06-03 14:35:17 +03:00
|
|
|
result.length.should.eql(3);
|
|
|
|
result[0].email.should.eql('email');
|
2016-10-03 17:11:43 +03:00
|
|
|
result[1].email.should.eql('jbloggs@example.com');
|
|
|
|
result[2].email.should.eql('test@example.com');
|
2016-05-08 10:12:37 +03:00
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
2016-06-03 14:35:17 +03:00
|
|
|
it('read csv: two columns, 1 filter', function (done) {
|
2016-05-08 10:12:37 +03:00
|
|
|
utils.readCSV({
|
2016-06-03 14:35:17 +03:00
|
|
|
path: csvPath + 'two-columns-with-header.csv',
|
|
|
|
columnsToExtract: [{name: 'email', lookup: /email/i}]
|
2016-05-08 10:12:37 +03:00
|
|
|
}).then(function (result) {
|
|
|
|
should.exist(result);
|
|
|
|
result.length.should.eql(2);
|
2016-10-03 17:11:43 +03:00
|
|
|
result[0].email.should.eql('jbloggs@example.com');
|
|
|
|
result[1].email.should.eql('test@example.com');
|
2016-05-08 10:12:37 +03:00
|
|
|
should.not.exist(result[0].id);
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
2016-06-03 14:35:17 +03:00
|
|
|
it('read csv: two columns, 2 filters', function (done) {
|
2016-05-08 10:12:37 +03:00
|
|
|
utils.readCSV({
|
2016-06-03 14:35:17 +03:00
|
|
|
path: csvPath + 'two-columns-obscure-header.csv',
|
|
|
|
columnsToExtract: [
|
|
|
|
{name: 'email', lookup: /email/i},
|
|
|
|
{name: 'id', lookup: /id/i}
|
|
|
|
]
|
2016-05-08 10:12:37 +03:00
|
|
|
}).then(function (result) {
|
|
|
|
should.exist(result);
|
|
|
|
result.length.should.eql(2);
|
2016-10-03 17:11:43 +03:00
|
|
|
result[0].email.should.eql('jbloggs@example.com');
|
2016-05-08 10:12:37 +03:00
|
|
|
result[0].id.should.eql('1');
|
2016-10-03 17:11:43 +03:00
|
|
|
result[1].email.should.eql('test@example.com');
|
2016-05-08 10:12:37 +03:00
|
|
|
result[1].id.should.eql('2');
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
});
|