-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusers_test.go
144 lines (129 loc) · 5.3 KB
/
users_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
140
141
142
143
144
package twch
import (
"fmt"
"net/http"
"reflect"
"testing"
)
func TestGetUser(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/users/test_user", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{ "type": "t", "name": "n", "created_at": "2011-03-19T15:42:22Z", "updated_at": "2012-06-14T00:14:27Z", "logo": "l", "_id": 1, "display_name": "d", "bio": "b" }`)
})
want := &User{
ID: intPtr(1),
Type: stringPtr("t"),
Name: stringPtr("n"),
Logo: stringPtr("l"),
DisplayName: stringPtr("d"),
Bio: stringPtr("b"),
CreatedAt: stringPtr("2011-03-19T15:42:22Z"),
UpdatedAt: stringPtr("2012-06-14T00:14:27Z"),
}
got, _, err := client.Users.GetUser("test_user")
if err != nil {
t.Errorf("Users.GetUser: request returned error %+v", err)
}
if !reflect.DeepEqual(got, want) {
t.Errorf("Users.GetUser response did not match:\nwant: %+v\ngot: %+v", want, got)
}
}
func TestGetCurrentUser(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/user", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{ "type": "t", "name": "n", "created_at": "2011-06-03T17:49:19Z", "updated_at": "2012-06-18T17:19:57Z", "logo": "l", "_id": 1, "display_name": "d", "email": "e", "partnered": true, "bio": "b" }`)
})
want := &User{
ID: intPtr(1),
Type: stringPtr("t"),
Name: stringPtr("n"),
Logo: stringPtr("l"),
DisplayName: stringPtr("d"),
Bio: stringPtr("b"),
Email: stringPtr("e"),
Partnered: boolPtr(true),
CreatedAt: stringPtr("2011-06-03T17:49:19Z"),
UpdatedAt: stringPtr("2012-06-18T17:19:57Z"),
}
got, _, err := client.Users.GetCurrentUser()
if err != nil {
t.Errorf("Users.GetCurrentUser: request returned error %+v", err)
}
if !reflect.DeepEqual(got, want) {
t.Errorf("Users.GetCurrentUser response did not match:\nwant: %+v\ngot: %+v", want, got)
}
}
func TestListFollowedStreams(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/streams/followed", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testParams(t, r, params{
"limit": "1",
"offset": "1",
"hls": "true",
})
fmt.Fprint(w, `{ "_total": 1, "streams": [ { "_id": 1, "preview": { "medium": "m", "small": "s", "large": "l", "template": "t" }, "game": "g", "channel": { "mature": null, "background": "b", "updated_at": "2013-02-15T15:22:24Z", "_id": 1, "status": "s", "logo": "l", "teams": [], "url": "u", "display_name": "d", "game": "g", "banner": "b", "name": "n", "delay": 0, "video_banner": null, "_links": { "chat": "c", "subscriptions": "s", "features": "f", "commercial": "c", "stream_key": "s", "editors": "e", "videos": "v", "self": "s", "follows": "f" }, "created_at": "2011-12-23T18:03:44Z" }, "viewers": 1, "created_at": "2014-09-12T02:03:17Z", "_links": { "self": "h" } } ], "_links": { "summary": "h", "followed": "h", "next": "https://api.twitch.tv/kraken/streams?channel=zisss%2Cvoyboy&game=Diablo+III&limit=100&offset=100", "featured": "f", "self": "https://api.twitch.tv/kraken/streams?channel=zisss%2Cvoyboy&game=Diablo+III&limit=100&offset=0" } }`)
})
opts := &RequestOptions{HLS: true, ListOptions: ListOptions{Limit: 1, Offset: 1}}
got, resp, err := client.Users.ListFollowedStreams(opts)
if err != nil {
t.Errorf("Users.ListFollowedStreams: returned error: %v", err)
}
testListResponse(t, resp, intPtr(1), intPtr(100), nil)
want := []Stream{
Stream{
ID: intPtr(1),
Viewers: intPtr(1),
CreatedAt: stringPtr("2014-09-12T02:03:17Z"),
Preview: assetPtr(),
Channel: channelPtr(),
Game: stringPtr("g"),
},
}
if !reflect.DeepEqual(got, want) {
t.Errorf("Users.ListFollowedStreams response did not match:\nwant: %+v\ngot: %+v", want, got)
}
}
func TestListFollowedVideos(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/videos/followed", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testParams(t, r, params{
"limit": "1",
"offset": "1",
})
fmt.Fprint(w, `{ "_links": { "next": "https://api.twitch.tv/kraken/videos/top?game=League+of+Legends&limit=10&offset=10&period=month", "self": "https://api.twitch.tv/kraken/videos/top?game=League+of+Legends&limit=10&offset=0&period=month" }, "videos": [ { "recorded_at": "2013-03-13T09:51:31Z", "preview": "p", "description": "d", "url": "u", "title": "t", "channel": { "name": "n", "display_name": "d" }, "length": 1, "game": "g", "views": 1, "_id": "i", "_links": { "channel": "c", "self": "s" } } ] }`)
})
opts := &ListOptions{Limit: 1, Offset: 1}
got, resp, err := client.Users.ListFollowedVideos(opts)
if err != nil {
t.Errorf("Users.ListFollowedVideos: returned error: %v", err)
}
testListResponse(t, resp, nil, intPtr(10), nil)
want := []Video{
Video{
ID: stringPtr("i"),
Preview: stringPtr("p"),
Description: stringPtr("d"),
URL: stringPtr("u"),
Title: stringPtr("t"),
Game: stringPtr("g"),
Views: intPtr(1),
Length: intPtr(1),
RecordedAt: stringPtr("2013-03-13T09:51:31Z"),
Channel: &Channel{
Name: stringPtr("n"),
DisplayName: stringPtr("d"),
},
},
}
if !reflect.DeepEqual(got, want) {
t.Errorf("Users.ListFollowedVideos response did not match:\nwant: %+v\ngot: %+v", want, got)
}
}