Skip to content

Commit

Permalink
fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cksidharthan committed Sep 21, 2024
1 parent 20896c6 commit c3d6dbd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 38 deletions.
16 changes: 8 additions & 8 deletions accounts_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ 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
}
return &account, nil
}

// 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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
28 changes: 8 additions & 20 deletions accounts_endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand All @@ -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)
})
Expand All @@ -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)
})
Expand All @@ -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)
})
Expand All @@ -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)
})
Expand All @@ -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)
})
Expand All @@ -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)
})
Expand All @@ -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)
})
Expand Down
11 changes: 1 addition & 10 deletions token_endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package gocardless_test

import (
"context"
"net/http"
"testing"

gocardless "github.com/cksidharthan/go-gocardless"
"github.com/stretchr/testify/assert"
)

Expand All @@ -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)
})
}

Expand Down

0 comments on commit c3d6dbd

Please sign in to comment.