-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest.js
88 lines (72 loc) · 2.05 KB
/
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const fs = require('fs');
const expect = require('chai').expect;
const sqlite3 = require('sqlite3');
const rimraf = require('rimraf').sync;
const SqliteToJson = require('./');
const db = new sqlite3.Database(':memory:');
const exporter = new SqliteToJson({
client: db
});
const data = [
{ name: 'one' },
{ name: 'two' },
{ name: 'three' },
{ name: 'four' },
{ name: 'five' },
{ name: 'six' },
{ name: 'seven' },
{ name: 'eight' },
{ name: 'nine' },
{ name: 'ten' }
];
describe('sqliteToJson', function () {
before(function (done) {
rimraf('./.tmp');
db.serialize(function() {
db.run("CREATE TABLE numbers (name TEXT)");
var stmt = db.prepare("INSERT INTO numbers VALUES (?)");
data.forEach(function(row) {
stmt.run(row.name);
});
stmt.finalize();
done();
});
});
describe('#tables', function () {
it('should callback with all tables in the specified database', function (done) {
exporter.tables(function (err, tables) {
expect(tables).to.deep.equal(['numbers']);
done();
});
});
});
describe('#save', function () {
it('should callback with error if no destination is specified', function (done) {
var dest = './.tmp/numbers.json';
exporter.save('numbers', null, function(err) {
expect(err).to.not.be.null;
done();
})
});
it('should throw if no callback is specified', function () {
expect(function () {
exporter.save('numbers', 'file');
}).to.throw(/No callback/);
});
it('should export a table in a database to a file', function (done) {
var dest = './.tmp/numbers.json';
exporter.save('numbers', dest, function (err) {
expect(JSON.parse(fs.readFileSync(dest))).to.deep.equal(data);
done(err);
});
});
});
describe('#all', function() {
it('should export all data into a single object', function(done) {
exporter.all(function (err, all) {
expect(all && all.numbers).to.deep.equal(data);
done();
})
})
});
});