test: add unit tests for OAuth2CredentialRefresher#403
Open
sarathfrancis90 wants to merge 2 commits into
Open
Conversation
Add unit tests for OAuth2CredentialRefresher, which previously had no test coverage while its sibling OAuth2CredentialExchanger was already tested. The tests cover isRefreshNeeded (no oauth2, missing expiresAt, expired and non-expired tokens) and refresh (missing oauth2, missing auth scheme, missing refresh token, refresh not needed, missing token endpoint, missing client credentials, successful refresh, response field fallback, request body construction, and fetch failure). This brings the refresher to coverage parity with the exchanger and mirrors the equivalent test in adk-python.
kalenkevich
approved these changes
Jun 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to Issue or Description of Change
2. Or, if no issue exists, describe the change:
Problem:
core/src/auth/oauth2/oauth2_credential_refresher.ts(OAuth2CredentialRefresher) had no unit tests and 0% coverage, while its siblingOAuth2CredentialExchangeris already covered bycore/test/auth/oauth2/oauth2_credential_exchanger_test.ts. adk-python also has an equivalent test for its refresher, so the JS side was missing parity.Solution:
Add
core/test/auth/oauth2/oauth2_credential_refresher_test.ts, following the established pattern used by the exchanger test (mockingoauth2_utils.js). The suite covers the real branches of the class:isRefreshNeeded: nooauth2field,oauth2withoutexpiresAt, token not expired, and token expired.refresh: missingoauth2, missing auth scheme, missing refresh token, refresh not needed, missing token endpoint, missingclientId/clientSecret, successful refresh, response-field fallback (preserving existing values when the response omits them), refresh-token request body construction, and fetch failure (returns the original credential).This brings
OAuth2CredentialRefresherto coverage parity withOAuth2CredentialExchangerand mirrors the equivalent test in adk-python. No source code changes are included; this is test-only.Testing Plan
Unit Tests:
Local results:
npm test: 1869 passed, 28 skipped (171 test files). The new file contributes 14 passing tests.npm run test:coverage:core/src/auth/oauth2/oauth2_credential_refresher.tsgoes from 0% to 100% (statements 64/64, branches 23/23, functions 2/2).npm run lint: clean.npm run format:check: clean.npm run docs:check: clean.Manual End-to-End (E2E) Tests:
Not applicable. This is a test-only change with no runtime behavior changes.
Checklist
Additional context
Test-only change. No prior issue is required for a test addition. The new file includes the Apache 2.0 license header matching the other test files in the repository.