Skip to content

Commit

Permalink
Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yasserf committed Jun 23, 2016
1 parent e80a150 commit fec3ee9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 34 deletions.
10 changes: 4 additions & 6 deletions src/record/record-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ RecordHandler.prototype._$handle = function( message ) {
* A (presumably unsolvable) problem remains when a client deletes a record in the exact moment
* between another clients creation and read message for the same record
*/
if( message.data[ 0 ] === C.ACTIONS.DELETE || message.data[ 0 ] === C.ACTIONS.UNSUBSCRIBE ) {
if( message.data[ 0 ] === C.ACTIONS.DELETE ||
message.data[ 0 ] === C.ACTIONS.UNSUBSCRIBE ||
( message.data[ 0 ] === C.EVENT.MESSAGE_DENIED && message.data[ 2 ] === C.ACTIONS.DELETE )
) {
this._destroyEventEmitter.emit( 'destroy_ack_' + name, message );

if( message.data[ 0 ] === C.ACTIONS.DELETE && this._records[ name ] ) {
Expand All @@ -214,11 +217,6 @@ RecordHandler.prototype._$handle = function( message ) {
return;
}

if( message.data[ 0 ] === C.EVENT.MESSAGE_DENIED && message.data[ 2 ] === C.ACTIONS.DELETE ) {
console.log( 'TODO' );
return;
}

} else {
name = message.data[ 0 ];
}
Expand Down
2 changes: 0 additions & 2 deletions src/record/record.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,8 @@ Record.prototype._$onMessage = function( message ) {
this._recoverRecord( message.data[ 2 ], JSON.parse( message.data[ 3 ] ), message );
}
else if( message.data[ 0 ] === C.EVENT.MESSAGE_DENIED ) {
message.processedError = true;
clearInterval( this._readAckTimeout );
clearInterval( this._readTimeout );
this.emit( 'error', C.EVENT.MESSAGE_DENIED );
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/rpc/rpc-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ RpcHandler.prototype._$handle = function( message ) {
return;
}
else if( message.data[ 2 ] === C.ACTIONS.REQUEST ) {
rpcName = message.data[ 3 ];
correlationId = message.data[ 4 ];
rpcName = message.data[ 1 ];
correlationId = message.data[ 3 ];
}
} else {
rpcName = message.data[ 1 ];
Expand Down
35 changes: 14 additions & 21 deletions test-e2e/specs/record-redis-permissionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe( 'record permissions with internal cache', function() {
it( 'creates the record with clientA and sets some data', function( done ){
var record = clientA.record.getRecord( 'open/some-user' );
record.set( 'firstname', 'wolfram' );
setTimeout( done, 100 );
setTimeout( done, 200 );
});

it( 'reads from the open record using clientB', function( done ){
Expand Down Expand Up @@ -125,15 +125,10 @@ describe( 'record permissions with internal cache', function() {
});

it( 'reads public and write is private', function( done ) {
console.log('==============================')
var recA1 = clientA.record.getRecord( 'public-read-private-write/client-a' );
var recB1 = clientB.record.getRecord( 'public-read-private-write/client-a' );
var recASubscribeCalled = false;

clientB.on( 'error', function(){
console.log( new Error().stack )
});

recA1.subscribe( 'firstname', function( firstname ){
var recASubscribeCalled = true;
expect( 'it should never get here' ).toBe( true );
Expand All @@ -144,12 +139,10 @@ describe( 'record permissions with internal cache', function() {
expect( recASubscribeCalled ).toBe( false );
expect( recA1.get( 'lastname' ) ).toBe( undefined );
expect( clientAErrors.length ).toBe( 0 );
console.log( clientBErrors)
expect( clientBErrors.length ).toBe( 1 );
assertMessageDenied( clientBErrors );
console.log('==============================')
done();
}, 100 );
}, 200 );
});
});

Expand All @@ -172,9 +165,9 @@ describe( 'record permissions with internal cache', function() {
rec.set( 'value', 2 );
setTimeout(function(){
expect( clientAErrors.length ).toBe( 1 );
assertMessageDenied( clientAErrors );
assertMessageDenied( clientAErrors );
done();
}, 100 );
}, 200 );
});

it( 'sends a valid update, which results in a version conflict', function( done ) {
Expand All @@ -186,7 +179,7 @@ describe( 'record permissions with internal cache', function() {
setTimeout(function(){
expect( clientAErrors.length ).toBe( 0 );
done();
}, 100 );
}, 200 );
});

it( 'works when setting values in quick succession', function( done ) {
Expand All @@ -206,7 +199,7 @@ describe( 'record permissions with internal cache', function() {
var incrementRecord = clientA.record.getRecord( 'only-increment' );
var decrementRecord = clientB.record.getRecord( 'only-decrement' );

decrementRecord.set( { value: 100 });
decrementRecord.set( { value: 200 });
incrementRecord.set( { value: 8 });
decrementRecord.set( { value: 99 });
incrementRecord.set( { value: 9 });
Expand All @@ -233,7 +226,7 @@ describe( 'record permissions with internal cache', function() {
clientA.record.getRecord( 'only-delete-egon-miller/Egon/fisher' );
clientA.record.getRecord( 'only-delete-egon-miller/mike/fisher' );
clientA.record.getRecord( 'only-delete-egon-miller/Egon/miller' );
setTimeout( done, 100 );
setTimeout( done, 200 );
});

it( 'fails to delete egon fisher', function( done ){
Expand All @@ -243,7 +236,7 @@ describe( 'record permissions with internal cache', function() {
expect( clientAErrors.length ).toBe( 1 );
assertMessageDenied( clientAErrors );
done();
}, 100 );
}, 200 );
});

it( 'successfully deletes egon miller', function( done ){
Expand All @@ -252,7 +245,7 @@ describe( 'record permissions with internal cache', function() {
setTimeout(function(){
expect( clientAErrors.length ).toBe( 0 );
done();
}, 100 );
}, 200 );
});

it( 'fails to delete mike fisher', function( done ){
Expand All @@ -262,15 +255,15 @@ describe( 'record permissions with internal cache', function() {
expect( clientAErrors.length ).toBe( 1 );
assertMessageDenied( clientAErrors );
done();
}, 100 );
}, 200 );
});
});

describe( 'it cross references another record in a permission', function(){
it( 'creates the cross referenced records', function( done ){
clientA.record.getRecord( 'item/a' ).set( 'stock', 3 );
clientA.record.getRecord( 'item/b' ).set( 'stock', 0 );
setTimeout( done, 50 );
setTimeout( done, 200 );
});

it( 'successfully creates a transaction for an item that is in stock', function( done ){
Expand All @@ -285,7 +278,7 @@ describe( 'record permissions with internal cache', function() {
setTimeout(function(){
expect( clientAErrors.length ).toBe( 0 );
done();
}, 100 );
}, 200 );
});

it( 'fails to create a transaction for an item that is out of stock', function( done ){
Expand All @@ -301,7 +294,7 @@ describe( 'record permissions with internal cache', function() {
expect( clientAErrors.length ).toBe( 1 );
assertMessageDenied( clientAErrors );
done();
}, 100 );
}, 200 );
});

it( 'sets the amout of items to 0 and immediately retries the transaction', function( done ){
Expand All @@ -318,7 +311,7 @@ describe( 'record permissions with internal cache', function() {
expect( clientAErrors.length ).toBe( 1 );
assertMessageDenied( clientAErrors );
done();
}, 100 );
}, 200 );
});
});

