diff --git a/accounts_endpoints.go b/accounts_endpoints.go index afb3aff..a599aa3 100644 --- a/accounts_endpoints.go +++ b/accounts_endpoints.go @@ -5,10 +5,10 @@ import ( ) // GetAccount retrieves an account by ID -func (c Client) GetAccount(ctx context.Context, token string, accountID string) (*Account, error) { +func (c Client) GetAccount(ctx context.Context, accountID string) (*Account, error) { var account Account endpointURL := AccountsPath + accountID - err := c.HTTP.Get(ctx, endpointURL, RequestHeadersWithAuth(token), &account) + err := c.HTTP.Get(ctx, endpointURL, RequestHeadersWithAuth(c.Token.Access), &account) if err != nil { return nil, err } @@ -16,10 +16,10 @@ func (c Client) GetAccount(ctx context.Context, token string, accountID string) } // GetAccountBalances retrieves balances for an account by ID -func (c Client) GetAccountBalances(ctx context.Context, token string, accountID string) (*Balances, error) { +func (c Client) GetAccountBalances(ctx context.Context, accountID string) (*Balances, error) { var balances Balances endpointURL := AccountsPath + accountID + "/balances" - err := c.HTTP.Get(ctx, endpointURL, RequestHeadersWithAuth(token), &balances) + err := c.HTTP.Get(ctx, endpointURL, RequestHeadersWithAuth(c.Token.Access), &balances) if err != nil { return nil, err } @@ -28,10 +28,10 @@ func (c Client) GetAccountBalances(ctx context.Context, token string, accountID } // GetAccountDetails retrieves details for an account by ID -func (c Client) GetAccountDetails(ctx context.Context, token string, accountID string) (*Details, error) { +func (c Client) GetAccountDetails(ctx context.Context, accountID string) (*Details, error) { var details Details endpointURL := AccountsPath + accountID + "/details" - err := c.HTTP.Get(ctx, endpointURL, RequestHeadersWithAuth(token), &details) + err := c.HTTP.Get(ctx, endpointURL, RequestHeadersWithAuth(c.Token.Access), &details) if err != nil { return nil, err } @@ -40,10 +40,10 @@ func (c Client) GetAccountDetails(ctx context.Context, token string, accountID s } // GetAccountTransactions retrieves transactions for an account by ID -func (c Client) GetAccountTransactions(ctx context.Context, token string, accountID string) (*Transactions, error) { +func (c Client) GetAccountTransactions(ctx context.Context, accountID string) (*Transactions, error) { var transactions Transactions endpointURL := AccountsPath + accountID + "/transactions" - err := c.HTTP.Get(ctx, endpointURL, RequestHeadersWithAuth(token), &transactions) + err := c.HTTP.Get(ctx, endpointURL, RequestHeadersWithAuth(c.Token.Access), &transactions) if err != nil { return nil, err } diff --git a/accounts_endpoints_test.go b/accounts_endpoints_test.go index fd9713d..abc00d7 100644 --- a/accounts_endpoints_test.go +++ b/accounts_endpoints_test.go @@ -18,13 +18,9 @@ func TestClient_GetAccount(t *testing.T) { assert.NotNil(t, client) assert.NoError(t, err) - token, err := client.NewToken(context.Background()) - assert.NoError(t, err) - assert.NotNil(t, token) - testAccountID := os.Getenv("GOCARDLESS_TEST_ACCOUNT_ID") - account, err := client.GetAccount(context.Background(), token.Access, testAccountID) + account, err := client.GetAccount(context.Background(), testAccountID) assert.NoError(t, err) assert.NotNil(t, account) }) @@ -36,11 +32,7 @@ func TestClient_GetAccount(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, client) - token, err := client.NewToken(context.Background()) - assert.NoError(t, err) - assert.NotNil(t, token) - - account, err := client.GetAccount(context.Background(), token.Access, "invalid") + account, err := client.GetAccount(context.Background(), "invalid") assert.Error(t, err) assert.Nil(t, account) }) @@ -56,13 +48,9 @@ func TestClient_GetAccountBalances(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, client) - token, err := client.NewToken(context.Background()) - assert.NoError(t, err) - assert.NotNil(t, token) - testAccountID := os.Getenv("GOCARDLESS_TEST_ACCOUNT_ID") - balances, err := client.GetAccountBalances(context.Background(), token.Access, testAccountID) + balances, err := client.GetAccountBalances(context.Background(), testAccountID) assert.NoError(t, err) assert.NotNil(t, balances) }) @@ -78,7 +66,7 @@ func TestClient_GetAccountBalances(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, token) - balances, err := client.GetAccountBalances(context.Background(), token.Access, "invalid") + balances, err := client.GetAccountBalances(context.Background(), "invalid") assert.Error(t, err) assert.Nil(t, balances) }) @@ -100,7 +88,7 @@ func TestClient_GetAccountDetails(t *testing.T) { testAccountID := os.Getenv("GOCARDLESS_TEST_ACCOUNT_ID") - details, err := client.GetAccountDetails(context.Background(), token.Access, testAccountID) + details, err := client.GetAccountDetails(context.Background(), testAccountID) assert.NoError(t, err) assert.NotNil(t, details) }) @@ -116,7 +104,7 @@ func TestClient_GetAccountDetails(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, token) - details, err := client.GetAccountDetails(context.Background(), token.Access, "invalid") + details, err := client.GetAccountDetails(context.Background(), "invalid") assert.Error(t, err) assert.Nil(t, details) }) @@ -138,7 +126,7 @@ func TestClient_GetAccountTransactions(t *testing.T) { testAccountID := os.Getenv("GOCARDLESS_TEST_ACCOUNT_ID") - transactions, err := client.GetAccountTransactions(context.Background(), token.Access, testAccountID) + transactions, err := client.GetAccountTransactions(context.Background(), testAccountID) assert.NoError(t, err) assert.NotNil(t, transactions) }) @@ -154,7 +142,7 @@ func TestClient_GetAccountTransactions(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, token) - transactions, err := client.GetAccountTransactions(context.Background(), token.Access, "invalid") + transactions, err := client.GetAccountTransactions(context.Background(), "invalid") assert.Error(t, err) assert.Nil(t, transactions) }) diff --git a/token_endpoints_test.go b/token_endpoints_test.go index 77bdf19..196169b 100644 --- a/token_endpoints_test.go +++ b/token_endpoints_test.go @@ -2,10 +2,8 @@ package gocardless_test import ( "context" - "net/http" "testing" - gocardless "github.com/cksidharthan/go-gocardless" "github.com/stretchr/testify/assert" ) @@ -28,15 +26,8 @@ func TestClient_NewToken(t *testing.T) { t.Parallel() invalidClient, err := getInvalidTestClient(t) - assert.NoError(t, err) - assert.NotNil(t, invalidClient) - - token, err := invalidClient.NewToken(context.Background()) assert.Error(t, err) - assert.Nil(t, token) - - checkErr := gocardless.ExtractError(err) - assert.Equal(t, http.StatusUnauthorized, checkErr.StatusCode) + assert.Nil(t, invalidClient) }) }