Repository: parse-community/Parse-SDK-JS
Pull request #1247 (2020-11-09 23:52:21)

fix(fetchAll): Properly handle passed in values
Prevents `TypeError: Cannot read property 'id' of null`

Handles input the same way saveAll and destroyAll.

Also removed unnecessary LDS call on destroy all for non ParseObject / Array<ParseObject>

Let me know if I need to change anything.

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



Danger run resulted in 1 warning; to find out more, see the [checks page](https://github.com/parse-community/Parse-SDK-JS/runs/1377112237).
<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/1247?src=pr&el=h1) Report
> Merging [#1247](https://codecov.io/gh/parse-community/Parse-SDK-JS/pull/1247?src=pr&el=desc) (80af9ae) into [master](https://codecov.io/gh/parse-community/Parse-SDK-JS/commit/73543fbab76fd9109fdf99689c6e0cce6079f896?el=desc) (73543fb) will **not change** coverage.
> The diff coverage is `100.00%`.

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

```diff
@@           Coverage Diff           @@
##           master    #1247   +/-   ##
=======================================
  Coverage   99.98%   99.98%           
=======================================
  Files          57       57           
  Lines        5401     5401           
  Branches     1198     1198           
=======================================
  Hits         5400     5400           
  Misses          1        1           
```


| [Impacted Files](https://codecov.io/gh/parse-community/Parse-SDK-JS/pull/1247?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/ParseObject.js](https://codecov.io/gh/parse-community/Parse-SDK-JS/pull/1247/diff?src=pr&el=tree#diff-c3JjL1BhcnNlT2JqZWN0Lmpz) | `100.00% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/parse-community/Parse-SDK-JS/pull/1247?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/1247?src=pr&el=footer). Last update [73543fb...80af9ae](https://codecov.io/gh/parse-community/Parse-SDK-JS/pull/1247?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/src/ParseObject.js b/src/ParseObject.js
index 3709add..1e778d9 100644
--- a/src/ParseObject.js
+++ b/src/ParseObject.js
@@ -2178,7 +2178,7 @@ const DefaultController = {
         }
         return Promise.resolve(results);
       });
-    } else {
+    } else if (target instanceof ParseObject) {
       if (!target.id) {
         return Promise.reject(new ParseError(
           ParseError.MISSING_OBJECT_ID,
@@ -2196,15 +2196,14 @@ const DefaultController = {
         params,
         options
       ).then(async (response) => {
-        if (target instanceof ParseObject) {
-          target._clearPendingOps();
-          target._clearServerData();
-          target._finishFetch(response);
-        }
+        target._clearPendingOps();
+        target._clearServerData();
+        target._finishFetch(response);
         await localDatastore._updateObjectIfPinned(target);
         return target;
       });
     }
+    return Promise.resolve();
   },
 
   async destroy(target: ParseObject | Array<ParseObject>, options: RequestOptions): Promise<Array<void> | ParseObject> {
@@ -2278,7 +2277,6 @@ const DefaultController = {
         return Promise.resolve(target);
       });
     }
-    await localDatastore._destroyObjectIfPinned(target);
     return Promise.resolve(target);
   },
 


Test patch:
diff --git a/src/__tests__/ParseObject-test.js b/src/__tests__/ParseObject-test.js
index 25c3cb7..9c40906 100644
--- a/src/__tests__/ParseObject-test.js
+++ b/src/__tests__/ParseObject-test.js
@@ -1257,6 +1257,21 @@ describe('ParseObject', () => {
     expect(controller.ajax).toHaveBeenCalledTimes(0);
   });
 
+  it('fetchAll with null', async () => {
+    CoreManager.getRESTController()._setXHR(
+      mockXHR([{
+        status: 200,
+        response: [{}]
+      }])
+    );
+    const controller = CoreManager.getRESTController();
+    jest.spyOn(controller, 'ajax');
+
+    const results = await ParseObject.fetchAll(null);
+    expect(results).toEqual(undefined);
+    expect(controller.ajax).toHaveBeenCalledTimes(0);
+  });
+
   it('fetchAll unique instance', async () => {
     ParseObject.disableSingleInstance();
     const obj = new ParseObject('Item');