Skip to content
This repository has been archived by the owner on Dec 1, 2024. It is now read-only.

Commit

Permalink
add promise tests
Browse files Browse the repository at this point in the history
juliangruber committed Aug 26, 2017
1 parent 2d72c7b commit 5ddbef9
Showing 2 changed files with 70 additions and 0 deletions.
48 changes: 48 additions & 0 deletions test/batch-test.js
Original file line number Diff line number Diff line change
@@ -34,6 +34,26 @@ buster.testCase('batch()', {
})
},

'batch() with promise interface': function (done) {
this.openTestDatabase(function (db) {
db.batch([
{ type: 'put', key: 'foo', value: 'afoovalue' },
{ type: 'put', key: 'bar', value: 'abarvalue' },
{ type: 'put', key: 'baz', value: 'abazvalue' }
])
.then(function () {
async.forEach(['foo', 'bar', 'baz'], function (key, callback) {
db.get(key, function (err, value) {
refute(err)
assert.equals(value, 'a' + key + 'value')
callback()
})
}, done)
})
.catch(done)
})
},

'batch() no type set defaults to put': function (done) {
this.openTestDatabase(function (db) {
db.batch([
@@ -125,6 +145,34 @@ buster.testCase('batch()', {
})
},

'batch() with chained promise interface': function (done) {
this.openTestDatabase(function (db) {
db.put('1', 'one', function (err) {
refute(err)

db.batch()
.put('one', '1')
.del('two')
.put('three', '3')
.clear()
.del('1')
.put('2', 'two')
.put('3', 'three')
.del('3')
.write()
.then(function () {
async.forEach([ 'one', 'three', '1', '2', '3' ], function (key, callback) {
db.get(key, function (err) {
if ([ 'one', 'three', '1', '3' ].indexOf(key) > -1) { assert(err) } else { refute(err) }
callback()
})
}, done)
})
.catch(done)
})
})
},

'batch() exposes ops queue length': function (done) {
this.openTestDatabase(function (db) {
var batch = db.batch()
22 changes: 22 additions & 0 deletions test/get-put-del-test.js
Original file line number Diff line number Diff line change
@@ -44,6 +44,20 @@ buster.testCase('get() / put() / del()', {
})
},

'put() and get() promise interface': function (done) {
this.openTestDatabase(function (db) {
db.put('some key', 'some value stored in the database')
.then(function () {
return db.get('some key')
})
.then(function (value) {
assert.equals(value, 'some value stored in the database')
done()
})
.catch(done)
})
},

'del() on empty database doesn\'t cause error': function (done) {
this.openTestDatabase(function (db) {
db.del('undefkey', function (err) {
@@ -53,6 +67,14 @@ buster.testCase('get() / put() / del()', {
})
},

'del() promise interface': function (done) {
this.openTestDatabase(function (db) {
db.del('undefkey')
.then(done)
.catch(done)
})
},

'del() works on real entries': function (done) {
this.openTestDatabase(function (db) {
async.series([

0 comments on commit 5ddbef9

Please sign in to comment.