Skip to content

Commit c4a2ef9

Browse files
authored
Merge dd3ce1a into a5ffb95
2 parents a5ffb95 + dd3ce1a commit c4a2ef9

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

spec/QueryTools.spec.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,71 @@ describe('matchesQuery', function () {
255255
expect(matchesQuery(img, q)).toBe(false);
256256
});
257257

258+
it('matches on queries with new format #parse-SDK-JS/pull/1373', function () {
259+
const obj1 = {
260+
objectId: 'Person01',
261+
score: 12,
262+
name: 'Bill',
263+
};
264+
265+
const q = {
266+
score: {
267+
$eq: 12,
268+
},
269+
};
270+
expect(matchesQuery(obj1, q)).toBe(true);
271+
});
272+
273+
it('matches on queries with new format #parse-SDK-JS/pull/1373 for Pointer', function () {
274+
const obj1 = {
275+
objectId: 'Person01',
276+
name: 'Bill',
277+
age: 34,
278+
};
279+
280+
const obj2 = {
281+
objectId: 'Car01',
282+
name: 'Volkswagen',
283+
owner: pointer('Person', obj1.objectId),
284+
};
285+
286+
const q = {
287+
owner: {
288+
$eq: pointer('Person', obj1.objectId),
289+
},
290+
};
291+
expect(matchesQuery(obj2, q)).toBe(true);
292+
});
293+
294+
it('matches on queries with new format #parse-SDK-JS/pull/1373 for Object', function () {
295+
const obj1 = {
296+
objectId: 'Person01',
297+
addr: { planet: 'Earth' },
298+
};
299+
300+
const q = {
301+
addr: {
302+
$eq: { planet: 'Earth' },
303+
},
304+
};
305+
expect(matchesQuery(obj1, q)).toBe(true);
306+
});
307+
308+
it('matches on queries with new format #parse-SDK-JS/pull/1373 for Array', function () {
309+
const obj = {
310+
objectId: 'Person01',
311+
name: 'Bill',
312+
nums: [1, 2, 3, 4],
313+
};
314+
315+
const q = {
316+
nums: {
317+
$eq: 5,
318+
},
319+
};
320+
expect(matchesQuery(obj, q)).toBe(false);
321+
});
322+
258323
it('matches on inequalities', function () {
259324
const player = {
260325
id: new Id('Person', 'O1'),

src/LiveQuery/QueryTools.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,32 @@ function matchesKeyConstraints(object, key, constraints) {
217217
compareTo = Parse._decode(key, compareTo);
218218
}
219219
switch (condition) {
220+
case '$eq': {
221+
if (typeof compareTo !== 'object') {
222+
// Equality (or Array contains) cases
223+
if (Array.isArray(object[key])) {
224+
if (object[key].indexOf(constraints[condition]) === -1) {
225+
return false;
226+
}
227+
break;
228+
}
229+
if (object[key] !== compareTo) {
230+
return false;
231+
}
232+
break;
233+
} else {
234+
if (compareTo && constraints[condition].__type === 'Pointer') {
235+
return equalObjectsGeneric(object[key], constraints[condition], function (obj, ptr) {
236+
return (
237+
typeof obj !== 'undefined' &&
238+
ptr.className === obj.className &&
239+
ptr.objectId === obj.objectId
240+
);
241+
});
242+
}
243+
return equalObjectsGeneric(object[key], compareTo, equalObjects);
244+
}
245+
}
220246
case '$lt':
221247
if (object[key] >= compareTo) {
222248
return false;

0 commit comments

Comments
 (0)