-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblocks_test.go
94 lines (79 loc) · 2.96 KB
/
blocks_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
package twch
import (
"fmt"
"net/http"
"reflect"
"testing"
)
func TestListBlocks(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/users/test_user1/blocks", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{ "_links": { "next": "https://api.twitch.tv/kraken/users/test_user1/test_user1?limit=25&offset=25", "self": "https://api.twitch.tv/kraken/users/test_user1/test_user1?limit=25&offset=0" }, "blocks": [ { "_links": { "self": "s" }, "updated_at": "2013-02-07T01:04:43Z", "user": { "_links": { "self": "s" }, "updated_at": "2013-02-06T22:44:19Z", "display_name": "d", "staff": false, "name": "n", "_id": 1, "logo": "l", "created_at": "2010-06-30T08:26:49Z" }, "_id": 1 } ] }`)
})
want := []Block{
Block{
ID: intPtr(1),
UpdatedAt: stringPtr("2013-02-07T01:04:43Z"),
User: &User{
ID: intPtr(1),
DisplayName: stringPtr("d"),
Name: stringPtr("n"),
Logo: stringPtr("l"),
Staff: boolPtr(false),
CreatedAt: stringPtr("2010-06-30T08:26:49Z"),
UpdatedAt: stringPtr("2013-02-06T22:44:19Z"),
},
},
}
opts := &ListOptions{Limit: 25, Offset: 0}
got, resp, err := client.Blocks.ListBlocks("test_user1", opts)
if err != nil {
t.Errorf("Blocks.ListBlocks: returned an error: %+v\n", err)
}
testListResponse(t, resp, nil, intPtr(25), nil)
if !reflect.DeepEqual(got, want) {
t.Errorf("Block.ListBlocks: result did not match expecation\nwant: %+v\n got: %+v", want, got)
}
}
func TestAddBlock(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/users/test_user1/blocks/test_user2", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
fmt.Fprint(w, `{ "_links": { "self": "h" }, "updated_at": "2013-02-07T01:04:43Z", "user": { "_links": { "self": "h" }, "updated_at": "2013-01-18T22:33:55Z", "logo": "l", "staff": false, "display_name": "d", "name": "n", "_id": 1, "created_at": "2011-05-01T14:50:12Z" }, "_id": 1 }`)
})
want := &Block{
ID: intPtr(1),
UpdatedAt: stringPtr("2013-02-07T01:04:43Z"),
User: &User{
ID: intPtr(1),
DisplayName: stringPtr("d"),
Name: stringPtr("n"),
Logo: stringPtr("l"),
Staff: boolPtr(false),
CreatedAt: stringPtr("2011-05-01T14:50:12Z"),
UpdatedAt: stringPtr("2013-01-18T22:33:55Z"),
},
}
got, _, err := client.Blocks.AddBlock("test_user1", "test_user2")
if err != nil {
t.Errorf("Blocks.AddBlock: returned error %+v", err)
}
if !reflect.DeepEqual(got, want) {
t.Errorf("Block.AddBlocks: result did not match expecation\nwant: %+v\n got: %+v", want, got)
}
}
func TestRemoveBlock(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/users/test_user1/blocks/test_user2", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
w.WriteHeader(http.StatusNoContent)
})
err := client.Blocks.RemoveBlock("test_user1", "test_user2")
if err != nil {
t.Errorf("Blocks.RemoveBlock: returned error %+v", err)
}
}