Skip to content

Commit

Permalink
Fix: Live Query Subscription Open Event (#1151)
Browse files Browse the repository at this point in the history
* Fix: Live Query Subscription Open Event

Closes: #1147

Waits 200 milliseconds to allow for client to set open event after the subscription resolves.

* fix tests
  • Loading branch information
dplewis committed Apr 22, 2020
1 parent 681016d commit 8ab920d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
16 changes: 16 additions & 0 deletions integration/test/ParseLiveQueryTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,20 @@ describe('Parse LiveQuery', () => {
})
await object.save({ foo: 'bar' });
});

it('can subscribe with open event', async (done) => {
const installationId = await Parse.CoreManager.getInstallationController().currentInstallationId();
const client = await Parse.CoreManager.getLiveQueryController().getDefaultLiveQueryClient();
const object = new TestObject();
await object.save();

const query = new Parse.Query(TestObject);
query.equalTo('objectId', object.id);
const subscription = await query.subscribe();
subscription.on('open', (response) => {
assert.equal(response.clientId, client.id);
assert.equal(response.installationId, installationId);
done();
})
});
});
2 changes: 1 addition & 1 deletion src/LiveQueryClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ class LiveQueryClient extends EventEmitter {
if (subscription) {
subscription.subscribed = true;
subscription.subscribePromise.resolve();
subscription.emit(SUBSCRIPTION_EMMITER_TYPES.OPEN, response);
setTimeout(() => subscription.emit(SUBSCRIPTION_EMMITER_TYPES.OPEN, response), 200);
}
break;
case OP_EVENTS.ERROR:
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/LiveQueryClient-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ describe('LiveQueryClient', () => {
});

liveQueryClient._handleWebSocketMessage(event);

jest.runOnlyPendingTimers();
expect(isChecked).toBe(true);
});

Expand Down

0 comments on commit 8ab920d

Please sign in to comment.