Skip to content

Commit

Permalink
Bug/#140 snapshot whenready (#192)
Browse files Browse the repository at this point in the history
* bug/record-handler: Fixes #140

* Fix #140 adding test for snapshot ready
  • Loading branch information
yasserf authored and timaschew committed Jul 28, 2016
1 parent 45cc40a commit 7e574b2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/record/record-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ RecordHandler.prototype.unlisten = function( pattern ) {
* @public
*/
RecordHandler.prototype.snapshot = function( name, callback ) {
if( this._records[ name ] ) {
if( this._records[ name ] && this._records[ name ].isReady ) {
callback( null, this._records[ name ].get() );
} else {
this._snapshotRegistry.request( name, callback );
Expand Down
15 changes: 13 additions & 2 deletions test-e2e/specs/record-snapshotSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe( 'record snapshot', function() {

it( 'creates clientA', function( done ) {
clientA = deepstreamClient( 'localhost:6021' );
clientA.login( null, function(){ done(); });
clientA.login( null, done );
});

/**************** TEST ****************/
Expand Down Expand Up @@ -59,12 +59,23 @@ describe( 'record snapshot', function() {
clientA.record.snapshot( 'localRecord', function( error, data ) {
expect( error ).toBeNull();
expect( data ).toEqual( { key: 'value' } );
done();
record.on( 'discard', done );
record.discard();
} );
}, 10 );
} );
});

it( 'retrieves remote snapshot if client record is not ready', function( done ){
var record = clientA.record.getRecord( 'localRecord' );

clientA.record.snapshot( 'localRecord', function( error, data ) {
expect( error ).toBeNull();
expect( data ).toEqual( { key: 'value' } );
done();
} );
});

/**************** TEAR DOWN ****************/
it( 'closes the clients', function() {
clientA.close();
Expand Down

0 comments on commit 7e574b2

Please sign in to comment.