-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplatform_test.go
98 lines (73 loc) · 2.34 KB
/
platform_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
// Copyright (c) 2015, Sgt. Kabukiman | MIT licensed
package srapi
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestPlatforms(t *testing.T) {
countRequests = true
gameboy := "o232q83p"
Convey("Fetching platforms by valid IDs", t, func() {
platform, err := PlatformByID(gameboy)
So(err, ShouldBeNil)
So(platform.ID, ShouldEqual, gameboy)
So(platform.Name, ShouldEqual, "Game Boy")
So(platform.Links, ShouldNotBeEmpty)
})
Convey("Fetching platforms by invalid IDs", t, func() {
platform, err := PlatformByID("i_do_not_exist")
So(err, ShouldNotBeNil)
So(platform, ShouldBeNil)
})
Convey("Fetching multiple platforms", t, func() {
platforms, err := Platforms(nil, &Cursor{0, 1})
So(err, ShouldBeNil)
So(platforms.Pagination.Offset, ShouldEqual, 0)
So(platforms.Pagination.Max, ShouldEqual, 1)
num := 0
// read a few pages, 7 is arbitrary
platforms.Walk(func(p *Platform) bool {
So(p.ID, ShouldNotBeBlank)
num++
return num < 7
})
})
Convey("Fetching runs of a platform", t, func() {
platform, err := PlatformByID(gameboy)
So(err, ShouldBeNil)
runs, err := platform.Runs(nil, nil, NoEmbeds)
So(err, ShouldBeNil)
firstID := ""
Convey("first page of runs should be fine", func() {
So(runs.Data, ShouldNotBeEmpty)
So(runs.Pagination.Offset, ShouldEqual, 0)
firstID = runs.Data[0].ID
})
runs, err = platform.Runs(nil, &Sorting{Direction: Descending}, NoEmbeds)
So(err, ShouldBeNil)
Convey("sorting order should be taken into account", func() {
So(runs.Data, ShouldNotBeEmpty)
So(runs.Pagination.Offset, ShouldEqual, 0)
So(firstID, ShouldNotEqual, runs.Data[0].ID)
})
})
Convey("Fetching games of a platform", t, func() {
platform, err := PlatformByID(gameboy)
So(err, ShouldBeNil)
games, err := platform.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 = platform.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)
})
})
}