Skip to content

Commit d1cf05b

Browse files
committed
Move 409 tests to same place
1 parent d67f3b2 commit d1cf05b

File tree

1 file changed

+12
-31
lines changed

1 file changed

+12
-31
lines changed

test/simperium/channel_test.js

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,18 @@ describe( 'Channel', function() {
435435
} );
436436
} );
437437

438+
it( 'should acknowledge sent changes when receiving 409', ( done ) =>{
439+
channel.localQueue.sent['mock-id'] = { fake: 'change', ccid: 'dup-ccid', id: 'mock-id' };
440+
441+
bucket.once( 'error', done );
442+
443+
// when we get the 409 we should acknowledge the change and clear the sent queue
444+
channel.once( 'sent', () => done( 'Should not send a duplicate change' ) );
445+
channel.once( 'acknowledge', () => done() );
446+
447+
channel.handleMessage( 'c:[{"error": 409, "ccids":["dup-ccid"], "id": "mock-id"}]' );
448+
} );
449+
438450
describe( 'with synced object', () => {
439451
beforeEach( ( done ) => {
440452
var data = { title: 'hola mundo' };
@@ -456,37 +468,6 @@ describe( 'Channel', function() {
456468
done()
457469
} );
458470
} );
459-
460-
it( 'should handle a 409', ( done ) =>{
461-
const expectedChange = { fake: 'change', ccid: 'dup-ccid', id: 'mock-id' };
462-
channel.localQueue.sent['mock-id'] = { fake: 'change', ccid: 'dup-ccid', id: 'mock-id' };
463-
464-
/**
465-
* If the 409 is not handled the bucket will error
466-
*/
467-
bucket.once( 'error', ( e ) => {
468-
done( e );
469-
} );
470-
471-
/**
472-
* After successfully handling the 409 we should have an acknowledged
473-
* local change matching the duplicated ccid error.
474-
*/
475-
channel.once( 'acknowledge', ( id, change ) => {
476-
try {
477-
equal( id, 'mock-id' );
478-
deepEqual( expectedChange, change )
479-
done();
480-
} catch ( error ) {
481-
done( error );
482-
}
483-
} );
484-
485-
/**
486-
* Simulate receiving a 409
487-
*/
488-
channel.handleMessage( 'c:[{"error": 409, "ccids":["dup-ccid"], "id": "mock-id"}]' );
489-
} );
490471
} );
491472
} );
492473

0 commit comments

Comments
 (0)