forked from strava/go.strava
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kudos_test.go
115 lines (87 loc) · 3.15 KB
/
kudos_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
package strava
import (
"testing"
)
func TestActivitiesKudosList(t *testing.T) {
client := newCassetteClient(testToken, "activity_kudos_list")
athletes, err := NewActivityKudosService(client, 103221154).List().Do()
if err != nil {
t.Fatalf("service error: %v", err)
}
if len(athletes) == 0 {
t.Fatal("kudoers not parsed")
}
if athletes[0].CreatedAt.IsZero() || athletes[0].UpdatedAt.IsZero() {
t.Error("athlete dates not parsed")
}
// from here on out just check the request parameters
s := NewActivityKudosService(newStoreRequestClient(), 123)
// path
s.List().Do()
transport := s.client.httpClient.Transport.(*storeRequestTransport)
if transport.request.URL.Path != "/api/v3/activities/123/kudos" {
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)
}
// parameters
s.List().Page(2).PerPage(3).Do()
transport = s.client.httpClient.Transport.(*storeRequestTransport)
if transport.request.URL.Path != "/api/v3/activities/123/kudos" {
t.Errorf("request path incorrect, got %v", transport.request.URL.Path)
}
if transport.request.URL.RawQuery != "page=2&per_page=3" {
t.Errorf("request query incorrect, got %v", transport.request.URL.RawQuery)
}
}
func TestActivityKudosCreate(t *testing.T) {
client := newCassetteClient(testToken, "activity_kudos_post")
err := NewActivityKudosService(client, 118229063).Create().Do()
if err != nil {
t.Fatalf("service error: %v", err)
}
// from here on out just check the request parameters
s := NewActivityKudosService(newStoreRequestClient(), 123)
// path
s.Create().Do()
transport := s.client.httpClient.Transport.(*storeRequestTransport)
if transport.request.URL.Path != "/api/v3/activities/123/kudos" {
t.Errorf("request path incorrect, got %v", transport.request.URL.Path)
}
if transport.request.Method != "POST" {
t.Errorf("request method incorrect, got %v", transport.request.Method)
}
if transport.request.URL.RawQuery != "" {
t.Errorf("request query incorrect, got %v", transport.request.URL.RawQuery)
}
}
func TestActivityKudosDelete(t *testing.T) {
client := newCassetteClient(testToken, "activity_kudos_delete")
err := NewActivityKudosService(client, 118229063).Delete().Do()
if err != nil {
t.Fatalf("service error: %v", err)
}
// from here on out just check the request parameters
s := NewActivityKudosService(newStoreRequestClient(), 123)
// path
s.Delete().Do()
transport := s.client.httpClient.Transport.(*storeRequestTransport)
if transport.request.URL.Path != "/api/v3/activities/123/kudos" {
t.Errorf("request path incorrect, got %v", transport.request.URL.Path)
}
if transport.request.Method != "DELETE" {
t.Errorf("request method incorrect, got %v", transport.request.Method)
}
if transport.request.URL.RawQuery != "" {
t.Errorf("request query incorrect, got %v", transport.request.URL.RawQuery)
}
}
func TestActivityKudosBadJSON(t *testing.T) {
var err error
s := NewActivityKudosService(NewStubResponseClient("bad json"), 123)
_, err = s.List().Do()
if err == nil {
t.Error("should return a bad json error")
}
}