-
Notifications
You must be signed in to change notification settings - Fork 1
/
client_test.go
145 lines (116 loc) · 3.2 KB
/
client_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
145
package tvdb_test
import (
"testing"
"github.com/danesparza/tvdb"
)
func TestTVDB_Login_ReturnsToken(t *testing.T) {
// Arrange
request := tvdb.AuthRequest{}
// Act
client := tvdb.Client{}
response, err := client.Login(request)
// Assert
if err != nil {
t.Errorf("Error logging in: %v", err)
}
if response.Token == "" {
t.Errorf("The token is blank, and shouldn't be")
} else {
t.Logf("Got a token back: %v", response.Token)
}
}
func TestTVDB_SeriesSearch_ReturnsInformation(t *testing.T) {
// Arrange
request := tvdb.SeriesSearchRequest{
Name: "Looney Tunes"}
// Act
client := tvdb.Client{}
responses, err := client.SeriesSearch(request)
// Assert
if err != nil {
t.Errorf("Error getting search results: %v", err)
}
if len(responses) == 0 {
t.Errorf("There are no matches")
}
if responses[0].ID != 72514 {
t.Errorf("Didn't get the series ID back that we expected")
}
// Loop through the responses:
for _, response := range responses {
t.Logf("Series name: %v", response.SeriesName)
}
}
func TestTVDB_EpisodesForSeries_ReturnsInformation(t *testing.T) {
// Arrange
request := tvdb.SeriesEpisodesRequest{
SeriesID: 72514}
// Act
client := tvdb.Client{}
response, err := client.EpisodesForSeries(request)
// Assert
if err != nil {
t.Errorf("Error getting search results: %v", err)
}
if len(response) == 0 {
t.Errorf("There are no responses")
} else {
t.Logf("Got %v episodes back", len(response))
}
if response[0].ID != 5657563 {
t.Errorf("Didn't get the episode ID back that we expected")
}
}
func TestTVDB_EpisodesForSeries_ReturnsExpectedCount(t *testing.T) {
// Arrange
request := tvdb.SeriesEpisodesRequest{
SeriesID: 78874}
// Act
client := tvdb.Client{}
response, err := client.EpisodesForSeries(request)
// Assert
if err != nil {
t.Errorf("Error getting search results: %v", err)
}
if len(response) != 18 {
t.Errorf("18 episodes expected, but got %v instead", len(response))
} else {
t.Logf("Got %v episodes back", len(response))
}
if response[0].ID != 297989 {
t.Errorf("Didn't get the episode ID back that we expected, but got %v instead", response[0].ID)
}
}
func TestTVDB_EpisodesForSeries_CanMap(t *testing.T) {
// Arrange
request := tvdb.SeriesEpisodesRequest{
SeriesID: 72514}
// Act
client := tvdb.Client{}
response, err := client.EpisodesForSeries(request)
// Assert
if err != nil {
t.Errorf("Error getting search results: %v", err)
}
if len(response) == 0 {
t.Errorf("Didn't get any episodes")
} else {
t.Logf("Got %v episodes back", len(response))
}
// Load up the map
episodes := make(map[string]tvdb.BasicEpisode)
for _, episode := range response {
episodes[episode.EpisodeName] = episode
}
t.Logf("Created a map with %v items in it", len(episodes))
// Check to see if the episode name exists
// and then get its season/episode number:
episodeToFind := "Upswept Hare"
if episode, ok := episodes[episodeToFind]; ok {
if episode.AiredSeason != 1953 || episode.AiredEpisodeNumber != 7 {
t.Errorf("The episode and season don't match what we expect. Expected s1953e7 - Found: s%ve%v", episode.AiredSeason, episode.AiredEpisodeNumber)
}
} else {
t.Errorf("Didn't find the episode '%v'", episodeToFind)
}
}