Expand Down
11 changes: 8 additions & 3 deletions test-e2e/specs/rpc-permissionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var DeepstreamServer = require( 'deepstream.io' ),
deepstreamClient = require( '../../src/client' ),
TestLogger = require( '../tools/test-logger' );

describe( 'event permissions', function() {
describe( 'rpc permissions', function() {
var deepstreamServer,
logger = new TestLogger(),
clientA,
Expand Down Expand Up @@ -104,7 +104,7 @@ describe( 'event permissions', function() {
expect( clientAErrors.length ).toBe( 0 );
expect( clientBErrors.length ).toBe( 1 );
//TODO order is muddled up, should be [ 0 ][ 1 ]
expect( clientBErrors[ 0 ][ 0 ] ).toBe( 'MESSAGE_DENIED' );
expect( clientBErrors[ 0 ][ 0 ] ).toEqual( [ 'MESSAGE_DENIED', 'a-provide-b-request', 'S' ] );
done();
}, 40 );
});
Expand Down Expand Up @@ -140,7 +140,12 @@ describe( 'event permissions', function() {
setTimeout( function(){
expect( clientAErrors.length ).toBe( 0 );
expect( clientBErrors.length ).toBe( 1 );
expect( clientBErrors[ 0 ][ 0 ] ).toBe( 'MESSAGE_PERMISSION_ERROR' );
console.log( clientBErrors[ 0 ][ 0 ] )
expect( clientBErrors[ 0 ][ 0 ][ 0 ] ).toBe( 'MESSAGE_PERMISSION_ERROR' );
expect( clientBErrors[ 0 ][ 0 ][ 1 ] ).toBe( 'only-full-user-data' );
expect( clientBErrors[ 0 ][ 0 ][ 2 ] ).toBe( 'REQ' );
// Number 3 is correlation id, which is random
expect( clientBErrors[ 0 ][ 0 ][ 4 ] ).toBe( 'L' );
done();
}, 100 );
});
Expand Down

0 comments on commit fec3ee9

Please sign in to comment.