Repository: parse-community/Parse-SDK-JS
Pull request #971 (2019-10-27 00:09:21)

Can unlink without provider (cloud code)
This is specifically for facebook since you can't register a auth provider in cloud code (FB doesn't exist).

Removes duplicate logic (linkWith handles the providers)

```
Cannot read property 'getAuthType' of undefined
```

Note: I can't add an integration test for this. I have tested and this works.
`integration/tests` uses /lib/node
`integration/server.js` uses /node_modules/parse (this doesn't have changes made in /lib/node)


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

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

```diff
@@            Coverage Diff             @@
##           master     #971      +/-   ##
==========================================
- Coverage   91.88%   91.84%   -0.05%     
==========================================
  Files          54       54              
  Lines        5080     5078       -2     
  Branches     1143     1142       -1     
==========================================
- Hits         4668     4664       -4     
- Misses        412      414       +2
```


| [Impacted Files](https://codecov.io/gh/parse-community/Parse-SDK-JS/pull/971?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/ParseUser.js](https://codecov.io/gh/parse-community/Parse-SDK-JS/pull/971/diff?src=pr&el=tree#diff-c3JjL1BhcnNlVXNlci5qcw==) | `82.08% <100%> (-0.54%)` | :arrow_down: |

------

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


Patch:
diff --git a/src/ParseUser.js b/src/ParseUser.js
index ea49c6c..3a4e318 100644
--- a/src/ParseUser.js
+++ b/src/ParseUser.js
@@ -213,11 +213,13 @@ class ParseUser extends ParseObject {
 
   /**
    * Unlinks a user from a service.
+   *
+   * @param {String|AuthProvider} provider Name of auth provider or {@link https://parseplatform.org/Parse-SDK-JS/api/master/AuthProvider.html AuthProvider}
+   * @param {Object} options MasterKey / SessionToken
+   * @return {Promise} A promise that is fulfilled when the unlinking
+   *     finishes.
    */
-  _unlinkFrom(provider: any, options?: FullOptions) {
-    if (typeof provider === 'string') {
-      provider = authProviders[provider];
-    }
+  _unlinkFrom(provider: any, options?: FullOptions): Promise<ParseUser> {
     return this.linkWith(provider, { authData: null }, options).then(() => {
       this._synchronizeAuthData(provider);
       return Promise.resolve(this);


Test patch:
diff --git a/src/__tests__/ParseUser-test.js b/src/__tests__/ParseUser-test.js
index 5dc6939..21f4057 100644
--- a/src/__tests__/ParseUser-test.js
+++ b/src/__tests__/ParseUser-test.js
@@ -849,7 +849,7 @@ describe('ParseUser', () => {
     const user = new ParseUser();
     jest.spyOn(user, 'linkWith')
       .mockImplementationOnce((authProvider, authData, saveOptions) => {
-        expect(authProvider).toEqual(provider);
+        expect(authProvider).toEqual(provider.getAuthType());
         expect(authData).toEqual({ authData: null});
         expect(saveOptions).toEqual({ useMasterKey: true });
         return Promise.resolve();
@@ -1007,6 +1007,6 @@ describe('ParseUser', () => {
 
     await user._unlinkFrom('testProvider');
     const authProvider = user.linkWith.mock.calls[0][0];
-    expect(authProvider.getAuthType()).toBe('testProvider');
+    expect(authProvider).toBe('testProvider');
   });
 });