Skip to content

Increase unit test coverage for facebook.ts to 100% #9129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions packages/auth/src/core/providers/facebook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -66,4 +71,65 @@ 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;
});

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;
});
});
Loading