diff --git a/spec/QueryTools.spec.js b/spec/QueryTools.spec.js index 7e09078dad..dbd3c9a5d3 100644 --- a/spec/QueryTools.spec.js +++ b/spec/QueryTools.spec.js @@ -583,6 +583,29 @@ describe('matchesQuery', function () { expect(matchesQuery(message, q)).toBe(false); }); + it('should support containedIn with array of pointers', () => { + const message = { + id: new Id('Message', 'O2'), + profiles: [pointer('Profile', 'yeahaw'), pointer('Profile', 'yes')], + }; + + let q = new Parse.Query('Message'); + q.containedIn('profiles', [ + Parse.Object.fromJSON({ className: 'Profile', objectId: 'no' }), + Parse.Object.fromJSON({ className: 'Profile', objectId: 'yes' }), + ]); + + expect(matchesQuery(message, q)).toBe(true); + + q = new Parse.Query('Message'); + q.containedIn('profiles', [ + Parse.Object.fromJSON({ className: 'Profile', objectId: 'no' }), + Parse.Object.fromJSON({ className: 'Profile', objectId: 'nope' }), + ]); + + expect(matchesQuery(message, q)).toBe(false); + }); + it('should support notContainedIn with pointers', () => { let message = { id: new Id('Message', 'O1'), diff --git a/src/LiveQuery/QueryTools.js b/src/LiveQuery/QueryTools.js index 905919ef61..a50699f03e 100644 --- a/src/LiveQuery/QueryTools.js +++ b/src/LiveQuery/QueryTools.js @@ -103,8 +103,18 @@ function contains(haystack: Array, needle: any): boolean { return true; } } + return false; } + + if (Array.isArray(needle)) { + for (const need of needle) { + if (contains(haystack, need)) { + return true; + } + } + } + return haystack.indexOf(needle) > -1; } /**