2026-07-17 18:33:06 +02:00
|
|
|
// Package mock provides a fake garmin.Client for tests and frontend/dev
|
2026-07-25 21:43:52 +02:00
|
|
|
// work without a live Garmin account or the wrapper subprocess.
|
2026-07-17 18:33:06 +02:00
|
|
|
package mock
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
2026-07-24 21:08:07 +02:00
|
|
|
"geniusrun/backend/internal/garmin"
|
2026-07-17 18:33:06 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Client is a fake garmin.Client returning data supplied by the test/caller.
|
|
|
|
|
type Client struct {
|
|
|
|
|
AuthResults []garmin.AuthResult // consumed in order by Authenticate/CompleteMFA calls
|
|
|
|
|
Activities []garmin.Activity
|
|
|
|
|
Splits map[int64]garmin.ActivitySplits
|
|
|
|
|
Details map[int64]garmin.ActivityDetails
|
2026-07-19 11:55:13 +02:00
|
|
|
Workouts map[int64]garmin.Workout
|
2026-07-17 18:33:06 +02:00
|
|
|
Err error // if set, every call returns this error
|
|
|
|
|
authResultCursor int
|
|
|
|
|
ClosedCalled bool
|
|
|
|
|
GetActivitiesCalls int
|
2026-07-17 18:57:54 +02:00
|
|
|
LastEmail string
|
|
|
|
|
LastPassword string
|
2026-07-17 18:33:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var _ garmin.Client = (*Client)(nil)
|
|
|
|
|
|
|
|
|
|
func (c *Client) nextAuthResult() garmin.AuthResult {
|
|
|
|
|
if c.authResultCursor >= len(c.AuthResults) {
|
|
|
|
|
return garmin.AuthResult{Status: garmin.AuthSuccess, Message: "Authenticated successfully."}
|
|
|
|
|
}
|
|
|
|
|
r := c.AuthResults[c.authResultCursor]
|
|
|
|
|
c.authResultCursor++
|
|
|
|
|
return r
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *Client) Authenticate(ctx context.Context) (garmin.AuthResult, error) {
|
|
|
|
|
if c.Err != nil {
|
|
|
|
|
return garmin.AuthResult{}, c.Err
|
|
|
|
|
}
|
|
|
|
|
return c.nextAuthResult(), nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *Client) CompleteMFA(ctx context.Context, code string) (garmin.AuthResult, error) {
|
|
|
|
|
if c.Err != nil {
|
|
|
|
|
return garmin.AuthResult{}, c.Err
|
|
|
|
|
}
|
|
|
|
|
return c.nextAuthResult(), nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *Client) GetActivities(ctx context.Context, startDate, endDate string, limit int) ([]garmin.Activity, error) {
|
|
|
|
|
c.GetActivitiesCalls++
|
|
|
|
|
if c.Err != nil {
|
|
|
|
|
return nil, c.Err
|
|
|
|
|
}
|
|
|
|
|
if limit > 0 && limit < len(c.Activities) {
|
|
|
|
|
return c.Activities[:limit], nil
|
|
|
|
|
}
|
|
|
|
|
return c.Activities, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *Client) GetActivitySplits(ctx context.Context, activityID int64) (garmin.ActivitySplits, error) {
|
|
|
|
|
if c.Err != nil {
|
|
|
|
|
return garmin.ActivitySplits{}, c.Err
|
|
|
|
|
}
|
|
|
|
|
return c.Splits[activityID], nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *Client) GetActivityDetails(ctx context.Context, activityID int64) (garmin.ActivityDetails, error) {
|
|
|
|
|
if c.Err != nil {
|
|
|
|
|
return garmin.ActivityDetails{}, c.Err
|
|
|
|
|
}
|
|
|
|
|
return c.Details[activityID], nil
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-19 11:55:13 +02:00
|
|
|
func (c *Client) GetWorkoutByID(ctx context.Context, workoutID int64) (garmin.Workout, error) {
|
|
|
|
|
if c.Err != nil {
|
|
|
|
|
return garmin.Workout{}, c.Err
|
|
|
|
|
}
|
|
|
|
|
return c.Workouts[workoutID], nil
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-17 18:57:54 +02:00
|
|
|
func (c *Client) UpdateCredentials(email, password string) {
|
|
|
|
|
c.LastEmail = email
|
|
|
|
|
c.LastPassword = password
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-17 18:33:06 +02:00
|
|
|
func (c *Client) Close() error {
|
|
|
|
|
c.ClosedCalled = true
|
|
|
|
|
return nil
|
|
|
|
|
}
|