Files
go-garth/internal/api/client/auth_test.go
sstent 2fdfbea34e feat(refactor): Implement 1A.1 Package Structure Refactoring
This commit implements the package structure refactoring as outlined in phase1.md (Task 1A.1).

Key changes include:
- Reorganized packages into `pkg/garmin` for public API and `internal/` for internal implementations.
- Updated all import paths to reflect the new structure.
- Consolidated types and client logic into their respective new packages.
- Updated `cmd/garth/main.go` to use the new public API.
- Fixed various compilation and test issues encountered during the refactoring process.
- Converted `internal/api/client/auth_test.go` to a functional test.

This establishes a solid foundation for future enhancements and improves maintainability.
2025-09-18 13:13:39 -07:00

37 lines
1.0 KiB
Go

package client_test
import (
"testing"
"garmin-connect/internal/api/client"
"garmin-connect/internal/auth/credentials"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestClient_Login_Functional(t *testing.T) {
if testing.Short() {
t.Skip("Skipping functional test in short mode")
}
// Load credentials from .env file
email, password, domain, err := credentials.LoadEnvCredentials()
require.NoError(t, err, "Failed to load credentials from .env file. Please ensure GARMIN_EMAIL, GARMIN_PASSWORD, and GARMIN_DOMAIN are set.")
// Create client
c, err := client.NewClient(domain)
require.NoError(t, err, "Failed to create client")
// Perform login
err = c.Login(email, password)
require.NoError(t, err, "Login failed")
// Verify login
assert.NotEmpty(t, c.AuthToken, "AuthToken should not be empty after login")
assert.NotEmpty(t, c.Username, "Username should not be empty after login")
// Logout for cleanup
err = c.Logout()
assert.NoError(t, err, "Logout failed")
}