Files
geniusrun/backend/internal/garmin/client_test.go
2026-07-17 18:57:54 +02:00

40 lines
1.2 KiB
Go

package garmin
import "testing"
func TestParseAuthResult(t *testing.T) {
cases := []struct {
msg string
want AuthStatus
}{
{"Authenticated successfully.", AuthSuccess},
{"MFA accepted. Authenticated successfully.", AuthSuccess},
{"MFA required. Garmin has sent a verification code...", AuthMFARequired},
{"Authentication failed: 401 Unauthorized (Invalid Username or Password)", AuthFailed},
{"Authentication failed after MFA: bad code", AuthFailed},
}
for _, c := range cases {
got := parseAuthResult(c.msg)
if got.Status != c.want {
t.Errorf("parseAuthResult(%q).Status = %v, want %v", c.msg, got.Status, c.want)
}
}
}
func TestMcpClient_UpdateCredentials_ResetsStartedState(t *testing.T) {
c := &mcpClient{cfg: Config{GarminEmail: "old@example.com", GarminPassword: "old"}}
c.started = true // simulate an already-spawned subprocess
c.UpdateCredentials("new@example.com", "new")
if c.cfg.GarminEmail != "new@example.com" || c.cfg.GarminPassword != "new" {
t.Errorf("cfg after update = %+v, want new@example.com/new", c.cfg)
}
if c.started {
t.Error("started should be reset to false so the next call respawns the subprocess")
}
if c.inner != nil {
t.Error("inner should be cleared so ensureStarted spawns a fresh client")
}
}