Skip to content

test: add unit tests for OAuth2CredentialRefresher#403

Open
sarathfrancis90 wants to merge 2 commits into
google:mainfrom
sarathfrancis90:test-oauth2-credential-refresher
Open

test: add unit tests for OAuth2CredentialRefresher#403
sarathfrancis90 wants to merge 2 commits into
google:mainfrom
sarathfrancis90:test-oauth2-credential-refresher

Conversation

@sarathfrancis90

Copy link
Copy Markdown

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 sibling OAuth2CredentialExchanger is already covered by core/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 (mocking oauth2_utils.js). The suite covers the real branches of the class:

  • isRefreshNeeded: no oauth2 field, oauth2 without expiresAt, token not expired, and token expired.
  • refresh: missing oauth2, missing auth scheme, missing refresh token, refresh not needed, missing token endpoint, missing clientId/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 OAuth2CredentialRefresher to coverage parity with OAuth2CredentialExchanger and mirrors the equivalent test in adk-python. No source code changes are included; this is test-only.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

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.ts goes 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

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants