Skip to content

Commit 8ab920d

Browse files
authored
Fix: Live Query Subscription Open Event (#1151)
* 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
1 parent 681016d commit 8ab920d

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

integration/test/ParseLiveQueryTest.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,20 @@ describe('Parse LiveQuery', () => {
205205
})
206206
await object.save({ foo: 'bar' });
207207
});
208+
209+
it('can subscribe with open event', async (done) => {
210+
const installationId = await Parse.CoreManager.getInstallationController().currentInstallationId();
211+
const client = await Parse.CoreManager.getLiveQueryController().getDefaultLiveQueryClient();
212+
const object = new TestObject();
213+
await object.save();
214+
215+
const query = new Parse.Query(TestObject);
216+
query.equalTo('objectId', object.id);
217+
const subscription = await query.subscribe();
218+
subscription.on('open', (response) => {
219+
assert.equal(response.clientId, client.id);
220+
assert.equal(response.installationId, installationId);
221+
done();
222+
})
223+
});
208224
});

src/LiveQueryClient.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ class LiveQueryClient extends EventEmitter {
374374
if (subscription) {
375375
subscription.subscribed = true;
376376
subscription.subscribePromise.resolve();
377-
subscription.emit(SUBSCRIPTION_EMMITER_TYPES.OPEN, response);
377+
setTimeout(() => subscription.emit(SUBSCRIPTION_EMMITER_TYPES.OPEN, response), 200);
378378
}
379379
break;
380380
case OP_EVENTS.ERROR:

src/__tests__/LiveQueryClient-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ describe('LiveQueryClient', () => {
182182
});
183183

184184
liveQueryClient._handleWebSocketMessage(event);
185-
185+
jest.runOnlyPendingTimers();
186186
expect(isChecked).toBe(true);
187187
});
188188

0 commit comments

Comments
 (0)