Skip to content

[client] add refresh token method#40

Merged
capcom6 merged 1 commit intomasterfrom
codex/add-refreshtoken-method-in-client
Mar 16, 2026
Merged

[client] add refresh token method#40
capcom6 merged 1 commit intomasterfrom
codex/add-refreshtoken-method-in-client

Conversation

@capcom6
Copy link
Copy Markdown
Member

@capcom6 capcom6 commented Mar 3, 2026

Motivation

  • Provide a client-side helper to exchange a refresh token for a fresh token pair so callers can renew credentials without re-authenticating.

Description

  • Add RefreshToken(ctx context.Context, refreshToken string) (TokenResponse, error) to Client, which POSTs to /auth/refresh with an Authorization: Bearer <refreshToken> header and decodes the response into TokenResponse, returning a wrapped error on failure.

Testing

  • Ran go test ./... and the test suite completed successfully.

Codex Task

Summary by CodeRabbit

  • New Features
    • Added token refresh capability so users can exchange a refresh token for a new access/refresh token pair without re-authenticating.
  • Tests
    • Added tests covering successful refresh and server error scenarios to ensure correct responses and robust error handling.

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
smsgateway/client.go 98.21% <100.00%> (+0.13%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 3, 2026

Walkthrough

Adds a public method RefreshToken on Client to exchange a refresh token for a new token pair via POST /auth/refresh (Authorization: Bearer ), returning TokenResponse or an error; also adds tests covering success and error responses.

Changes

Cohort / File(s) Summary
Client implementation
smsgateway/client.go
Added func (c *Client) RefreshToken(ctx context.Context, refreshToken string) (TokenResponse, error) which POSTs to /auth/refresh with Authorization: Bearer <refreshToken>, parses and returns TokenResponse, and wraps errors on failure.
Tests
smsgateway/client_test.go
Added TestClient_RefreshToken with scenarios for successful 200 token refresh (validates header and response fields) and server error (500) to assert error handling.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title '[client] add refresh token method' accurately describes the main change: adding a RefreshToken method to the client.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
smsgateway/client_test.go (1)

998-1000: Assert wrapped error context in the failure case.

At Line 998-Line 1000, the error path only checks non-nil. Consider also asserting the expected wrapped message (e.g., "failed to refresh token") so regressions in error context are caught.

Proposed tightening
 import (
 	"context"
 	"io"
 	"net/http"
 	"net/http/httptest"
 	"net/url"
 	"reflect"
+	"strings"
 	"testing"
 	"time"
@@
 			resp, err := client.RefreshToken(context.Background(), tt.refreshToken)
 			if (err != nil) != tt.wantErr {
 				t.Errorf("RefreshToken error = %v, wantErr %v", err, tt.wantErr)
 			}
+			if tt.wantErr && err != nil && !strings.Contains(err.Error(), "failed to refresh token") {
+				t.Errorf("RefreshToken error = %v, expected wrapped context", err)
+			}
 			if !tt.wantErr && !reflect.DeepEqual(resp, tt.want) {
 				t.Errorf("RefreshToken response = %v, want %v", resp, tt.want)
 			}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@smsgateway/client_test.go` around lines 998 - 1000, The test currently only
verifies presence/absence of an error for RefreshToken; tighten it by asserting
the expected wrapped error message when an error is expected: in the test block
around the RefreshToken call (the failing branch where (err != nil) !=
tt.wantErr is checked), if tt.wantErr is true assert that err is non-nil and
that its message contains the expected context (e.g., "failed to refresh token")
— use err.Error() string containment or errors.Is/errors.As if you have a
sentinel or wrapped error type — so regressions that drop the error context are
caught.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@smsgateway/client_test.go`:
- Around line 998-1000: The test currently only verifies presence/absence of an
error for RefreshToken; tighten it by asserting the expected wrapped error
message when an error is expected: in the test block around the RefreshToken
call (the failing branch where (err != nil) != tt.wantErr is checked), if
tt.wantErr is true assert that err is non-nil and that its message contains the
expected context (e.g., "failed to refresh token") — use err.Error() string
containment or errors.Is/errors.As if you have a sentinel or wrapped error type
— so regressions that drop the error context are caught.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8e09521 and 76d6562.

📒 Files selected for processing (1)
  • smsgateway/client_test.go

@capcom6 capcom6 force-pushed the codex/add-refreshtoken-method-in-client branch from 76d6562 to c1a09eb Compare March 4, 2026 05:06
@capcom6 capcom6 changed the title Add RefreshToken method to client for /auth/refresh endpoint [client] add refresh token method Mar 4, 2026
@capcom6 capcom6 marked this pull request as ready for review March 4, 2026 07:55
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@capcom6 capcom6 added the ready label Mar 5, 2026
@capcom6
Copy link
Copy Markdown
Member Author

capcom6 commented Mar 5, 2026

Waiting for server release...

@capcom6 capcom6 merged commit 89278a5 into master Mar 16, 2026
8 checks passed
@capcom6 capcom6 deleted the codex/add-refreshtoken-method-in-client branch March 16, 2026 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant