-
-
Notifications
You must be signed in to change notification settings - Fork 594
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
Fixes LiveQuery behavior on multiple subscriptions #758
Merged
Merged
Changes from all 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 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 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,148 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const clear = require('./clear'); | ||
const Parse = require('../../node'); | ||
|
||
const TestObject = Parse.Object.extend('TestObject'); | ||
const DiffObject = Parse.Object.extend('DiffObject'); | ||
|
||
describe('Parse LiveQuery', () => { | ||
beforeEach((done) => { | ||
Parse.initialize('integration'); | ||
Parse.CoreManager.set('SERVER_URL', 'http://localhost:1337/parse'); | ||
Parse.Storage._clear(); | ||
clear().then(done).catch(done.fail); | ||
}); | ||
|
||
it('can subscribe to query', async () => { | ||
const object = new TestObject(); | ||
await object.save(); | ||
|
||
const query = new Parse.Query(TestObject); | ||
query.equalTo('objectId', object.id); | ||
const subscription = await query.subscribe(); | ||
|
||
subscription.on('update', object => { | ||
assert.equal(object.get('foo'), 'bar'); | ||
}) | ||
object.set({ foo: 'bar' }); | ||
await object.save(); | ||
}); | ||
|
||
it('can subscribe to multiple queries', async (done) => { | ||
const objectA = new TestObject(); | ||
const objectB = new TestObject(); | ||
await Parse.Object.saveAll([objectA, objectB]); | ||
|
||
const queryA = new Parse.Query(TestObject); | ||
const queryB = new Parse.Query(TestObject); | ||
queryA.equalTo('objectId', objectA.id); | ||
queryB.equalTo('objectId', objectB.id); | ||
const subscriptionA = await queryA.subscribe(); | ||
const subscriptionB = await queryB.subscribe(); | ||
let count = 0; | ||
subscriptionA.on('update', object => { | ||
count++; | ||
assert.equal(object.get('foo'), 'bar'); | ||
}) | ||
subscriptionB.on('update', object => { | ||
count++; | ||
assert.equal(object.get('foo'), 'baz'); | ||
}) | ||
await objectA.save({ foo: 'bar' }); | ||
await objectB.save({ foo: 'baz' }); | ||
|
||
setTimeout(() => { | ||
assert.equal(count, 2); | ||
done(); | ||
}, 100); | ||
}); | ||
|
||
it('can subscribe to multiple queries different class', async (done) => { | ||
const objectA = new TestObject(); | ||
const objectB = new DiffObject(); | ||
await Parse.Object.saveAll([objectA, objectB]); | ||
|
||
const queryA = new Parse.Query(TestObject); | ||
const queryB = new Parse.Query(DiffObject); | ||
queryA.equalTo('objectId', objectA.id); | ||
queryB.equalTo('objectId', objectB.id); | ||
const subscriptionA = await queryA.subscribe(); | ||
const subscriptionB = await queryB.subscribe(); | ||
let count = 0; | ||
subscriptionA.on('update', object => { | ||
count++; | ||
assert.equal(object.get('foo'), 'bar'); | ||
}) | ||
subscriptionB.on('update', object => { | ||
count++; | ||
assert.equal(object.get('foo'), 'baz'); | ||
}) | ||
await objectA.save({ foo: 'bar' }); | ||
await objectB.save({ foo: 'baz' }); | ||
|
||
setTimeout(() => { | ||
expect(count).toBe(2); | ||
done(); | ||
}, 1000); | ||
}); | ||
|
||
it('can unsubscribe to multiple queries different class', async (done) => { | ||
const objectA = new TestObject(); | ||
const objectB = new DiffObject(); | ||
await Parse.Object.saveAll([objectA, objectB]); | ||
|
||
const queryA = new Parse.Query(TestObject); | ||
const queryB = new Parse.Query(DiffObject); | ||
queryA.equalTo('objectId', objectA.id); | ||
queryB.equalTo('objectId', objectB.id); | ||
const subscriptionA = await queryA.subscribe(); | ||
const subscriptionB = await queryB.subscribe(); | ||
let count = 0; | ||
subscriptionA.on('update', () => { | ||
count++; | ||
}) | ||
subscriptionB.on('update', object => { | ||
count++; | ||
assert.equal(object.get('foo'), 'baz'); | ||
}) | ||
subscriptionA.unsubscribe(); | ||
await objectA.save({ foo: 'bar' }); | ||
await objectB.save({ foo: 'baz' }); | ||
|
||
setTimeout(() => { | ||
assert.equal(count, 1); | ||
done(); | ||
}, 1000); | ||
}); | ||
|
||
it('can unsubscribe with await to multiple queries different class', async (done) => { | ||
const objectA = new TestObject(); | ||
const objectB = new DiffObject(); | ||
await Parse.Object.saveAll([objectA, objectB]); | ||
|
||
const queryA = new Parse.Query(TestObject); | ||
const queryB = new Parse.Query(DiffObject); | ||
queryA.equalTo('objectId', objectA.id); | ||
queryB.equalTo('objectId', objectB.id); | ||
const subscriptionA = await queryA.subscribe(); | ||
const subscriptionB = await queryB.subscribe(); | ||
let count = 0; | ||
subscriptionA.on('update', () => { | ||
count++; | ||
}) | ||
subscriptionB.on('update', object => { | ||
count++; | ||
assert.equal(object.get('foo'), 'baz'); | ||
}) | ||
await subscriptionA.unsubscribe(); | ||
await objectA.save({ foo: 'bar' }); | ||
await objectB.save({ foo: 'baz' }); | ||
|
||
setTimeout(() => { | ||
assert.equal(count, 1); | ||
done(); | ||
}, 1000); | ||
}); | ||
}); |
This file contains 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 |
---|---|---|
@@ -1,8 +1,13 @@ | ||
const ParseServer = require('parse-server').ParseServer; | ||
|
||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000; | ||
beforeAll((done) => { | ||
const { app } = require('../server'); | ||
app.listen(1337, () => { | ||
const httpServer = require('http').createServer(app); | ||
|
||
httpServer.listen(1337, () => { | ||
console.log('parse-server running on port 1337.'); | ||
done(); | ||
}); | ||
ParseServer.createLiveQueryServer(httpServer); | ||
}); |
This file contains 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 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 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.
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.
can you help me understand what this change is please?
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.
Those function (subscribe, unsubscribe, open, close) already exists in the LiveQueryClient.
In the LiveQueryController those were just wrapper functions. Instead of using wrapper functions call the ones from the LiveQueryClient (Which you can get from the LiveQueryController).
setDefaultLiveQueryClient, getDefaultLiveQueryClient, _clearCachedDefaultClient already existed but weren't documented.