From 05fe08801b882bddec4254adbba82a50a928a483 Mon Sep 17 00:00:00 2001 From: mansisampat Date: Fri, 27 Jun 2025 15:19:37 +0530 Subject: [PATCH 1/2] Increase unit test coverage for github.ts to 100% --- .../auth/src/core/providers/github.test.ts | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/packages/auth/src/core/providers/github.test.ts b/packages/auth/src/core/providers/github.test.ts index 9e7d0d73de8..4c6a33ab850 100644 --- a/packages/auth/src/core/providers/github.test.ts +++ b/packages/auth/src/core/providers/github.test.ts @@ -35,6 +35,11 @@ describe('core/providers/github', () => { expect(cred.signInMethod).to.eq(SignInMethod.GITHUB); }); + it('generates Github provider', () => { + const provider = new GithubAuthProvider(); + expect(provider.providerId).to.eq(ProviderId.GITHUB); + }); + it('credentialFromResult creates the cred from a tagged result', async () => { const auth = await testAuth(); const userCred = new UserCredentialImpl({ @@ -66,4 +71,65 @@ describe('core/providers/github', () => { expect(cred.providerId).to.eq(ProviderId.GITHUB); expect(cred.signInMethod).to.eq(SignInMethod.GITHUB); }); + + it('returns null when _tokenResponse is missing', () => { + const error = _createError(AuthErrorCode.NEED_CONFIRMATION, { + appName: 'foo' + }); + error.customData = {}; // no _tokenResponse + + const cred = GithubAuthProvider.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 = GithubAuthProvider.credentialFromError(error); + expect(cred).to.be.null; + }); + + it('returns null when GithubAuthProvider.credential throws', () => { + // Temporarily stub credential method to throw + const original = GithubAuthProvider.credential; + GithubAuthProvider.credential = () => { + throw new Error('Simulated failure'); + }; + + const error = _createError(AuthErrorCode.NEED_CONFIRMATION, { + appName: 'foo' + }); + error.customData = { + _tokenResponse: { + oauthAccessToken: 'valid-token' + } + }; + + const cred = GithubAuthProvider.credentialFromError(error); + expect(cred).to.be.null; + + // Restore original method + GithubAuthProvider.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 = GithubAuthProvider.credentialFromError(error); + expect(cred).to.be.null; + }); }); From 481e7c605151d5fbd47b99afc43529cc19987fc8 Mon Sep 17 00:00:00 2001 From: mansisampat Date: Fri, 27 Jun 2025 15:24:26 +0530 Subject: [PATCH 2/2] yarn run format --- packages/auth/src/core/providers/github.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/auth/src/core/providers/github.test.ts b/packages/auth/src/core/providers/github.test.ts index 4c6a33ab850..2cb15a1be0d 100644 --- a/packages/auth/src/core/providers/github.test.ts +++ b/packages/auth/src/core/providers/github.test.ts @@ -36,9 +36,9 @@ describe('core/providers/github', () => { }); it('generates Github provider', () => { - const provider = new GithubAuthProvider(); - expect(provider.providerId).to.eq(ProviderId.GITHUB); - }); + const provider = new GithubAuthProvider(); + expect(provider.providerId).to.eq(ProviderId.GITHUB); + }); it('credentialFromResult creates the cred from a tagged result', async () => { const auth = await testAuth();