feat: add token file and env Login
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package auth_test
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"s1d3sw1ped/robinhood-agentic-mcp/auth"
|
||||
)
|
||||
|
||||
func TestLoginFromEnv(t *testing.T) {
|
||||
t.Setenv("ROBINHOOD_ACCESS_TOKEN", "tok-live")
|
||||
t.Setenv("ROBINHOOD_REFRESH_TOKEN", "ref")
|
||||
path := filepath.Join(t.TempDir(), "tokens.json")
|
||||
id, err := auth.Login(t.Context(), auth.Config{TokenFile: path, Name: "tradey", Version: "9"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if id != "" {
|
||||
t.Fatalf("id %q", id)
|
||||
}
|
||||
tok, err := auth.ReadTokens(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if tok.AccessToken != "tok-live" || tok.RefreshToken != "ref" {
|
||||
t.Fatalf("%+v", tok)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithDefaults(t *testing.T) {
|
||||
t.Parallel()
|
||||
c := auth.Config{}.WithDefaults()
|
||||
if c.URL != auth.DefaultURL || c.Name != auth.DefaultName || c.Version != auth.DefaultVersion {
|
||||
t.Fatalf("%+v", c)
|
||||
}
|
||||
c = auth.Config{Name: "tradey", Version: "1.2.3", URL: "http://x"}.WithDefaults()
|
||||
if c.Name != "tradey" || c.Version != "1.2.3" || c.URL != "http://x" {
|
||||
t.Fatalf("%+v", c)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user