Skip to content

Commit 247b92f

Browse files
authored
Increase unit test coverage for github.ts to 100% (#9130)
* Increase unit test coverage for github.ts to 100%
1 parent 5d13166 commit 247b92f

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

packages/auth/src/core/providers/github.test.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ describe('core/providers/github', () => {
3535
expect(cred.signInMethod).to.eq(SignInMethod.GITHUB);
3636
});
3737

38+
it('generates Github provider', () => {
39+
const provider = new GithubAuthProvider();
40+
expect(provider.providerId).to.eq(ProviderId.GITHUB);
41+
});
42+
3843
it('credentialFromResult creates the cred from a tagged result', async () => {
3944
const auth = await testAuth();
4045
const userCred = new UserCredentialImpl({
@@ -66,4 +71,65 @@ describe('core/providers/github', () => {
6671
expect(cred.providerId).to.eq(ProviderId.GITHUB);
6772
expect(cred.signInMethod).to.eq(SignInMethod.GITHUB);
6873
});
74+
75+
it('returns null when _tokenResponse is missing', () => {
76+
const error = _createError(AuthErrorCode.NEED_CONFIRMATION, {
77+
appName: 'foo'
78+
});
79+
error.customData = {}; // no _tokenResponse
80+
81+
const cred = GithubAuthProvider.credentialFromError(error);
82+
expect(cred).to.be.null;
83+
});
84+
85+
it('returns null when _tokenResponse is missing oauthAccessToken key', () => {
86+
const error = _createError(AuthErrorCode.NEED_CONFIRMATION, {
87+
appName: 'foo'
88+
});
89+
error.customData = {
90+
_tokenResponse: {
91+
// intentionally missing oauthAccessToken
92+
idToken: 'some-id-token',
93+
oauthAccessToken: null
94+
}
95+
};
96+
97+
const cred = GithubAuthProvider.credentialFromError(error);
98+
expect(cred).to.be.null;
99+
});
100+
101+
it('returns null when GithubAuthProvider.credential throws', () => {
102+
// Temporarily stub credential method to throw
103+
const original = GithubAuthProvider.credential;
104+
GithubAuthProvider.credential = () => {
105+
throw new Error('Simulated failure');
106+
};
107+
108+
const error = _createError(AuthErrorCode.NEED_CONFIRMATION, {
109+
appName: 'foo'
110+
});
111+
error.customData = {
112+
_tokenResponse: {
113+
oauthAccessToken: 'valid-token'
114+
}
115+
};
116+
117+
const cred = GithubAuthProvider.credentialFromError(error);
118+
expect(cred).to.be.null;
119+
120+
// Restore original method
121+
GithubAuthProvider.credential = original;
122+
});
123+
124+
it('returns null when error.customData is undefined (falls back to empty object)', () => {
125+
const error = _createError(AuthErrorCode.NEED_CONFIRMATION, {
126+
appName: 'foo'
127+
});
128+
129+
// Don't set `customData` at all → fallback to {}
130+
delete (error as any).customData;
131+
132+
const cred = GithubAuthProvider.credentialFromError(error);
133+
expect(cred).to.be.null;
134+
});
69135
});

0 commit comments

Comments
 (0)