Files
go-garth/internal/api/client/client_test.go
sstent bb07b261bf Refactor: Complete authentication flow changes
This commit includes the remaining files from the authentication flow refactoring.\nThese changes were part of the initial diff between c00ea67f31 and HEAD,\nand complete the transition to the new SSO and OAuth-based authentication mechanism.
2025-09-18 13:32:33 -07:00

47 lines
1.0 KiB
Go

package client_test
import (
"crypto/tls"
"net/http"
"net/url"
"testing"
"time"
"garmin-connect/internal/testutils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"garmin-connect/internal/api/client"
)
func TestClient_GetUserProfile(t *testing.T) {
// Create mock server returning user profile
server := testutils.MockJSONResponse(http.StatusOK, `{
"userName": "testuser",
"displayName": "Test User",
"fullName": "Test User",
"location": "Test Location"
}`)
defer server.Close()
// Create client with test configuration
u, _ := url.Parse(server.URL)
c, err := client.NewClient(u.Host)
require.NoError(t, err)
c.HTTPClient = &http.Client{
Timeout: 5 * time.Second,
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
}
c.AuthToken = "Bearer testtoken"
// Get user profile
profile, err := c.GetUserProfile()
// Verify response
require.NoError(t, err)
assert.Equal(t, "testuser", profile.UserName)
assert.Equal(t, "Test User", profile.DisplayName)
}