-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Account API endpoint[ch28502] (#41)
* Add Account API endpoint[ch28502] * code review, removed omitempty and error field from account struct
- Loading branch information
1 parent
a401318
commit 651a11c
Showing
5 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package chartmogul | ||
|
||
const ( | ||
accountEndpoint = "account" | ||
) | ||
|
||
// Account details in ChartMogul | ||
type Account struct { | ||
Name string `json:"name"` | ||
Currency string `json:"currency"` | ||
TimeZone string `json:"time_zone"` | ||
WeekStartOn string `json:"week_start_on"` | ||
} | ||
|
||
// RetrieveAccount returns details of current account. | ||
func (api API) RetrieveAccount() (*Account, error) { | ||
result := &Account{} | ||
accountUUID := "" | ||
return result, api.retrieve(accountEndpoint, accountUUID, result) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package chartmogul | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/davecgh/go-spew/spew" | ||
) | ||
|
||
const accountExample = `{ | ||
"name": "Example Test Company", | ||
"currency": "EUR", | ||
"time_zone": "Europe/Berlin", | ||
"week_start_on": "sunday" | ||
}` | ||
|
||
func TestRetrieveAccount(t *testing.T) { | ||
server := httptest.NewServer( | ||
http.HandlerFunc( | ||
func(w http.ResponseWriter, r *http.Request) { | ||
expectedMethod := "GET" | ||
if r.Method != expectedMethod { | ||
t.Errorf("Requested method expected: %v, actual: %v", expectedMethod, r.Method) | ||
} | ||
expected := "/v/account" | ||
path := r.URL.Path | ||
if path != expected { | ||
t.Errorf("Requested path expected: %v, actual: %v", expected, path) | ||
w.WriteHeader(http.StatusNotFound) | ||
} | ||
w.Write([]byte(accountExample)) //nolint | ||
})) | ||
defer server.Close() | ||
SetURL(server.URL + "/v/%v") | ||
|
||
var tested IApi = &API{ | ||
AccountToken: "token", | ||
AccessKey: "key", | ||
} | ||
account, err := tested.RetrieveAccount() | ||
|
||
if account.Name != "Example Test Company" || account.Currency != "EUR" || account.TimeZone != "Europe/Berlin" || account.WeekStartOn != "sunday" { | ||
spew.Dump(account) | ||
t.Error("Unexpected account details") | ||
} | ||
if err != nil { | ||
spew.Dump(err) | ||
t.Fatal("Not expected to fail") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters