This repository has been archived by the owner on Jan 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathaddresses_test.go
117 lines (104 loc) · 2.28 KB
/
addresses_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 starling
import (
"context"
"encoding/json"
"fmt"
"net/http"
"reflect"
"testing"
)
var addressesTestCases = []struct {
name string
mock string
}{
{
name: "single address",
mock: `{
"current": {
"streetAddress": "3rd Floor",
"city": "London",
"country": "GBR",
"postcode": " EC2M 2PP"
},
"previous": []
}`,
},
{
name: "single previous address",
mock: `{
"current": {
"streetAddress": "3rd Floor",
"city": "London",
"country": "GBR",
"postcode": " EC2M 2PP"
},
"previous": [{
"streetAddress": "3rd Floor",
"city": "London",
"country": "GBR",
"postcode": " EC2M 2PP"
}]
}`,
},
{
name: "multiple previous addresses",
mock: `{
"current": {
"streetAddress": "3rd Floor",
"city": "London",
"country": "GBR",
"postcode": " EC2M 2PP"
},
"previous": [{
"streetAddress": "3rd Floor",
"city": "London",
"country": "GBR",
"postcode": " EC2M 2PP"
},
{
"streetAddress": "3rd Floor",
"city": "London",
"country": "GBR",
"postcode": " EC2M 2PP"
}]
}`,
},
}
func TestAddressHistory(t *testing.T) {
for _, tc := range addressesTestCases {
t.Run(tc.name, func(st *testing.T) {
testAddressHistory(st, tc.name, tc.mock)
})
}
}
func testAddressHistory(t *testing.T, name, mock string) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc("/api/v1/addresses", func(w http.ResponseWriter, r *http.Request) {
checkMethod(t, r, http.MethodGet)
fmt.Fprint(w, mock)
})
got, _, err := client.AddressHistory(context.Background())
checkNoError(t, err)
want := &AddressHistory{}
json.Unmarshal([]byte(mock), want)
if !reflect.DeepEqual(got, want) {
t.Error("should return addresses matching the mock response", cross)
}
}
func TestAddressHistoryForbidden(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc("/api/v1/addresses", func(w http.ResponseWriter, r *http.Request) {
checkMethod(t, r, http.MethodGet)
w.WriteHeader(http.StatusForbidden)
})
got, resp, err := client.AddressHistory(context.Background())
checkHasError(t, err)
if resp.StatusCode != http.StatusForbidden {
t.Error("should return HTTP 403 status")
}
if got != nil {
t.Error("should not return any addresses")
}
}