mirror of
https://github.com/sstent/go-garth.git
synced 2026-01-25 16:42:28 +00:00
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.
47 lines
1.0 KiB
Go
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)
|
|
} |