Repository: parse-community/Parse-SDK-JS
Pull request #1235 (2020-10-22 15:31:44)

equalTo + notEqualTo: Add possibility to pass objects
- Add possibility to pass objects to equalTo and notEqualTo

_@dplewis Please add hacktoberfest label_

peril-parse-community[bot]: 
<!--
  0 failure: 
  0 warning: 
  
  1 markdown notices
  DangerID: danger-id-Peril;
-->



Danger run resulted in 1 fail and 1 markdown; to find out more, see the [checks page](https://github.com/parse-community/Parse-SDK-JS/runs/1293423008).
<p align="right">
  Generated by :no_entry_sign: <a href="https://danger.systems/js">dangerJS</a>
</p>

codecov[bot]: # [Codecov](https://codecov.io/gh/parse-community/Parse-SDK-JS/pull/1235?src=pr&el=h1) Report
> Merging [#1235](https://codecov.io/gh/parse-community/Parse-SDK-JS/pull/1235?src=pr&el=desc) into [master](https://codecov.io/gh/parse-community/Parse-SDK-JS/commit/c922a7c6731341a4de6d0543c0f99e8c32673aba?el=desc) will **increase** coverage by `0.01%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/parse-community/Parse-SDK-JS/pull/1235/graphs/tree.svg?width=650&height=150&src=pr&token=8nCENM0QHj)](https://codecov.io/gh/parse-community/Parse-SDK-JS/pull/1235?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #1235      +/-   ##
==========================================
+ Coverage   92.39%   92.40%   +0.01%     
==========================================
  Files          54       54              
  Lines        5325     5334       +9     
  Branches     1201     1203       +2     
==========================================
+ Hits         4920     4929       +9     
  Misses        405      405              
```


| [Impacted Files](https://codecov.io/gh/parse-community/Parse-SDK-JS/pull/1235?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/ParseQuery.js](https://codecov.io/gh/parse-community/Parse-SDK-JS/pull/1235/diff?src=pr&el=tree#diff-c3JjL1BhcnNlUXVlcnkuanM=) | `96.08% <100.00%> (+0.05%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/parse-community/Parse-SDK-JS/pull/1235?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/parse-community/Parse-SDK-JS/pull/1235?src=pr&el=footer). Last update [c922a7c...54406ea](https://codecov.io/gh/parse-community/Parse-SDK-JS/pull/1235?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/src/ParseQuery.js b/src/ParseQuery.js
index e063e8d..72c2806 100644
--- a/src/ParseQuery.js
+++ b/src/ParseQuery.js
@@ -1169,7 +1169,11 @@ class ParseQuery {
    * @param value The value that the Parse.Object must contain.
    * @return {Parse.Query} Returns the query, so you can chain this call.
    */
-  equalTo(key: string, value: mixed): ParseQuery {
+  equalTo(key: string | { [key: string]: any }, value: ?mixed): ParseQuery {
+    if (key && typeof key === 'object') {
+      Object.entries(key).forEach(([k, val]) => this.equalTo(k, val))
+      return this
+    }
     if (typeof value === 'undefined') {
       return this.doesNotExist(key);
     }
@@ -1185,7 +1189,11 @@ class ParseQuery {
    * @param value The value that must not be equalled.
    * @return {Parse.Query} Returns the query, so you can chain this call.
    */
-  notEqualTo(key: string, value: mixed): ParseQuery {
+  notEqualTo(key: string | { [key: string]: any }, value: ?mixed): ParseQuery {
+    if (key && typeof key === 'object') {
+      Object.entries(key).forEach(([k, val]) => this.notEqualTo(k, val))
+      return this
+    }
     return this._addCondition(key, '$ne', value);
   }
 


Test patch:
diff --git a/integration/test/ParseQueryTest.js b/integration/test/ParseQueryTest.js
index 0dd2038..8468014 100644
--- a/integration/test/ParseQueryTest.js
+++ b/integration/test/ParseQueryTest.js
@@ -362,6 +362,15 @@ describe('Parse Query', () => {
     });
   });
 
+  it('can do equalTo queries with object', (done) => {
+    const query = new Parse.Query('BoxedNumber');
+    query.equalTo({ number: 3 });
+    query.find().then((results) => {
+      assert.equal(results.length, 1);
+      done();
+    });
+  });
+
   it('can test equality with undefined', (done) => {
     const query = new Parse.Query('BoxedNumber');
     query.equalTo('number', undefined);
@@ -436,6 +445,15 @@ describe('Parse Query', () => {
     });
   });
 
+  it('can perform notEqualTo queries with object', (done) => {
+    const query = new Parse.Query('BoxedNumber');
+    query.notEqualTo({ number: 5 });
+    query.find().then((results) => {
+      assert.equal(results.length, 9);
+      done();
+    });
+  });
+
   it('can perform containedIn queries', (done) => {
     const query = new Parse.Query('BoxedNumber');
     query.containedIn('number', [3,5,7,9,11]);
diff --git a/src/__tests__/ParseQuery-test.js b/src/__tests__/ParseQuery-test.js
index a31a7bc..eb8ed61 100644
--- a/src/__tests__/ParseQuery-test.js
+++ b/src/__tests__/ParseQuery-test.js
@@ -109,6 +109,16 @@ describe('ParseQuery', () => {
         }
       }
     });
+
+    const size = 'medium';
+    const stock = true;
+    q.equalTo({ size, stock });
+    expect(q.toJSON()).toEqual({
+      where: {
+        size: 'medium',
+        stock: true,
+      }
+    });
   });
 
   it('can generate inequality queries', () => {
@@ -130,6 +140,20 @@ describe('ParseQuery', () => {
         }
       }
     });
+
+    const size = 'medium';
+    const stock = true;
+    q.notEqualTo({ size, stock });
+    expect(q.toJSON()).toEqual({
+      where: {
+        size: {
+          $ne: 'medium',
+        },
+        stock: {
+          $ne: true,
+        }
+      }
+    });
   });
 
   it('can generate less-than queries', () => {