Skip to content

Commit 00a8553

Browse files
committed
Test for receiving unknown cv
1 parent 7dbe13c commit 00a8553

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

src/simperium/channel.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import uuid from 'node-uuid'
77

88
const jsondiff = new JSONDiff( {list_diff: false} )
99

10+
const UNKNOWN_CV = '?'
11+
1012
var operation = {
1113
MODIFY: 'M',
1214
REMOVE: '-'
@@ -218,6 +220,7 @@ export default function Channel( appid, access_token, bucket, store ) {
218220
message.on( 'i', this.onIndex.bind( this ) );
219221
message.on( 'c', this.onChanges.bind( this ) );
220222
message.on( 'e', this.onVersion.bind( this ) );
223+
message.on( 'cv', this.onChangeVersion.bind( this ) );
221224
message.on( 'o', function() {} );
222225

223226
this.networkQueue = new NetworkQueue();
@@ -403,8 +406,15 @@ Channel.prototype.onChanges = function( data ) {
403406
} );
404407
// emit ready after all server changes have been applied
405408
this.emit( 'ready' );
409+
};
410+
411+
Channel.prototype.onChangeVersion = function( data ) {
412+
if ( data === UNKNOWN_CV ) {
413+
// TODO: delete current cv
414+
// Start new index
415+
throw new Error( 'not implemented' );
416+
}
406417
}
407-
;
408418

409419
Channel.prototype.onVersion = function( data ) {
410420
var ghost = parseVersionMessage( data );

test/simperium/channel_test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,14 @@ describe( 'Channel', function() {
434434
} );
435435
} );
436436

437+
it( 'should request index when cv is unknown', done => {
438+
channel.once( 'send', ( data ) => {
439+
equal( data, '' );
440+
done()
441+
} )
442+
channel.handleMessage( 'cv:?' );
443+
} )
444+
437445
it( 'should emit index and ready event when index complete', () => new Promise( resolve => {
438446
var page = 'i:{"index":[{"id":"objectid","v":1,"d":{"title":"Hello World"}}],"current":"cv"}';
439447
let indexed = false

0 commit comments

Comments
 (0)