-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
feature: run query via livequery #9864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dblythy
wants to merge
5
commits into
parse-community:alpha
Choose a base branch
from
dblythy:feature/live-query-query
base: alpha
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,245 @@ | ||
'use strict'; | ||
|
||
const Parse = require('parse/node'); | ||
|
||
describe('ParseLiveQuery query operation', function () { | ||
beforeEach(function (done) { | ||
// Mock ParseWebSocketServer | ||
const mockParseWebSocketServer = jasmine.createSpy('ParseWebSocketServer'); | ||
jasmine.mockLibrary( | ||
'../lib/LiveQuery/ParseWebSocketServer', | ||
'ParseWebSocketServer', | ||
mockParseWebSocketServer | ||
); | ||
// Mock Client pushError | ||
const Client = require('../lib/LiveQuery/Client').Client; | ||
Client.pushError = jasmine.createSpy('pushError'); | ||
done(); | ||
}); | ||
|
||
afterEach(function () { | ||
jasmine.restoreLibrary('../lib/LiveQuery/ParseWebSocketServer', 'ParseWebSocketServer'); | ||
}); | ||
|
||
function addMockClient(parseLiveQueryServer, clientId) { | ||
const Client = require('../lib/LiveQuery/Client').Client; | ||
const client = new Client(clientId, {}); | ||
client.pushResult = jasmine.createSpy('pushResult'); | ||
parseLiveQueryServer.clients.set(clientId, client); | ||
return client; | ||
} | ||
|
||
function addMockSubscription(parseLiveQueryServer, clientId, requestId, parseWebSocket, query = {}) { | ||
const Subscription = require('../lib/LiveQuery/Subscription').Subscription; | ||
const subscription = new Subscription( | ||
query.className || 'TestObject', | ||
query.where || {}, | ||
'hash' | ||
); | ||
|
||
// Add to server subscriptions | ||
if (!parseLiveQueryServer.subscriptions.has(subscription.className)) { | ||
parseLiveQueryServer.subscriptions.set(subscription.className, new Map()); | ||
} | ||
const classSubscriptions = parseLiveQueryServer.subscriptions.get(subscription.className); | ||
classSubscriptions.set('hash', subscription); | ||
|
||
// Add to client | ||
const client = parseLiveQueryServer.clients.get(clientId); | ||
const subscriptionInfo = { | ||
subscription: subscription, | ||
keys: query.keys, | ||
}; | ||
if (parseWebSocket.sessionToken) { | ||
subscriptionInfo.sessionToken = parseWebSocket.sessionToken; | ||
} | ||
client.subscriptionInfos.set(requestId, subscriptionInfo); | ||
|
||
return subscription; | ||
} | ||
|
||
it('can handle query command with existing subscription', async () => { | ||
await reconfigureServer(); | ||
|
||
const { ParseLiveQueryServer } = require('../lib/LiveQuery/ParseLiveQueryServer'); | ||
const parseLiveQueryServer = new ParseLiveQueryServer({ | ||
appId: 'test', | ||
masterKey: 'test', | ||
serverURL: 'http://localhost:1337/parse' | ||
}); | ||
|
||
// Create test objects | ||
const TestObject = Parse.Object.extend('TestObject'); | ||
const obj1 = new TestObject(); | ||
obj1.set('name', 'object1'); | ||
await obj1.save(); | ||
|
||
const obj2 = new TestObject(); | ||
obj2.set('name', 'object2'); | ||
await obj2.save(); | ||
|
||
// Add mock client | ||
const clientId = 1; | ||
const client = addMockClient(parseLiveQueryServer, clientId); | ||
client.hasMasterKey = true; | ||
|
||
// Add mock subscription | ||
const parseWebSocket = { clientId: 1 }; | ||
const requestId = 2; | ||
const query = { | ||
className: 'TestObject', | ||
where: {}, | ||
}; | ||
addMockSubscription(parseLiveQueryServer, clientId, requestId, parseWebSocket, query); | ||
|
||
// Handle query command | ||
const request = { | ||
op: 'query', | ||
requestId: requestId, | ||
}; | ||
|
||
await parseLiveQueryServer._handleQuery(parseWebSocket, request); | ||
|
||
// Verify pushResult was called | ||
expect(client.pushResult).toHaveBeenCalled(); | ||
const results = client.pushResult.calls.mostRecent().args[1]; | ||
expect(Array.isArray(results)).toBe(true); | ||
expect(results.length).toBe(2); | ||
expect(results.some(r => r.name === 'object1')).toBe(true); | ||
expect(results.some(r => r.name === 'object2')).toBe(true); | ||
}); | ||
|
||
it('can handle query command without clientId', async () => { | ||
const { ParseLiveQueryServer } = require('../lib/LiveQuery/ParseLiveQueryServer'); | ||
const parseLiveQueryServer = new ParseLiveQueryServer({}); | ||
const incompleteParseConn = {}; | ||
await parseLiveQueryServer._handleQuery(incompleteParseConn, {}); | ||
|
||
const Client = require('../lib/LiveQuery/Client').Client; | ||
expect(Client.pushError).toHaveBeenCalled(); | ||
}); | ||
|
||
it('can handle query command without subscription', async () => { | ||
const { ParseLiveQueryServer } = require('../lib/LiveQuery/ParseLiveQueryServer'); | ||
const parseLiveQueryServer = new ParseLiveQueryServer({}); | ||
const clientId = 1; | ||
addMockClient(parseLiveQueryServer, clientId); | ||
|
||
const parseWebSocket = { clientId: 1 }; | ||
const request = { | ||
op: 'query', | ||
requestId: 999, // Non-existent subscription | ||
}; | ||
|
||
await parseLiveQueryServer._handleQuery(parseWebSocket, request); | ||
|
||
const Client = require('../lib/LiveQuery/Client').Client; | ||
expect(Client.pushError).toHaveBeenCalled(); | ||
}); | ||
|
||
it('respects field filtering (keys) when executing query', async () => { | ||
await reconfigureServer(); | ||
|
||
const { ParseLiveQueryServer } = require('../lib/LiveQuery/ParseLiveQueryServer'); | ||
const parseLiveQueryServer = new ParseLiveQueryServer({ | ||
appId: 'test', | ||
masterKey: 'test', | ||
serverURL: 'http://localhost:1337/parse' | ||
}); | ||
|
||
// Create test object with multiple fields | ||
const TestObject = Parse.Object.extend('TestObject'); | ||
const obj = new TestObject(); | ||
obj.set('name', 'test'); | ||
obj.set('color', 'blue'); | ||
obj.set('size', 'large'); | ||
await obj.save(); | ||
|
||
// Add mock client | ||
const clientId = 1; | ||
const client = addMockClient(parseLiveQueryServer, clientId); | ||
client.hasMasterKey = true; | ||
|
||
// Add mock subscription with keys | ||
const parseWebSocket = { clientId: 1 }; | ||
const requestId = 2; | ||
const query = { | ||
className: 'TestObject', | ||
where: {}, | ||
keys: ['name', 'color'], // Only these fields | ||
}; | ||
addMockSubscription(parseLiveQueryServer, clientId, requestId, parseWebSocket, query); | ||
|
||
// Handle query command | ||
const request = { | ||
op: 'query', | ||
requestId: requestId, | ||
}; | ||
|
||
await parseLiveQueryServer._handleQuery(parseWebSocket, request); | ||
|
||
// Verify results | ||
expect(client.pushResult).toHaveBeenCalled(); | ||
const results = client.pushResult.calls.mostRecent().args[1]; | ||
expect(results.length).toBe(1); | ||
|
||
// Results should include selected fields | ||
expect(results[0].name).toBe('test'); | ||
expect(results[0].color).toBe('blue'); | ||
|
||
// Results should NOT include size | ||
expect(results[0].size).toBeUndefined(); | ||
}); | ||
|
||
it('handles query with where constraints', async () => { | ||
await reconfigureServer(); | ||
|
||
const { ParseLiveQueryServer } = require('../lib/LiveQuery/ParseLiveQueryServer'); | ||
const parseLiveQueryServer = new ParseLiveQueryServer({ | ||
appId: 'test', | ||
masterKey: 'test', | ||
serverURL: 'http://localhost:1337/parse' | ||
}); | ||
|
||
// Create test objects | ||
const TestObject = Parse.Object.extend('TestObject'); | ||
const obj1 = new TestObject(); | ||
obj1.set('name', 'match'); | ||
obj1.set('status', 'active'); | ||
await obj1.save(); | ||
|
||
const obj2 = new TestObject(); | ||
obj2.set('name', 'nomatch'); | ||
obj2.set('status', 'inactive'); | ||
await obj2.save(); | ||
|
||
// Add mock client | ||
const clientId = 1; | ||
const client = addMockClient(parseLiveQueryServer, clientId); | ||
client.hasMasterKey = true; | ||
|
||
// Add mock subscription with where clause | ||
const parseWebSocket = { clientId: 1 }; | ||
const requestId = 2; | ||
const query = { | ||
className: 'TestObject', | ||
where: { status: 'active' }, // Only active objects | ||
}; | ||
addMockSubscription(parseLiveQueryServer, clientId, requestId, parseWebSocket, query); | ||
|
||
// Handle query command | ||
const request = { | ||
op: 'query', | ||
requestId: requestId, | ||
}; | ||
|
||
await parseLiveQueryServer._handleQuery(parseWebSocket, request); | ||
|
||
// Verify results | ||
expect(client.pushResult).toHaveBeenCalled(); | ||
const results = client.pushResult.calls.mostRecent().args[1]; | ||
expect(results.length).toBe(1); | ||
expect(results[0].name).toBe('match'); | ||
expect(results[0].status).toBe('active'); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Verify serverURL configuration matches test setup.
The
ParseLiveQueryServer
is configured withserverURL: 'http://localhost:1337/parse'
, but the test usesreconfigureServer
which typically runs on a different port. If the query operation makes REST calls to Parse Server, this mismatch could cause connection failures.Check if the serverURL should use the same port as the reconfigured server:
🏁 Script executed:
Length of output: 279
🏁 Script executed:
Length of output: 112115
🏁 Script executed:
Length of output: 283
🏁 Script executed:
Length of output: 650
🏁 Script executed:
Length of output: 1789
🏁 Script executed:
Length of output: 3677
🏁 Script executed:
Length of output: 7315
Replace hard-coded serverURL in query tests
In spec/ParseLiveQueryQuery.spec.js (around line 76), you’re instantiating ParseLiveQueryServer with
serverURL: 'http://localhost:1337/parse'
, but the test helper reconfigures Parse Server on port 8378 with mount/1
. This mismatch causes_handleQuery
to point at the wrong endpoint. Use the helper’sserverURL
(orParse.serverURL
) instead so LiveQueryServer and the test Parse Server align.🤖 Prompt for AI Agents