Skip to content

Commit 04af5a6

Browse files
committed
Adds tests for promise interface in addition to the callback interface
1 parent 66a3398 commit 04af5a6

1 file changed

Lines changed: 51 additions & 19 deletions

File tree

test/simperium/bucket_test.js

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,102 @@
1-
import assert from 'assert'
2-
import Bucket from '../../src/simperium/bucket'
3-
import storeProvider from './mock_bucket_store'
1+
import { ok, equal, deepEqual } from 'assert';
42

5-
describe( 'Bucket', function() {
6-
var bucket, store;
3+
import Bucket from '../../src/simperium/bucket';
4+
import storeProvider from './mock_bucket_store';
5+
import { MockChannel } from './mock-channel';
6+
7+
describe( 'Bucket', () => {
8+
let bucket, store;
79

810
beforeEach( function() {
9-
bucket = new Bucket( 'things', storeProvider );
11+
bucket = new Bucket( 'things', storeProvider, new MockChannel() );
1012
store = bucket.store;
1113
} );
1214

13-
it( 'should fetch object data', function( done ) {
15+
it( 'should fetch object data callback', function( done ) {
1416
var object = {title: 'hi'};
1517
store.objects = {
1618
hello: object
1719
};
1820

19-
bucket.get( 'hello', function( e, found ) {
20-
assert.deepEqual( found, object );
21+
bucket.get( 'hello', ( e, found ) => {
22+
deepEqual( found, object );
2123
done();
2224
} );
2325
} );
2426

25-
it( 'should store object update', function( done ) {
26-
var id = 'thing',
27+
it( 'should fetch object data promise', () => {
28+
var object = {title: 'hi'};
29+
store.objects = {
30+
hello: object
31+
};
32+
33+
return bucket.get( 'hello' ).then( found => {
34+
deepEqual( found, object );
35+
} );
36+
} );
37+
38+
it( 'should store object update callback', ( done ) => {
39+
const id = 'thing',
2740
object = {one: 'two'};
2841

2942
bucket.update( id, object, function() {
3043
bucket.get( id, function( err, savedObject ) {
31-
assert.deepEqual( object, savedObject );
44+
deepEqual( object, savedObject );
3245
done();
3346
} );
3447
} );
3548
} );
3649

37-
it( 'should update with options', function( done ) {
38-
var id = 'thing',
50+
it( 'should update with options callback', ( done ) => {
51+
const id = 'thing',
3952
object = {one: 'two'}
4053

4154
bucket.update( id, object, {}, function() {
4255
bucket.get( id, function( err, savedObject ) {
43-
assert.deepEqual( object, savedObject );
56+
deepEqual( object, savedObject );
4457
done();
4558
} )
4659
} )
4760
} );
4861

49-
it( 'should delete object data', function( done ) {
62+
it( 'should delete object data callback', ( done ) => {
5063
store.objects = {
5164
hello: {title: 'hola mundo'}
5265
};
5366

5467
bucket.remove( 'hello', function() {
55-
assert.ok( !store.objects.hello );
68+
ok( !store.objects.hello );
5669
done();
5770
} );
5871
} );
5972

60-
it( 'should fetch object version', () => {
73+
it( 'should delete object data promise', () => {
74+
store.objects = {
75+
hello: {title: 'hola mundo'}
76+
};
77+
78+
return bucket.remove( 'hello' ).then( () => {
79+
ok( !store.objects.hello );
80+
} );
81+
} );
82+
83+
it( 'should fetch object version callback', ( done ) => {
6184
store.objects = {
6285
thing: { other: 'thing' }
6386
};
6487
bucket.getVersion( 'thing', ( error, version ) => {
65-
assert.equal( version, 0 );
88+
equal( version, 0 );
89+
done();
6690
} );
6791
} );
6892

93+
it( 'should fetch object version promise', () => {
94+
store.objects = {
95+
thing: { other: 'thing' }
96+
};
97+
bucket.getVersion( 'thing' ).then( ( version ) => {
98+
equal( version, 0 );
99+
} );
100+
} );
69101
} );
70102

0 commit comments

Comments
 (0)