This repository has been archived by the owner on Feb 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 67
/
clubs_test.go
139 lines (109 loc) · 3.46 KB
/
clubs_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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package strava
import (
"reflect"
"testing"
)
func TestClubsGet(t *testing.T) {
client := newCassetteClient(testToken, "club_get")
club, err := NewClubsService(client).Get(45255).Do()
if err != nil {
t.Fatalf("service error: %v", err)
}
expected := &ClubDetailed{}
expected.Id = 45255
expected.Name = "Test Club"
expected.ProfileMedium = "avatar/club/medium.png"
expected.Profile = "avatar/club/large.png"
expected.Description = "test description"
expected.Type = ClubTypes.CasualClub
expected.SportType = SportTypes.Cycling
expected.City = "San Francisco"
expected.State = "California"
expected.Country = "United States"
expected.Private = true
expected.MemberCount = 2
if !reflect.DeepEqual(club, expected) {
t.Errorf("should match\n%v\n%v", club, expected)
}
// from here on out just check the request parameters
s := NewClubsService(newStoreRequestClient())
// path
s.Get(321).Do()
transport := s.client.httpClient.Transport.(*storeRequestTransport)
if transport.request.URL.Path != "/api/v3/clubs/321" {
t.Errorf("request path incorrect, got %v", transport.request.URL.Path)
}
if transport.request.URL.RawQuery != "" {
t.Errorf("request query incorrect, got %v", transport.request.URL.RawQuery)
}
}
func TestClubsListMembers(t *testing.T) {
client := newCassetteClient(testToken, "club_list_members")
members, err := NewClubsService(client).ListMembers(45255).Do()
if err != nil {
t.Fatalf("service error: %v", err)
}
if len(members) == 0 {
t.Fatal("no members, how can I test?")
}
if members[0].CreatedAt.IsZero() || members[0].UpdatedAt.IsZero() {
t.Error("dates are not parsed")
}
// from here on out just check the request parameters
s := NewClubsService(newStoreRequestClient())
// per_page
s.ListMembers(45255).PerPage(1).Do()
transport := s.client.httpClient.Transport.(*storeRequestTransport)
if transport.request.URL.RawQuery != "per_page=1" {
t.Error("per_page request incorrect")
}
// page
s.ListMembers(45255).Page(3).Do()
transport = s.client.httpClient.Transport.(*storeRequestTransport)
if transport.request.URL.RawQuery != "page=3" {
t.Error("page request incorrect")
}
}
func TestClubsListActivities(t *testing.T) {
client := newCassetteClient(testToken, "club_list_activities")
activities, err := NewClubsService(client).ListActivities(45255).Do()
if err != nil {
t.Fatalf("service error: %v", err)
}
if len(activities) == 0 {
t.Fatal("no activities, how can I test")
}
if activities[0].StartDate.IsZero() || activities[0].StartDateLocal.IsZero() {
t.Error("dates are not parsed")
}
// from here on out just check the request parameters
s := NewClubsService(newStoreRequestClient())
// per_page
s.ListActivities(45255).PerPage(1).Do()
transport := s.client.httpClient.Transport.(*storeRequestTransport)
if transport.request.URL.RawQuery != "per_page=1" {
t.Error("per_page request incorrect")
}
// page
s.ListActivities(45255).Page(21).Do()
transport = s.client.httpClient.Transport.(*storeRequestTransport)
if transport.request.URL.RawQuery != "page=21" {
t.Error("page request incorrect")
}
}
func TestClubsBadJSON(t *testing.T) {
var err error
s := NewClubsService(NewStubResponseClient("bad json"))
_, err = s.Get(123).Do()
if err == nil {
t.Error("should return a bad json error")
}
_, err = s.ListMembers(123).Do()
if err == nil {
t.Error("should return a bad json error")
}
_, err = s.ListActivities(123).Do()
if err == nil {
t.Error("should return a bad json error")
}
}