Skip to content

Commit

Permalink
Add unit test for accounts #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas Matt committed Jan 30, 2017
1 parent d2004a5 commit 989d733
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 3 deletions.
9 changes: 6 additions & 3 deletions accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@

package coinbase

import "bytes"
import (
"bytes"
"time"
)

/*
Expand Down Expand Up @@ -54,8 +57,8 @@ type APIAccountData struct {
Currency string
Balance APIBalance
Native_balance APIBalance
Created_at string
Updated_at string
Created_at *time.Time
Updated_at *time.Time
Resource string
Resource_path string
}
Expand Down
59 changes: 59 additions & 0 deletions test/accounts_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package coinbase_test

import (
"testing"
"zauberstuhl/coinbase"
)

func TestAccounts(t *testing.T) {
s := serverHelper(`
{
"data": {
"id": "2bbf394c-193b-5b2a-9155-3b4732659ede",
"name": "My Wallet",
"primary": true,
"type": "wallet",
"currency": "BTC",
"balance": {
"amount": "39.59000000",
"currency": "BTC"
},
"native_balance": {
"amount": "395.90",
"currency": "USD"
},
"created_at": "2015-01-31T20:49:02Z",
"updated_at": "2015-01-31T20:49:02Z",
"resource": "account",
"resource_path": "/v2/accounts/2bbf394c-193b-5b2a-9155-3b4732659ede"
}
}
`)
defer s.Close()

a := coinbase.APIClient{
Key: "123",
Secret: "123456",
Endpoint: s.URL,
}

acc, err := a.Account("2bbf394c-193b-5b2a-9155-3b4732659ede")
if err != nil {
t.Error("Expected nil, got ", err.Error())
}
if acc.Data.Id != "2bbf394c-193b-5b2a-9155-3b4732659ede" {
t.Error("Expected 2bbf394c-193b-5b2a-9155-3b4732659ede, got ", acc.Data.Id)
}
if acc.Data.Balance.Amount != 39.59 {
t.Error("Expected 39.59, got ", acc.Data.Balance.Amount)
}
if acc.Data.Native_balance.Amount != 395.90 {
t.Error("Expected 395.90, got ", acc.Data.Native_balance.Amount)
}
if acc.Data.Created_at.Year() != 2015 {
t.Error("Expected 2015, got ", acc.Data.Created_at.Year())
}
if acc.Data.Updated_at.Year() != 2015 {
t.Error("Expected 2015, got ", acc.Data.Created_at.Year())
}
}
14 changes: 14 additions & 0 deletions test/helper_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package coinbase_test

import (
"net/http"
"net/http/httptest"
"fmt"
)

func serverHelper(body string) *httptest.Server {
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
fmt.Fprintln(w, body)
}))
}

0 comments on commit 989d733

Please sign in to comment.