-
Notifications
You must be signed in to change notification settings - Fork 295
/
show_test.go
84 lines (73 loc) · 1.8 KB
/
show_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
package spotify
import (
"bytes"
"context"
"net/http"
"testing"
)
func TestGetShow(t *testing.T) {
c, s := testClientFile(http.StatusOK, "test_data/get_show.txt")
defer s.Close()
r, err := c.GetShow(context.Background(), "1234")
if err != nil {
t.Fatal(err)
}
if r.SimpleShow.Name != "Uncommon Core" {
t.Error("Invalid data:", r.Name)
}
if len(r.Episodes.Episodes) != 25 {
t.Error("Invalid data", len(r.Episodes.Episodes))
}
}
func TestGetShowEpisodes(t *testing.T) {
c, s := testClientFile(http.StatusOK, "test_data/get_show_episodes.txt")
defer s.Close()
r, err := c.GetShowEpisodes(context.Background(), "1234")
if err != nil {
t.Fatal(err)
}
if r.Total != 25 {
t.Error("Invalid data:", r.Total)
}
if r.Offset != 0 {
t.Error("Invalid data:", r.Offset)
}
if len(r.Episodes) != 25 {
t.Error("Invalid data", len(r.Episodes))
}
}
func TestSaveShowsForCurrentUser(t *testing.T) {
c, s := testClient(http.StatusOK, new(bytes.Buffer), func(req *http.Request) {
if ids := req.URL.Query().Get("ids"); ids != "1,2" {
t.Error("Invalid data:", ids)
}
})
defer s.Close()
err := c.SaveShowsForCurrentUser(context.Background(), []ID{"1", "2"})
if err != nil {
t.Fatal(err)
}
}
func TestSaveShowsForCurrentUser_Errors(t *testing.T) {
c, s := testClient(http.StatusInternalServerError, new(bytes.Buffer))
defer s.Close()
err := c.SaveShowsForCurrentUser(context.Background(), []ID{"1"})
if err == nil {
t.Fatal(err)
}
}
func TestGetEpisode(t *testing.T) {
c, s := testClientFile(http.StatusOK, "test_data/get_episode.txt")
defer s.Close()
id := "2DSKnz9Hqm1tKimcXqcMJD"
r, err := c.GetEpisode(context.Background(), id)
if err != nil {
t.Fatal(err)
}
if r.ID.String() != id {
t.Error("Invalid data:", r.ID)
}
if r.Type != "episode" {
t.Error("Invalid data:", r.ID)
}
}