Skip to content

Commit ca414a6

Browse files
committed
Adds tests for getVersion
- sv will be > 0 in tests to emulate the server
1 parent 9a1abc5 commit ca414a6

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

test/simperium/bucket_test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,15 @@ describe( 'Bucket', function() {
5656
done();
5757
} );
5858
} );
59+
60+
it( 'should fetch object version', () => {
61+
store.objects = {
62+
thing: { other: 'thing' }
63+
};
64+
bucket.getVersion( 'thing', ( error, version ) => {
65+
assert.equal( version, 0 );
66+
} );
67+
} );
68+
5969
} );
6070

test/simperium/channel_test.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,31 @@ describe( 'Channel', function() {
403403
// send a 405 error
404404
channel.handleMessage( 'c:' + JSON.stringify( [{error: 405, id: 'thing', ccids: ['abc']}] ) );
405405
} );
406+
407+
describe( 'with synced object', () => {
408+
beforeEach( ( done ) => {
409+
var data = { title: 'hola mundo' };
410+
411+
channel.on( 'acknowledge', function( id ) {
412+
done();
413+
} );
414+
415+
channel.on( 'send', function( msg ) {
416+
acknowledge( channel, msg );
417+
} );
418+
419+
bucket.update( 'mock-id', data );
420+
} );
421+
422+
it( 'should get version', ( done ) => {
423+
bucket.getVersion( 'mock-id', ( error, version ) => {
424+
assert.equal( version, 1 );
425+
done()
426+
} );
427+
} );
428+
429+
} );
430+
406431
} );
407432

408433
it( 'should request index when cv is unknown', done => {
@@ -513,7 +538,7 @@ function acknowledge( channel, msg, cv ) {
513538
id: change.id,
514539
o: change.o,
515540
v: change.v,
516-
ev: change.sv ? change.sv + 1 : 0,
541+
ev: change.sv ? change.sv + 1 : 1,
517542
ccids: [change.ccid],
518543
cv: cv || uuid.v4()
519544
};

0 commit comments

Comments
 (0)