Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Wise committed Sep 9, 2016
1 parent abba64f commit 81931f5
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 92 deletions.
2 changes: 1 addition & 1 deletion test/10.database.open.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var expect = require('chai').expect;
var fs = require('fs');
var Database = require('../.');

describe('Opening a database', function () {
describe('new Database()', function () {
it('should throw an exception when file path is not a string', function () {
expect(function () {new Database();}).to.throw(TypeError);
expect(function () {new Database(null);}).to.throw(TypeError);
Expand Down
21 changes: 4 additions & 17 deletions test/12.database.close.js → test/11.database.close.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var expect = require('chai').expect;
var Database = require('../.');

describe('Closing a database', function () {
describe('Database#close()', function () {
describe('before opening it', function () {
it('should never emit the "open" event', function (done) {
var db = new Database('temp/12.1.db');
var db = new Database('temp/11.1.db');
expect(db.open).to.be.false;
db.on('open', function () {
done(new Error('This event should not have been fired.'));
Expand All @@ -20,7 +20,7 @@ describe('Closing a database', function () {
});
describe('because of a failed open attempt', function (done) {
it('should have an Error object as its first parameter', function () {
var db = new Database('temp/nonexistent/abcfoobar123/12.2.db');
var db = new Database('temp/nonexistent/abcfoobar123/11.2.db');
db.on('open', function () {
done(new Error('This event should not have been fired.'));
});
Expand All @@ -33,7 +33,7 @@ describe('Closing a database', function () {
});
describe('after opening it', function () {
it('should emit the close event as normal', function (done) {
var db = new Database('temp/12.3.db');
var db = new Database('temp/11.3.db');
expect(db.open).to.be.false;
db.on('open', function () {
expect(db.open).to.be.true;
Expand All @@ -46,18 +46,5 @@ describe('Closing a database', function () {
});
});
});
it('should prevent further PRAGMA executions', function (done) {
var db = new Database('temp/12.4.db');
db.on('open', function () {
expect(db.pragma('cache_size', true)).to.equal('-16000');
db.close();
expect(function () {db.pragma('cache_size', true)}).to.throw(Error);
db.on('close', function (err) {
expect(err).to.be.null;
expect(function () {db.pragma('cache_size', true)}).to.throw(Error);
done();
});
});
});
});
});
74 changes: 0 additions & 74 deletions test/11.database.pragma.js

This file was deleted.

54 changes: 54 additions & 0 deletions test/12.database.pragma.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
var expect = require('chai').expect;
var Database = require('../.');

describe('Database#pragma()', function () {
it('should throw an exception if used before the database is open', function () {
var db = new Database('temp/12.1.db');
expect(function () {db.pragma('cache_size');}).to.throw(Error);
})
it('should throw an exception if a string is not provided', function (done) {
var db = new Database('temp/12.2.db');
db.on('open', function () {
expect(function () {db.pragma(123);}).to.throw(TypeError);
expect(function () {db.pragma(0);}).to.throw(TypeError);
expect(function () {db.pragma(null);}).to.throw(TypeError);
expect(function () {db.pragma();}).to.throw(TypeError);
expect(function () {db.pragma(new String('cache_size'));}).to.throw(TypeError);
done();
});
})
it('should throw an exception if invalid/redundant SQL is provided', function (done) {
var db = new Database('temp/12.3.db');
db.on('open', function () {
expect(function () {db.pragma('PRAGMA cache_size');}).to.throw(Error);
done();
});
})
it('should execute the pragma, returning rows of strings', function (done) {
var db = new Database('temp/12.4.db');
db.on('open', function () {
var rows = db.pragma('cache_size');
expect(rows[0].cache_size).to.be.a('string');
expect(+rows[0].cache_size).to.equal(-16000);
done();
});
});
it('should optionally return simpler results', function (done) {
var db = new Database('temp/12.5.db');
db.on('open', function () {
var cache_size = db.pragma('cache_size', true);
expect(cache_size).to.be.a('string');
expect(cache_size).to.equal('-16000');
done();
});
});
it('should obey PRAGMA changes', function (done) {
var db = new Database('temp/12.6.db');
db.on('open', function () {
expect(db.pragma('cache_size', true)).to.equal('-16000');
db.pragma('cache_size = -8000');
expect(db.pragma('cache_size', true)).to.equal('-8000');
done();
});
});
});

0 comments on commit 81931f5

Please sign in to comment.