Skip to content

Commit 89345ad

Browse files
committed
Update ParseLiveQuery.spec.js
1 parent 67a39c7 commit 89345ad

File tree

1 file changed

+40
-35
lines changed

1 file changed

+40
-35
lines changed

spec/ParseLiveQuery.spec.js

+40-35
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ describe('ParseLiveQuery', function () {
645645
await object.save();
646646
});
647647

648-
it('LiveQuery with ACL', async done => {
648+
it('LiveQuery with ACL', async () => {
649649
await reconfigureServer({
650650
liveQuery: {
651651
classNames: ['Chat'],
@@ -659,49 +659,54 @@ describe('ParseLiveQuery', function () {
659659
user.setPassword('password');
660660
await user.signUp();
661661

662-
let calls = 0;
663-
664-
Parse.Cloud.beforeConnect(req => {
665-
expect(req.event).toBe('connect');
666-
expect(req.clients).toBe(0);
667-
expect(req.subscriptions).toBe(0);
668-
expect(req.useMasterKey).toBe(false);
669-
expect(req.installationId).toBeDefined();
670-
expect(req.client).toBeDefined();
671-
calls++;
672-
});
673-
674-
Parse.Cloud.beforeSubscribe('Chat', req => {
675-
expect(req.op).toBe('subscribe');
676-
expect(req.requestId).toBe(1);
677-
expect(req.query).toBeDefined();
678-
expect(req.user).toBeDefined();
679-
calls++;
680-
});
681-
682-
Parse.Cloud.afterLiveQueryEvent('Chat', req => {
683-
expect(req.user).toBeDefined();
684-
expect(req.object.get('foo')).toBe('bar');
685-
calls++;
686-
});
662+
const calls = {
663+
beforeConnect(req) {
664+
expect(req.event).toBe('connect');
665+
expect(req.clients).toBe(0);
666+
expect(req.subscriptions).toBe(0);
667+
expect(req.useMasterKey).toBe(false);
668+
expect(req.installationId).toBeDefined();
669+
expect(req.client).toBeDefined();
670+
},
671+
beforeSubscribe(req) {
672+
expect(req.op).toBe('subscribe');
673+
expect(req.requestId).toBe(1);
674+
expect(req.query).toBeDefined();
675+
expect(req.user).toBeDefined();
676+
},
677+
afterLiveQueryEvent(req) {
678+
expect(req.user).toBeDefined();
679+
expect(req.object.get('foo')).toBe('bar');
680+
},
681+
create(object) {
682+
expect(object.get('foo')).toBe('bar');
683+
},
684+
delete(object) {
685+
expect(object.get('foo')).toBe('bar');
686+
},
687+
};
688+
for (const key in calls) {
689+
console.log(key);
690+
spyOn(calls, key).and.callThrough();
691+
}
692+
Parse.Cloud.beforeConnect(calls.beforeConnect);
693+
Parse.Cloud.beforeSubscribe('Chat', calls.beforeSubscribe);
694+
Parse.Cloud.afterLiveQueryEvent('Chat', calls.afterLiveQueryEvent);
687695

688696
const chatQuery = new Parse.Query('Chat');
689697
const subscription = await chatQuery.subscribe();
690-
subscription.on('create', object => {
691-
expect(object.get('foo')).toBe('bar');
692-
expect(calls).toEqual(3);
693-
});
694-
subscription.on('delete', object => {
695-
expect(object.get('foo')).toBe('bar');
696-
expect(calls).toEqual(4);
697-
done();
698-
});
698+
subscription.on('create', calls.create);
699+
subscription.on('delete', calls.delete);
699700
const object = new Parse.Object('Chat');
700701
const acl = new Parse.ACL(user);
701702
object.setACL(acl);
702703
object.set({ foo: 'bar' });
703704
await object.save();
704705
await object.destroy();
706+
await new Promise(resolve => setTimeout(resolve, 200));
707+
for (const key in calls) {
708+
expect(calls[key]).toHaveBeenCalled();
709+
}
705710
});
706711

707712
it('handle invalid websocket payload length', async done => {

0 commit comments

Comments
 (0)