|
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'; |
4 | 2 |
|
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; |
7 | 9 |
|
8 | 10 | beforeEach( function() { |
9 | | - bucket = new Bucket( 'things', storeProvider ); |
| 11 | + bucket = new Bucket( 'things', storeProvider, new MockChannel() ); |
10 | 12 | store = bucket.store; |
11 | 13 | } ); |
12 | 14 |
|
13 | | - it( 'should fetch object data', function( done ) { |
| 15 | + it( 'should fetch object data callback', function( done ) { |
14 | 16 | var object = {title: 'hi'}; |
15 | 17 | store.objects = { |
16 | 18 | hello: object |
17 | 19 | }; |
18 | 20 |
|
19 | | - bucket.get( 'hello', function( e, found ) { |
20 | | - assert.deepEqual( found, object ); |
| 21 | + bucket.get( 'hello', ( e, found ) => { |
| 22 | + deepEqual( found, object ); |
21 | 23 | done(); |
22 | 24 | } ); |
23 | 25 | } ); |
24 | 26 |
|
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', |
27 | 40 | object = {one: 'two'}; |
28 | 41 |
|
29 | 42 | bucket.update( id, object, function() { |
30 | 43 | bucket.get( id, function( err, savedObject ) { |
31 | | - assert.deepEqual( object, savedObject ); |
| 44 | + deepEqual( object, savedObject ); |
32 | 45 | done(); |
33 | 46 | } ); |
34 | 47 | } ); |
35 | 48 | } ); |
36 | 49 |
|
37 | | - it( 'should update with options', function( done ) { |
38 | | - var id = 'thing', |
| 50 | + it( 'should update with options callback', ( done ) => { |
| 51 | + const id = 'thing', |
39 | 52 | object = {one: 'two'} |
40 | 53 |
|
41 | 54 | bucket.update( id, object, {}, function() { |
42 | 55 | bucket.get( id, function( err, savedObject ) { |
43 | | - assert.deepEqual( object, savedObject ); |
| 56 | + deepEqual( object, savedObject ); |
44 | 57 | done(); |
45 | 58 | } ) |
46 | 59 | } ) |
47 | 60 | } ); |
48 | 61 |
|
49 | | - it( 'should delete object data', function( done ) { |
| 62 | + it( 'should delete object data callback', ( done ) => { |
50 | 63 | store.objects = { |
51 | 64 | hello: {title: 'hola mundo'} |
52 | 65 | }; |
53 | 66 |
|
54 | 67 | bucket.remove( 'hello', function() { |
55 | | - assert.ok( !store.objects.hello ); |
| 68 | + ok( !store.objects.hello ); |
56 | 69 | done(); |
57 | 70 | } ); |
58 | 71 | } ); |
59 | 72 |
|
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 ) => { |
61 | 84 | store.objects = { |
62 | 85 | thing: { other: 'thing' } |
63 | 86 | }; |
64 | 87 | bucket.getVersion( 'thing', ( error, version ) => { |
65 | | - assert.equal( version, 0 ); |
| 88 | + equal( version, 0 ); |
| 89 | + done(); |
66 | 90 | } ); |
67 | 91 | } ); |
68 | 92 |
|
| 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 | + } ); |
69 | 101 | } ); |
70 | 102 |
|
0 commit comments