From 5b1f497b62d36e97a26e1be7921ce5ede4d063c5 Mon Sep 17 00:00:00 2001 From: mansisampat Date: Fri, 27 Jun 2025 14:56:04 +0530 Subject: [PATCH 1/2] Increase unit test coverage for facebook.ts to 100% --- .../auth/src/core/providers/facebook.test.ts | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/packages/auth/src/core/providers/facebook.test.ts b/packages/auth/src/core/providers/facebook.test.ts index 7f71d04cc94..b271f08c013 100644 --- a/packages/auth/src/core/providers/facebook.test.ts +++ b/packages/auth/src/core/providers/facebook.test.ts @@ -35,6 +35,11 @@ describe('core/providers/facebook', () => { expect(cred.signInMethod).to.eq(SignInMethod.FACEBOOK); }); + it('generates Facebook provider', () => { + const provider = new FacebookAuthProvider(); + expect(provider.providerId).to.eq(ProviderId.FACEBOOK); + }); + it('credentialFromResult creates the cred from a tagged result', async () => { const auth = await testAuth(); const userCred = new UserCredentialImpl({ @@ -66,4 +71,53 @@ describe('core/providers/facebook', () => { expect(cred.providerId).to.eq(ProviderId.FACEBOOK); expect(cred.signInMethod).to.eq(SignInMethod.FACEBOOK); }); + + it('returns null when _tokenResponse is missing', () => { + const error = _createError(AuthErrorCode.NEED_CONFIRMATION, { + appName: 'foo' + }); + error.customData = {}; // no _tokenResponse + + const cred = FacebookAuthProvider.credentialFromError(error); + expect(cred).to.be.null; + }); + + it('returns null when _tokenResponse is missing oauthAccessToken key', () => { + const error = _createError(AuthErrorCode.NEED_CONFIRMATION, { + appName: 'foo' + }); + error.customData = { + _tokenResponse: { + // intentionally missing oauthAccessToken + idToken: 'some-id-token', + oauthAccessToken: null + } + }; + + const cred = FacebookAuthProvider.credentialFromError(error); + expect(cred).to.be.null; + }); + + it('returns null when FacebookAuthProvider.credential throws', () => { + // Temporarily stub credential method to throw + const original = FacebookAuthProvider.credential; + FacebookAuthProvider.credential = () => { + throw new Error('Simulated failure'); + }; + + const error = _createError(AuthErrorCode.NEED_CONFIRMATION, { + appName: 'foo' + }); + error.customData = { + _tokenResponse: { + oauthAccessToken: 'valid-token' + } + }; + + const cred = FacebookAuthProvider.credentialFromError(error); + expect(cred).to.be.null; + + // Restore original method + FacebookAuthProvider.credential = original; + }); }); From 3860172898d1edd9055891aedb9d6d84833901cc Mon Sep 17 00:00:00 2001 From: mansisampat Date: Fri, 27 Jun 2025 15:02:38 +0530 Subject: [PATCH 2/2] Increase unit test coverage for facebook.ts to 100% --- packages/auth/src/core/providers/facebook.test.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/auth/src/core/providers/facebook.test.ts b/packages/auth/src/core/providers/facebook.test.ts index b271f08c013..30e42648404 100644 --- a/packages/auth/src/core/providers/facebook.test.ts +++ b/packages/auth/src/core/providers/facebook.test.ts @@ -120,4 +120,16 @@ describe('core/providers/facebook', () => { // Restore original method FacebookAuthProvider.credential = original; }); + + it('returns null when error.customData is undefined (falls back to empty object)', () => { + const error = _createError(AuthErrorCode.NEED_CONFIRMATION, { + appName: 'foo' + }); + + // Don't set `customData` at all → fallback to {} + delete (error as any).customData; + + const cred = FacebookAuthProvider.credentialFromError(error); + expect(cred).to.be.null; + }); });