Skip to content

Commit

Permalink
Update ParseLiveQuery.spec.js
Browse files Browse the repository at this point in the history
  • Loading branch information
dblythy committed Apr 23, 2021
1 parent aef2881 commit 517d050
Showing 1 changed file with 40 additions and 35 deletions.
75 changes: 40 additions & 35 deletions spec/ParseLiveQuery.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ describe('ParseLiveQuery', function () {
await object.save();
});

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

let calls = 0;

Parse.Cloud.beforeConnect(req => {
expect(req.event).toBe('connect');
expect(req.clients).toBe(0);
expect(req.subscriptions).toBe(0);
expect(req.useMasterKey).toBe(false);
expect(req.installationId).toBeDefined();
expect(req.client).toBeDefined();
calls++;
});

Parse.Cloud.beforeSubscribe('Chat', req => {
expect(req.op).toBe('subscribe');
expect(req.requestId).toBe(1);
expect(req.query).toBeDefined();
expect(req.user).toBeDefined();
calls++;
});

Parse.Cloud.afterLiveQueryEvent('Chat', req => {
expect(req.user).toBeDefined();
expect(req.object.get('foo')).toBe('bar');
calls++;
});
const calls = {
beforeConnect(req) {
expect(req.event).toBe('connect');
expect(req.clients).toBe(0);
expect(req.subscriptions).toBe(0);
expect(req.useMasterKey).toBe(false);
expect(req.installationId).toBeDefined();
expect(req.client).toBeDefined();
},
beforeSubscribe(req) {
expect(req.op).toBe('subscribe');
expect(req.requestId).toBe(1);
expect(req.query).toBeDefined();
expect(req.user).toBeDefined();
},
afterLiveQueryEvent(req) {
expect(req.user).toBeDefined();
expect(req.object.get('foo')).toBe('bar');
},
create(object) {
expect(object.get('foo')).toBe('bar');
},
delete(object) {
expect(object.get('foo')).toBe('bar');
},
};
for (const key in calls) {
console.log(key);
spyOn(calls, key).and.callThrough();
}
Parse.Cloud.beforeConnect(calls.beforeConnect);
Parse.Cloud.beforeSubscribe('Chat', calls.beforeSubscribe);
Parse.Cloud.afterLiveQueryEvent('Chat', calls.afterLiveQueryEvent);

const chatQuery = new Parse.Query('Chat');
const subscription = await chatQuery.subscribe();
subscription.on('create', object => {
expect(object.get('foo')).toBe('bar');
expect(calls).toEqual(3);
});
subscription.on('delete', object => {
expect(object.get('foo')).toBe('bar');
expect(calls).toEqual(4);
done();
});
subscription.on('create', calls.create);
subscription.on('delete', calls.delete);
const object = new Parse.Object('Chat');
const acl = new Parse.ACL(user);
object.setACL(acl);
object.set({ foo: 'bar' });
await object.save();
await object.destroy();
await new Promise(resolve => setTimeout(resolve, 200));
for (const key in calls) {
expect(calls[key]).toHaveBeenCalled();
}
});

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

0 comments on commit 517d050

Please sign in to comment.