Skip to content

Commit 24cc493

Browse files
committed
Cleanup and Documentation
1 parent 0efa36a commit 24cc493

File tree

4 files changed

+263
-264
lines changed

4 files changed

+263
-264
lines changed

spec/ParseLiveQueryServer.spec.js

Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ describe('ParseLiveQueryServer', function () {
232232
classNames: ['Yolo'],
233233
},
234234
})
235-
.then((parseServer) => {
235+
.then(parseServer => {
236236
saveSpy = spyOn(parseServer.config.liveQueryController, 'onAfterSave');
237237
deleteSpy = spyOn(
238238
parseServer.config.liveQueryController,
@@ -247,7 +247,7 @@ describe('ParseLiveQueryServer', function () {
247247
const obj = new Parse.Object('Yolo');
248248
return obj.save();
249249
})
250-
.then((obj) => {
250+
.then(obj => {
251251
return obj.destroy();
252252
})
253253
.then(() => {
@@ -307,6 +307,52 @@ describe('ParseLiveQueryServer', function () {
307307
expect(client.pushConnect).toHaveBeenCalled();
308308
});
309309

310+
it('basic beforeConnect rejection', async () => {
311+
Parse.Cloud.beforeConnect(function () {
312+
throw new Error('You shall not pass!');
313+
});
314+
const parseLiveQueryServer = new ParseLiveQueryServer({});
315+
const parseWebSocket = {
316+
clientId: -1,
317+
};
318+
await parseLiveQueryServer._handleConnect(parseWebSocket, {
319+
sessionToken: 'token',
320+
});
321+
expect(parseLiveQueryServer.clients.size).toBe(0);
322+
const Client = require('../lib/LiveQuery/Client').Client;
323+
expect(Client.pushError).toHaveBeenCalled();
324+
});
325+
326+
it('basic beforeSubscribe rejection', async () => {
327+
Parse.Cloud.beforeSubscribe('test', function () {
328+
throw new Error('You shall not pass!');
329+
});
330+
const parseLiveQueryServer = new ParseLiveQueryServer({});
331+
const parseWebSocket = {
332+
clientId: -1,
333+
};
334+
await parseLiveQueryServer._handleConnect(parseWebSocket, {
335+
sessionToken: 'token',
336+
});
337+
const query = {
338+
className: 'test',
339+
where: {
340+
key: 'value',
341+
},
342+
fields: ['test'],
343+
};
344+
const requestId = 2;
345+
const request = {
346+
query: query,
347+
requestId: requestId,
348+
sessionToken: 'sessionToken',
349+
};
350+
await parseLiveQueryServer._handleSubscribe(parseWebSocket, request);
351+
expect(parseLiveQueryServer.clients.size).toBe(1);
352+
const Client = require('../lib/LiveQuery/Client').Client;
353+
expect(Client.pushError).toHaveBeenCalled();
354+
});
355+
310356
it('can handle subscribe command without clientId', async () => {
311357
const parseLiveQueryServer = new ParseLiveQueryServer({});
312358
const incompleteParseConn = {};
@@ -729,7 +775,7 @@ describe('ParseLiveQueryServer', function () {
729775
expect(client.pushDelete).not.toHaveBeenCalled();
730776
});
731777

732-
it('can handle object delete command which matches some subscriptions', async (done) => {
778+
it('can handle object delete command which matches some subscriptions', async done => {
733779
const parseLiveQueryServer = new ParseLiveQueryServer({});
734780
// Make deletedParseObject
735781
const parseObject = new Parse.Object(testClassName);
@@ -773,7 +819,7 @@ describe('ParseLiveQueryServer', function () {
773819
parseLiveQueryServer._onAfterSave(message);
774820
});
775821

776-
it('can handle object save command which does not match any subscription', async (done) => {
822+
it('can handle object save command which does not match any subscription', async done => {
777823
const parseLiveQueryServer = new ParseLiveQueryServer({});
778824
// Make mock request message
779825
const message = generateMockMessage();
@@ -804,7 +850,7 @@ describe('ParseLiveQueryServer', function () {
804850
}, jasmine.ASYNC_TEST_WAIT_TIME);
805851
});
806852

807-
it('can handle object enter command which matches some subscriptions', async (done) => {
853+
it('can handle object enter command which matches some subscriptions', async done => {
808854
const parseLiveQueryServer = new ParseLiveQueryServer({});
809855
// Make mock request message
810856
const message = generateMockMessage(true);
@@ -841,7 +887,7 @@ describe('ParseLiveQueryServer', function () {
841887
}, jasmine.ASYNC_TEST_WAIT_TIME);
842888
});
843889

844-
it('can handle object update command which matches some subscriptions', async (done) => {
890+
it('can handle object update command which matches some subscriptions', async done => {
845891
const parseLiveQueryServer = new ParseLiveQueryServer({});
846892
// Make mock request message
847893
const message = generateMockMessage(true);
@@ -874,7 +920,7 @@ describe('ParseLiveQueryServer', function () {
874920
}, jasmine.ASYNC_TEST_WAIT_TIME);
875921
});
876922

877-
it('can handle object leave command which matches some subscriptions', async (done) => {
923+
it('can handle object leave command which matches some subscriptions', async done => {
878924
const parseLiveQueryServer = new ParseLiveQueryServer({});
879925
// Make mock request message
880926
const message = generateMockMessage(true);
@@ -911,7 +957,7 @@ describe('ParseLiveQueryServer', function () {
911957
}, jasmine.ASYNC_TEST_WAIT_TIME);
912958
});
913959

914-
it('can handle update command with original object', async (done) => {
960+
it('can handle update command with original object', async done => {
915961
jasmine.restoreLibrary('../lib/LiveQuery/Client', 'Client');
916962
const Client = require('../lib/LiveQuery/Client').Client;
917963
const parseLiveQueryServer = new ParseLiveQueryServer({});
@@ -961,7 +1007,7 @@ describe('ParseLiveQueryServer', function () {
9611007
}, jasmine.ASYNC_TEST_WAIT_TIME);
9621008
});
9631009

964-
it('can handle object create command which matches some subscriptions', async (done) => {
1010+
it('can handle object create command which matches some subscriptions', async done => {
9651011
const parseLiveQueryServer = new ParseLiveQueryServer({});
9661012
// Make mock request message
9671013
const message = generateMockMessage();
@@ -994,7 +1040,7 @@ describe('ParseLiveQueryServer', function () {
9941040
}, jasmine.ASYNC_TEST_WAIT_TIME);
9951041
});
9961042

997-
it('can handle create command with fields', async (done) => {
1043+
it('can handle create command with fields', async done => {
9981044
jasmine.restoreLibrary('../lib/LiveQuery/Client', 'Client');
9991045
const Client = require('../lib/LiveQuery/Client').Client;
10001046
const parseLiveQueryServer = new ParseLiveQueryServer({});
@@ -1500,7 +1546,7 @@ describe('ParseLiveQueryServer', function () {
15001546
});
15011547

15021548
describe('class level permissions', () => {
1503-
it('matches CLP when find is closed', (done) => {
1549+
it('matches CLP when find is closed', done => {
15041550
const parseLiveQueryServer = new ParseLiveQueryServer({});
15051551
const acl = new Parse.ACL();
15061552
acl.setReadAccess(testUserId, true);
@@ -1525,13 +1571,13 @@ describe('ParseLiveQueryServer', function () {
15251571
requestId,
15261572
'find'
15271573
)
1528-
.then((isMatched) => {
1574+
.then(isMatched => {
15291575
expect(isMatched).toBe(false);
15301576
done();
15311577
});
15321578
});
15331579

1534-
it('matches CLP when find is open', (done) => {
1580+
it('matches CLP when find is open', done => {
15351581
const parseLiveQueryServer = new ParseLiveQueryServer({});
15361582
const acl = new Parse.ACL();
15371583
acl.setReadAccess(testUserId, true);
@@ -1556,13 +1602,13 @@ describe('ParseLiveQueryServer', function () {
15561602
requestId,
15571603
'find'
15581604
)
1559-
.then((isMatched) => {
1605+
.then(isMatched => {
15601606
expect(isMatched).toBe(true);
15611607
done();
15621608
});
15631609
});
15641610

1565-
it('matches CLP when find is restricted to userIds', (done) => {
1611+
it('matches CLP when find is restricted to userIds', done => {
15661612
const parseLiveQueryServer = new ParseLiveQueryServer({});
15671613
const acl = new Parse.ACL();
15681614
acl.setReadAccess(testUserId, true);
@@ -1587,13 +1633,13 @@ describe('ParseLiveQueryServer', function () {
15871633
requestId,
15881634
'find'
15891635
)
1590-
.then((isMatched) => {
1636+
.then(isMatched => {
15911637
expect(isMatched).toBe(true);
15921638
done();
15931639
});
15941640
});
15951641

1596-
it('matches CLP when find is restricted to userIds', (done) => {
1642+
it('matches CLP when find is restricted to userIds', done => {
15971643
const parseLiveQueryServer = new ParseLiveQueryServer({});
15981644
const acl = new Parse.ACL();
15991645
acl.setReadAccess(testUserId, true);
@@ -1618,7 +1664,7 @@ describe('ParseLiveQueryServer', function () {
16181664
requestId,
16191665
'find'
16201666
)
1621-
.then((isMatched) => {
1667+
.then(isMatched => {
16221668
expect(isMatched).toBe(false);
16231669
done();
16241670
});
@@ -1955,7 +2001,7 @@ describe('LiveQueryController', () => {
19552001
classNames: ['Yolo'],
19562002
},
19572003
})
1958-
.then((parseServer) => {
2004+
.then(parseServer => {
19592005
saveSpy = spyOn(
19602006
parseServer.config.liveQueryController,
19612007
'onAfterSave'
@@ -1973,7 +2019,7 @@ describe('LiveQueryController', () => {
19732019
const obj = new Parse.Object('Yolo');
19742020
return obj.save();
19752021
})
1976-
.then((obj) => {
2022+
.then(obj => {
19772023
return obj.destroy();
19782024
})
19792025
.then(() => {
@@ -2053,49 +2099,3 @@ describe('LiveQueryController', () => {
20532099
});
20542100
});
20552101
});
2056-
2057-
it('basic beforeConnect rejection', async () => {
2058-
Parse.Cloud.beforeConnect(function () {
2059-
throw new Error('You shall not pass!');
2060-
});
2061-
const parseLiveQueryServer = new ParseLiveQueryServer({});
2062-
const parseWebSocket = {
2063-
clientId: -1,
2064-
};
2065-
await parseLiveQueryServer._handleConnect(parseWebSocket, {
2066-
sessionToken: 'token',
2067-
});
2068-
expect(parseLiveQueryServer.clients.size).toBe(0);
2069-
const Client = require('../lib/LiveQuery/Client').Client;
2070-
expect(Client.pushError).toHaveBeenCalled();
2071-
});
2072-
2073-
it('basic beforeSubscribe rejection', async () => {
2074-
Parse.Cloud.beforeSubscribe('test', function () {
2075-
throw new Error('You shall not pass!');
2076-
});
2077-
const parseLiveQueryServer = new ParseLiveQueryServer({});
2078-
const parseWebSocket = {
2079-
clientId: -1,
2080-
};
2081-
await parseLiveQueryServer._handleConnect(parseWebSocket, {
2082-
sessionToken: 'token',
2083-
});
2084-
const query = {
2085-
className: 'test',
2086-
where: {
2087-
key: 'value',
2088-
},
2089-
fields: ['test'],
2090-
};
2091-
const requestId = 2;
2092-
const request = {
2093-
query: query,
2094-
requestId: requestId,
2095-
sessionToken: 'sessionToken',
2096-
};
2097-
await parseLiveQueryServer._handleSubscribe(parseWebSocket, request);
2098-
expect(parseLiveQueryServer.clients.size).toBe(0);
2099-
const Client = require('../lib/LiveQuery/Client').Client;
2100-
expect(Client.pushError).toHaveBeenCalled();
2101-
});

0 commit comments

Comments
 (0)