feat: Add ParseQuery.watch to trigger LiveQuery only on update of specific fields (#8028)
This commit is contained in:
@@ -394,6 +394,49 @@ describe('ParseLiveQuery', function () {
|
||||
await object.save();
|
||||
});
|
||||
|
||||
xit('can handle live query with fields - enable upon JS SDK support', async () => {
|
||||
await reconfigureServer({
|
||||
liveQuery: {
|
||||
classNames: ['Test'],
|
||||
},
|
||||
startLiveQueryServer: true,
|
||||
});
|
||||
const query = new Parse.Query('Test');
|
||||
query.watch('yolo');
|
||||
const subscription = await query.subscribe();
|
||||
const spy = {
|
||||
create(obj) {
|
||||
if (!obj.get('yolo')) {
|
||||
fail('create should not have been called');
|
||||
}
|
||||
},
|
||||
update(object, original) {
|
||||
if (object.get('yolo') === original.get('yolo')) {
|
||||
fail('create should not have been called');
|
||||
}
|
||||
},
|
||||
};
|
||||
const createSpy = spyOn(spy, 'create').and.callThrough();
|
||||
const updateSpy = spyOn(spy, 'update').and.callThrough();
|
||||
subscription.on('create', spy.create);
|
||||
subscription.on('update', spy.update);
|
||||
const obj = new Parse.Object('Test');
|
||||
obj.set('foo', 'bar');
|
||||
await obj.save();
|
||||
obj.set('foo', 'xyz');
|
||||
obj.set('yolo', 'xyz');
|
||||
await obj.save();
|
||||
const obj2 = new Parse.Object('Test');
|
||||
obj2.set('foo', 'bar');
|
||||
obj2.set('yolo', 'bar');
|
||||
await obj2.save();
|
||||
obj2.set('foo', 'bart');
|
||||
await obj2.save();
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
expect(createSpy).toHaveBeenCalledTimes(1);
|
||||
expect(updateSpy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('can handle afterEvent set pointers', async done => {
|
||||
await reconfigureServer({
|
||||
liveQuery: {
|
||||
|
||||
Reference in New Issue
Block a user