-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathseries_test.go
151 lines (115 loc) · 3.87 KB
/
series_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
146
147
148
149
150
151
// Copyright (c) 2015, Sgt. Kabukiman | MIT licensed
package srapi
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestSeries(t *testing.T) {
countRequests = true
gta := "9v7og6n0"
Convey("Fetching series by valid IDs", t, func() {
series, err := SeriesByID(gta, NoEmbeds)
So(err, ShouldBeNil)
So(series.ID, ShouldEqual, gta)
So(series.Names.International, ShouldEqual, "Grand Theft Auto")
So(series.Abbreviation, ShouldEqual, "gta")
So(series.Weblink, ShouldNotBeEmpty)
So(series.Links, ShouldNotBeEmpty)
So(series.ModeratorMap(), ShouldNotBeEmpty)
mods, err := series.Moderators()
So(err, ShouldBeNil)
So(mods, ShouldNotBeEmpty)
})
Convey("Fetching series by valid abbreviation", t, func() {
series, err := SeriesByAbbreviation("gta", NoEmbeds)
So(err, ShouldBeNil)
So(series.ID, ShouldEqual, gta)
So(series.Names.International, ShouldEqual, "Grand Theft Auto")
So(series.Abbreviation, ShouldEqual, "gta")
So(series.Weblink, ShouldNotBeEmpty)
So(series.Links, ShouldNotBeEmpty)
m := series.ModeratorMap()
So(m, ShouldNotBeEmpty)
for _, level := range m {
So(level, ShouldNotEqual, UnknownModLevel)
}
mods, err := series.Moderators()
So(err, ShouldBeNil)
So(mods, ShouldNotBeEmpty)
})
Convey("Fetching series by invalid IDs", t, func() {
series, err := SeriesByID("i_do_not_exist", NoEmbeds)
So(err, ShouldNotBeNil)
So(series, ShouldBeNil)
})
Convey("Fetching series by invalid abbrevitation", t, func() {
series, err := SeriesByAbbreviation("i_do_not_exist", NoEmbeds)
So(err, ShouldNotBeNil)
So(series, ShouldBeNil)
})
Convey("embed moderators in series", t, func() {
series, err := SeriesByID(gta, "moderators")
So(err, ShouldBeNil)
before := requestCount
m := series.ModeratorMap()
So(m, ShouldNotBeEmpty)
So(requestCount, ShouldEqual, before)
for _, level := range m {
So(level, ShouldEqual, UnknownModLevel)
}
mods, err := series.Moderators()
So(err, ShouldBeNil)
So(mods.Size(false), ShouldBeBetween, 3, 100)
So(mods.First().Names.International, ShouldNotBeEmpty)
})
Convey("Fetching multiple series", t, func() {
seriesList, err := ManySeries(nil, nil, &Cursor{0, 1}, NoEmbeds)
So(err, ShouldBeNil)
So(seriesList.Pagination.Offset, ShouldEqual, 0)
So(seriesList.Pagination.Max, ShouldEqual, 1)
num := 0
// read a few pages, 7 is arbitrary
seriesList.Walk(func(s *Series) bool {
So(s.ID, ShouldNotBeBlank)
num++
return num < 7
})
Convey("test the SeriesFilter", func() {
// check abbrevitation
filter := SeriesFilter{Abbreviation: "gta"}
seriesList, err := ManySeries(&filter, nil, nil, NoEmbeds)
So(err, ShouldBeNil)
So(seriesList.Data, ShouldHaveLength, 1)
// check name
filter = SeriesFilter{Name: "mario"}
cursor := Cursor{Max: 5}
seriesList, err = ManySeries(&filter, nil, &cursor, NoEmbeds)
So(err, ShouldBeNil)
So(seriesList.Data, ShouldHaveLength, 5)
// check moderator
filter = SeriesFilter{Moderator: "r5j52gjv"}
seriesList, err = ManySeries(&filter, nil, nil, NoEmbeds)
So(err, ShouldBeNil)
So(len(seriesList.Data), ShouldBeBetween, 2, 5) // Sorry Josh, but I don't assume it's gonna be more than 5 #Kappa
})
})
Convey("Fetching games of a series", t, func() {
series, err := SeriesByID(gta, NoEmbeds)
So(err, ShouldBeNil)
games, err := series.Games(nil, nil, NoEmbeds)
So(err, ShouldBeNil)
firstID := ""
Convey("first page of games should be fine", func() {
So(games.Data, ShouldNotBeEmpty)
So(games.Pagination.Offset, ShouldEqual, 0)
firstID = games.Data[0].ID
})
games, err = series.Games(nil, &Sorting{Direction: Descending}, NoEmbeds)
So(err, ShouldBeNil)
Convey("sorting order should be taken into account", func() {
So(games.Data, ShouldNotBeEmpty)
So(games.Pagination.Offset, ShouldEqual, 0)
So(firstID, ShouldNotEqual, games.Data[0].ID)
})
})
}