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

Commit 5ddbef9

Browse files
committed
add promise tests
1 parent 2d72c7b commit 5ddbef9

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

test/batch-test.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,26 @@ buster.testCase('batch()', {
3434
})
3535
},
3636

37+
'batch() with promise interface': function (done) {
38+
this.openTestDatabase(function (db) {
39+
db.batch([
40+
{ type: 'put', key: 'foo', value: 'afoovalue' },
41+
{ type: 'put', key: 'bar', value: 'abarvalue' },
42+
{ type: 'put', key: 'baz', value: 'abazvalue' }
43+
])
44+
.then(function () {
45+
async.forEach(['foo', 'bar', 'baz'], function (key, callback) {
46+
db.get(key, function (err, value) {
47+
refute(err)
48+
assert.equals(value, 'a' + key + 'value')
49+
callback()
50+
})
51+
}, done)
52+
})
53+
.catch(done)
54+
})
55+
},
56+
3757
'batch() no type set defaults to put': function (done) {
3858
this.openTestDatabase(function (db) {
3959
db.batch([
@@ -125,6 +145,34 @@ buster.testCase('batch()', {
125145
})
126146
},
127147

148+
'batch() with chained promise interface': function (done) {
149+
this.openTestDatabase(function (db) {
150+
db.put('1', 'one', function (err) {
151+
refute(err)
152+
153+
db.batch()
154+
.put('one', '1')
155+
.del('two')
156+
.put('three', '3')
157+
.clear()
158+
.del('1')
159+
.put('2', 'two')
160+
.put('3', 'three')
161+
.del('3')
162+
.write()
163+
.then(function () {
164+
async.forEach([ 'one', 'three', '1', '2', '3' ], function (key, callback) {
165+
db.get(key, function (err) {
166+
if ([ 'one', 'three', '1', '3' ].indexOf(key) > -1) { assert(err) } else { refute(err) }
167+
callback()
168+
})
169+
}, done)
170+
})
171+
.catch(done)
172+
})
173+
})
174+
},
175+
128176
'batch() exposes ops queue length': function (done) {
129177
this.openTestDatabase(function (db) {
130178
var batch = db.batch()

test/get-put-del-test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ buster.testCase('get() / put() / del()', {
4444
})
4545
},
4646

47+
'put() and get() promise interface': function (done) {
48+
this.openTestDatabase(function (db) {
49+
db.put('some key', 'some value stored in the database')
50+
.then(function () {
51+
return db.get('some key')
52+
})
53+
.then(function (value) {
54+
assert.equals(value, 'some value stored in the database')
55+
done()
56+
})
57+
.catch(done)
58+
})
59+
},
60+
4761
'del() on empty database doesn\'t cause error': function (done) {
4862
this.openTestDatabase(function (db) {
4963
db.del('undefkey', function (err) {
@@ -53,6 +67,14 @@ buster.testCase('get() / put() / del()', {
5367
})
5468
},
5569

70+
'del() promise interface': function (done) {
71+
this.openTestDatabase(function (db) {
72+
db.del('undefkey')
73+
.then(done)
74+
.catch(done)
75+
})
76+
},
77+
5678
'del() works on real entries': function (done) {
5779
this.openTestDatabase(function (db) {
5880
async.series([

0 commit comments

Comments
 (0)