forked from olivierkaisin/node-csv-query
-
Notifications
You must be signed in to change notification settings - Fork 1
/
db.test.js
66 lines (58 loc) · 1.93 KB
/
db.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* eslint-env mocha */
import path from 'path';
import { expect } from 'chai';
import csvdb from '..';
describe('classic dataset', () => {
let databaseConnection = null;
before((done) => {
csvdb(path.join(__dirname, './fixtures/dataset.csv')).then((db) => {
databaseConnection = db;
done();
}).catch(err => done(err));
});
it('should find 0 record', (done) => {
databaseConnection.find({ firstName: 'Mike' }).then((records) => {
expect(records).to.have.lengthOf(0);
done();
}).catch(err => done(err));
});
it('should find 1 record', (done) => {
databaseConnection.find({ firstName: 'Olivier' }).then((records) => {
expect(records).to.have.lengthOf(1);
done();
}).catch(err => done(err));
});
it('should find 2 records', (done) => {
databaseConnection.find({ firstName: 'Alex' }).then((records) => {
expect(records).to.have.lengthOf(2);
done();
}).catch(err => done(err));
});
it('should findOne record', (done) => {
databaseConnection.findOne({ firstName: 'Alex' }).then((record) => {
expect(record.firstName).to.equals('Alex');
done();
}).catch(err => done(err));
});
it('should find 2 records with an i in their first name', (done) => {
databaseConnection.find(({ firstName }) => firstName.includes('i')).then((records) => {
expect(records).to.have.lengthOf(2);
done();
}).catch(err => done(err));
});
});
describe('custom dataset', () => {
let databaseConnection = null;
before((done) => {
csvdb(path.join(__dirname, './fixtures/dataset_custom.csv'), { rtrim: true, delimiter: ';', comment: '#' }).then((db) => {
databaseConnection = db;
done();
}).catch(err => done(err));
});
it('should find 2 records', (done) => {
databaseConnection.find({ firstName: 'Alex' }).then((records) => {
expect(records).to.have.lengthOf(2);
done();
}).catch(err => done(err));
});
});