Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions spec/ParseLiveQuery.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,48 @@ describe('ParseLiveQuery', function () {
requestedUser.setUsername('username');
requestedUser.setPassword('password');
Parse.Cloud.onLiveQueryEvent(req => {
const { event, sessionToken } = req;
const {
event,
clientId,
clients,
installationId,
sessionToken,
subscriptions,
useMasterKey,
} = req;
if (event === 'ws_disconnect') {
Parse.Cloud._removeAllHooks();
expect(sessionToken).toBeDefined();
expect(clientId).toBeDefined();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For completeness can we add tests for the other keys in req (e.g req.masterKey)

expect(clients).toBeDefined();
expect(installationId).toBeDefined();
expect(sessionToken).toBe(requestedUser.getSessionToken());
expect(useMasterKey).toBeDefined();
done();
}
if (event === 'ws_connect') {
expect(clients).toBeDefined();
expect(subscriptions).toBeDefined();
}
if (event === 'connect') {
expect(client).toBeDefined();
expect(clientId).toBeDefined();
expect(event).toBeDefined();
expect(clients).toBeDefined();
expect(subscriptions).toBeDefined();
expect(sessionToken).toBeDefined();
expect(useMasterKey).toBeDefined();
expect(installationId).toBeDefined();
}
if (event === 'subscribe') {
Copy link
Member

@mtrezza mtrezza May 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you split this up into individual tests for each event? Bulk tests have shown to be more difficult to maintain, also the test description would not be accurate anymore: "access user on onLiveQueryEvent disconnect".

expect(client).toBeDefined();
expect(clientId).toBeDefined();
expect(event).toBeDefined();
expect(clients).toBeDefined();
expect(subscriptions).toBeDefined();
expect(sessionToken).toBeDefined();
expect(useMasterKey).toBeDefined();
expect(installationId).toBeDefined();
}
});
await requestedUser.signUp();
const query = new Parse.Query(TestObject);
Expand Down
3 changes: 3 additions & 0 deletions src/LiveQuery/ParseLiveQueryServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ class ParseLiveQueryServer {
if (!this.clients.has(clientId)) {
runLiveQueryEventHandlers({
event: 'ws_disconnect_error',
clientId,
clients: this.clients.size,
subscriptions: this.subscriptions.size,
error: `Unable to find client ${clientId}`,
Expand Down Expand Up @@ -445,6 +446,7 @@ class ParseLiveQueryServer {
logger.verbose('Current subscriptions %d', this.subscriptions.size);
runLiveQueryEventHandlers({
event: 'ws_disconnect',
clientId,
clients: this.clients.size,
subscriptions: this.subscriptions.size,
useMasterKey: client.hasMasterKey,
Expand Down Expand Up @@ -805,6 +807,7 @@ class ParseLiveQueryServer {
logger.verbose('Current client number: %d', this.clients.size);
runLiveQueryEventHandlers({
client,
clientId: parseWebsocket.clientId,
event: 'subscribe',
clients: this.clients.size,
subscriptions: this.subscriptions.size,
Expand Down