From cced89c4bd9093db6a3909515c06d012e3f8cf40 Mon Sep 17 00:00:00 2001 From: Rahul Lanjewar Date: Sat, 16 Dec 2023 12:30:51 +0530 Subject: [PATCH 01/10] feat: removed package lock --- spec/ParseLiveQuery.spec.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/spec/ParseLiveQuery.spec.js b/spec/ParseLiveQuery.spec.js index 015725ac46..0154ff1a03 100644 --- a/spec/ParseLiveQuery.spec.js +++ b/spec/ParseLiveQuery.spec.js @@ -1269,4 +1269,25 @@ describe('ParseLiveQuery', function () { expect(object2.id).toBeDefined(); expect(object3.id).toBeDefined(); }); + + it('matchesKeyConstraints fails when subscribing a query with constraint notEqualTo null', async done => { + await reconfigureServer({ + liveQuery: { + classNames: ['TestObject'], + }, + startLiveQueryServer: true, + verbose: false, + silent: true, + }); + + const query = new Parse.Query(TestObject); + query.notEqualTo('foo', null); + await query.subscribe(); + + // Create a object and save it, this passes but server crashes afterwards + const object1 = new TestObject(); + object1.set('foo', 'bar'); + await object1.save(); + done(); + }); }); From e3b3a55a1191cb916ee92f122837ceda7195a01c Mon Sep 17 00:00:00 2001 From: Rahul Lanjewar <63550998+RahulLanjewar93@users.noreply.github.com> Date: Sat, 16 Dec 2023 19:00:36 +0000 Subject: [PATCH 02/10] test: added expect condition --- spec/ParseLiveQuery.spec.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/spec/ParseLiveQuery.spec.js b/spec/ParseLiveQuery.spec.js index 0154ff1a03..f719c860ea 100644 --- a/spec/ParseLiveQuery.spec.js +++ b/spec/ParseLiveQuery.spec.js @@ -1270,7 +1270,7 @@ describe('ParseLiveQuery', function () { expect(object3.id).toBeDefined(); }); - it('matchesKeyConstraints fails when subscribing a query with constraint notEqualTo null', async done => { + it('matchesKeyConstraints fails when subscribing a query with constraint notEqualTo null', async () => { await reconfigureServer({ liveQuery: { classNames: ['TestObject'], @@ -1280,14 +1280,26 @@ describe('ParseLiveQuery', function () { silent: true, }); + // Creating a spy so we can register it as event listener. + const spy = { + create(obj) { + expect(obj.attributes.foo).toEqual('bar'); + }, + }; + const createSpy = spyOn(spy, 'create'); + + // Subscribe to TestObject class. where foo is not equal to null const query = new Parse.Query(TestObject); query.notEqualTo('foo', null); - await query.subscribe(); + const subscription = await query.subscribe(); + subscription.on('create', spy.create); - // Create a object and save it, this passes but server crashes afterwards + // Create a object and save it, the save call passes but server crashes afterwards const object1 = new TestObject(); object1.set('foo', 'bar'); await object1.save(); - done(); + + // Failing test.Since server crashed, it should not have been called. + expect(createSpy).toHaveBeenCalledTimes(1); }); }); From d3b9fc369b9b2e0ac3279d9decbf9c1f6103b1c5 Mon Sep 17 00:00:00 2001 From: Manuel <5673677+mtrezza@users.noreply.github.com> Date: Sat, 16 Dec 2023 21:05:45 +0100 Subject: [PATCH 03/10] Update spec/ParseLiveQuery.spec.js Signed-off-by: Manuel <5673677+mtrezza@users.noreply.github.com> --- spec/ParseLiveQuery.spec.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/ParseLiveQuery.spec.js b/spec/ParseLiveQuery.spec.js index f719c860ea..bee29c0428 100644 --- a/spec/ParseLiveQuery.spec.js +++ b/spec/ParseLiveQuery.spec.js @@ -1298,8 +1298,6 @@ describe('ParseLiveQuery', function () { const object1 = new TestObject(); object1.set('foo', 'bar'); await object1.save(); - - // Failing test.Since server crashed, it should not have been called. expect(createSpy).toHaveBeenCalledTimes(1); }); }); From a6ea95b6fbb4a3043ba92960a730759ee753857a Mon Sep 17 00:00:00 2001 From: Manuel <5673677+mtrezza@users.noreply.github.com> Date: Sat, 16 Dec 2023 21:05:52 +0100 Subject: [PATCH 04/10] Update spec/ParseLiveQuery.spec.js Signed-off-by: Manuel <5673677+mtrezza@users.noreply.github.com> --- spec/ParseLiveQuery.spec.js | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/ParseLiveQuery.spec.js b/spec/ParseLiveQuery.spec.js index bee29c0428..0a449ca3a6 100644 --- a/spec/ParseLiveQuery.spec.js +++ b/spec/ParseLiveQuery.spec.js @@ -1294,7 +1294,6 @@ describe('ParseLiveQuery', function () { const subscription = await query.subscribe(); subscription.on('create', spy.create); - // Create a object and save it, the save call passes but server crashes afterwards const object1 = new TestObject(); object1.set('foo', 'bar'); await object1.save(); From d899544700254fa97c10e1574ad3a1cf32383b42 Mon Sep 17 00:00:00 2001 From: Manuel <5673677+mtrezza@users.noreply.github.com> Date: Sat, 16 Dec 2023 21:05:59 +0100 Subject: [PATCH 05/10] Update spec/ParseLiveQuery.spec.js Signed-off-by: Manuel <5673677+mtrezza@users.noreply.github.com> --- spec/ParseLiveQuery.spec.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/spec/ParseLiveQuery.spec.js b/spec/ParseLiveQuery.spec.js index 0a449ca3a6..bd1a604c3b 100644 --- a/spec/ParseLiveQuery.spec.js +++ b/spec/ParseLiveQuery.spec.js @@ -1280,15 +1280,13 @@ describe('ParseLiveQuery', function () { silent: true, }); - // Creating a spy so we can register it as event listener. const spy = { create(obj) { expect(obj.attributes.foo).toEqual('bar'); }, }; const createSpy = spyOn(spy, 'create'); - - // Subscribe to TestObject class. where foo is not equal to null + const query = new Parse.Query(TestObject); query.notEqualTo('foo', null); const subscription = await query.subscribe(); From 502acc42d30a69f046b299212f01816b67dadb56 Mon Sep 17 00:00:00 2001 From: Manuel <5673677+mtrezza@users.noreply.github.com> Date: Sat, 16 Dec 2023 21:07:24 +0100 Subject: [PATCH 06/10] Update spec/ParseLiveQuery.spec.js Signed-off-by: Manuel <5673677+mtrezza@users.noreply.github.com> --- spec/ParseLiveQuery.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/ParseLiveQuery.spec.js b/spec/ParseLiveQuery.spec.js index bd1a604c3b..1ac6cf5356 100644 --- a/spec/ParseLiveQuery.spec.js +++ b/spec/ParseLiveQuery.spec.js @@ -1270,7 +1270,7 @@ describe('ParseLiveQuery', function () { expect(object3.id).toBeDefined(); }); - it('matchesKeyConstraints fails when subscribing a query with constraint notEqualTo null', async () => { + it('subscribes to query event with constraint not equal to null', async () => { await reconfigureServer({ liveQuery: { classNames: ['TestObject'], From 9260e401e23b3f0352c6533d87b58e424668eb85 Mon Sep 17 00:00:00 2001 From: Manuel <5673677+mtrezza@users.noreply.github.com> Date: Sat, 16 Dec 2023 21:07:49 +0100 Subject: [PATCH 07/10] Update spec/ParseLiveQuery.spec.js Signed-off-by: Manuel <5673677+mtrezza@users.noreply.github.com> --- spec/ParseLiveQuery.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/ParseLiveQuery.spec.js b/spec/ParseLiveQuery.spec.js index 1ac6cf5356..385bc8b030 100644 --- a/spec/ParseLiveQuery.spec.js +++ b/spec/ParseLiveQuery.spec.js @@ -1270,7 +1270,7 @@ describe('ParseLiveQuery', function () { expect(object3.id).toBeDefined(); }); - it('subscribes to query event with constraint not equal to null', async () => { + it('triggers to query event with constraint not equal to null', async () => { await reconfigureServer({ liveQuery: { classNames: ['TestObject'], From 87f12c9b0b575055a1bff715be7bbfc577677fa9 Mon Sep 17 00:00:00 2001 From: Manuel <5673677+mtrezza@users.noreply.github.com> Date: Sat, 16 Dec 2023 21:08:03 +0100 Subject: [PATCH 08/10] Update spec/ParseLiveQuery.spec.js Signed-off-by: Manuel <5673677+mtrezza@users.noreply.github.com> --- spec/ParseLiveQuery.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/ParseLiveQuery.spec.js b/spec/ParseLiveQuery.spec.js index 385bc8b030..94f8f7c8e3 100644 --- a/spec/ParseLiveQuery.spec.js +++ b/spec/ParseLiveQuery.spec.js @@ -1270,7 +1270,7 @@ describe('ParseLiveQuery', function () { expect(object3.id).toBeDefined(); }); - it('triggers to query event with constraint not equal to null', async () => { + it('triggers query event with constraint not equal to null', async () => { await reconfigureServer({ liveQuery: { classNames: ['TestObject'], From 263b8c8735d7ba29df25419e2c4313b14c8371a9 Mon Sep 17 00:00:00 2001 From: Manuel <5673677+mtrezza@users.noreply.github.com> Date: Sat, 16 Dec 2023 21:09:46 +0100 Subject: [PATCH 09/10] Update spec/ParseLiveQuery.spec.js Signed-off-by: Manuel <5673677+mtrezza@users.noreply.github.com> --- spec/ParseLiveQuery.spec.js | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/ParseLiveQuery.spec.js b/spec/ParseLiveQuery.spec.js index 94f8f7c8e3..d496cfc0d7 100644 --- a/spec/ParseLiveQuery.spec.js +++ b/spec/ParseLiveQuery.spec.js @@ -1286,7 +1286,6 @@ describe('ParseLiveQuery', function () { }, }; const createSpy = spyOn(spy, 'create'); - const query = new Parse.Query(TestObject); query.notEqualTo('foo', null); const subscription = await query.subscribe(); From 20d089de5c0bcf731ec0d9b84b4deec47fcfa250 Mon Sep 17 00:00:00 2001 From: Rahul Lanjewar Date: Fri, 31 May 2024 21:20:59 +0530 Subject: [PATCH 10/10] fix: added optional chaining so server doesn't crash --- spec/ParseLiveQuery.spec.js | 2 ++ src/LiveQuery/QueryTools.js | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/ParseLiveQuery.spec.js b/spec/ParseLiveQuery.spec.js index d496cfc0d7..789898f62a 100644 --- a/spec/ParseLiveQuery.spec.js +++ b/spec/ParseLiveQuery.spec.js @@ -1294,6 +1294,8 @@ describe('ParseLiveQuery', function () { const object1 = new TestObject(); object1.set('foo', 'bar'); await object1.save(); + + await new Promise(resolve => setTimeout(resolve, 100)); expect(createSpy).toHaveBeenCalledTimes(1); }); }); diff --git a/src/LiveQuery/QueryTools.js b/src/LiveQuery/QueryTools.js index 1607278f46..a839918088 100644 --- a/src/LiveQuery/QueryTools.js +++ b/src/LiveQuery/QueryTools.js @@ -223,7 +223,7 @@ function matchesKeyConstraints(object, key, constraints) { // More complex cases for (var condition in constraints) { compareTo = constraints[condition]; - if (compareTo.__type) { + if (compareTo?.__type) { compareTo = Parse._decode(key, compareTo); } switch (condition) {