-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorganizations_test.go
117 lines (98 loc) · 2.57 KB
/
organizations_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package goqonto
import (
"fmt"
"net/http"
"reflect"
"testing"
)
var (
organizationFixture = `{
"organization": {
"slug": "croissant-9134",
"bank_accounts": [
{
"slug": "croissant-bank-account-1",
"iban": "FR7616798000010000004321396",
"bic": "TRZOFR21XXX",
"currency": "EUR",
"balance": 225.3,
"balance_cents": 22530,
"authorized_balance": 213.2,
"authorized_balance_cents": 21320
}
]
}
}`
bankAccount = BankAccount{
Slug: "croissant-bank-account-1",
IBAN: "FR7616798000010000004321396",
BIC: "TRZOFR21XXX",
Currency: "EUR",
Balance: 225.3,
BalanceCents: 22530,
AuthorizedBalance: 213.2,
AuthorizedBalanceCents: 21320,
}
organization = Organization{
Slug: "croissant-9134",
BankAccounts: []BankAccount{bankAccount},
}
)
func TestOrganization_marshall(t *testing.T) {
testJSONMarshal(t, Organization{}, "{}")
want := `{
"slug": "croissant-9134",
"bank_accounts": [
{
"slug": "croissant-bank-account-1",
"iban": "FR7616798000010000004321396",
"bic": "TRZOFR21XXX",
"currency": "EUR",
"balance": 225.3,
"balance_cents": 22530,
"authorized_balance": 213.2,
"authorized_balance_cents": 21320
}
]
}`
testJSONMarshal(t, organization, want)
}
func TestOrganizationsService_Get(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc(fmt.Sprintf("/%s/9134", organizationsBasePath), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
testHeader(t, r, "Accept", mediaType)
testHeader(t, r, "Content-Type", mediaType)
fmt.Fprint(w, organizationFixture)
})
got, _, err := client.Organizations.Get(ctx, "9134")
if err != nil {
t.Errorf("Organizations.Get returned error: %v", err)
}
want := &organization
if !reflect.DeepEqual(got, want) {
t.Errorf("Organizations.Get \n got %v\n want %v\n", got, want)
}
}
func TestOrganizationsService_Get_Error(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
testHeader(t, r, "Accept", mediaType)
testHeader(t, r, "Content-Type", mediaType)
w.WriteHeader(http.StatusNotFound)
fmt.Fprint(w, `{ "message": "Not found" }`)
})
got, resp, err := client.Organizations.Get(ctx, "9134")
if err.Error() == "" {
t.Errorf("Expected non-empty err.Error()")
}
if resp.StatusCode != http.StatusNotFound {
t.Errorf("Expected 404 Status")
}
if got != nil {
t.Errorf("Expected empty body")
}
}