forked from credondocr/dota2api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintegration_test.go
388 lines (377 loc) · 13.6 KB
/
integration_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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
// +build integration
package dota2api
import (
"fmt"
. "github.com/franela/goblin"
"testing"
"time"
)
//These tests make sure that the API returns data in the format the code can parse
func TestDota2_GetPlayerSummaries_Integration(t *testing.T) {
g := Goblin(t)
api, _ := LoadConfigFromFile("config.yaml")
g.Describe("api.GetPlayerSummaries Integration Test", func() {
steamId0 := NewSteamIdFrom64(76561198054320440)
steamId1 := NewSteamIdFrom64(76561198048536965)
sum, err := api.GetPlayerSummaries(ParameterSteamIds(steamId0, steamId1))
g.It("Should return summaries from the correct players", func() {
g.Assert(err).IsNil()
if sum[0].SteamId == steamId0 {
g.Assert(sum[0].SteamId).Equal(steamId0)
g.Assert(sum[1].SteamId).Equal(steamId1)
} else {
g.Assert(sum[0].SteamId).Equal(steamId1)
g.Assert(sum[1].SteamId).Equal(steamId0)
}
})
})
}
func TestDota2_GetFriendList_Integration(t *testing.T) {
g := Goblin(t)
api, _ := LoadConfigFromFile("config.yaml")
g.Describe("api.GetFriendList Integration Test", func() {
friendList, err := api.GetFriendList(ParameterSteamId(NewSteamIdFrom64(76561198392783738)))
g.It("Should not error", func() {
g.Assert(err).IsNil()
})
g.It("Should return non empty friends", func() {
g.Assert(friendList.Count() > 0).IsTrue()
friendList.ForEach(func(friend Friend) {
id, err := friend.SteamId.SteamId64()
g.Assert(err).IsNil()
g.Assert(id != 0).IsTrue()
g.Assert(friend.RelationShip != "").IsTrue()
g.Assert(friend.FriendsSince.Equal(time.Time{})).IsFalse()
})
})
})
}
func TestDota2_GetHeroes_Integration(t *testing.T) {
g := Goblin(t)
api, _ := LoadConfigFromFile("config.yaml")
g.Describe("api.GetHeroes Integration Test", func() {
heroes, err := api.GetHeroes()
g.It("Should not error", func() {
g.Assert(err).IsNil()
})
g.It("Should return non empty heroes", func() {
g.Assert(heroes.Count() > 0).IsTrue()
heroes.ForEach(func(hero Hero) {
g.Assert(hero.Name.GetName() != "").IsTrue()
g.Assert(hero.Name.GetFullName() != "").IsTrue()
g.Assert(hero.Id != 0).IsTrue()
})
})
})
}
func TestDota2_GetItems_Integration(t *testing.T) {
g := Goblin(t)
api, _ := LoadConfigFromFile("config.yaml")
g.Describe("api.GetItems Integration Test", func() {
items, err := api.GetItems()
g.It("Should not error", func() {
g.Assert(err).IsNil()
})
g.It("Should return non empty items", func() {
g.Assert(items.Count() > 0).IsTrue()
items.ForEach(func(item Item) {
g.Assert(item.Name.GetName() != "").IsTrue()
g.Assert(item.Name.GetFullName() != "").IsTrue()
g.Assert(item.Id != 0).IsTrue()
})
})
})
}
func TestDota2_GetLiveLeagueGames_Integration(t *testing.T) {
g := Goblin(t)
api, _ := LoadConfigFromFile("config.yaml")
g.Describe("api.GetLiveLeagueGames Integration Test", func() {
games, err := api.GetLiveLeagueGames()
g.It("Should not error", func() {
g.Assert(err).IsNil()
})
g.It("Should return non empty games", func() {
g.Assert(games.Count() > 0).IsTrue()
games.ForEachGame(func(game LiveGame) {
g.Assert(game.ScoreBoard).IsNotZero()
})
})
})
}
func TestDota2_GetMatchDetails_Integration(t *testing.T) {
g := Goblin(t)
api, _ := LoadConfigFromFile("config.yaml")
g.Describe("api.GetHeroes Integration Test", func() {
details, err := api.GetMatchDetails(MatchId(5548608983))
g.It("Should not error", func() {
g.Assert(err).IsNil()
})
g.Describe("Should return the correct game", func() {
g.It("Should return the correct match ID and SeqNum", func() {
g.Assert(details.MatchID).Equal(int64(5548608983))
g.Assert(details.MatchSeqNum == 4655597189).IsTrue()
})
g.It("Should return a HumanPlayers, 5 players in each team", func() {
g.Assert(details.HumanPlayers).Equal(10)
g.Assert(details.Radiant.Count()).Equal(5)
g.Assert(details.Dire.Count()).Equal(5)
details.ForEachPlayer(func(p PlayerDetails) {
g.Assert(p.LeaverStatus).Equal(LeaverStatusNone)
})
})
g.It("Should return Source2 as engine", func() {
g.Assert(details.Engine).Equal(Source2)
})
g.Xit("Should return Ranked Matchmaking as GameMode", func() {
g.Assert(details.GameMode).Equal(GameModeRankedMatchmaking)
g.Assert(details.GameMode.GetString()).Equal("Ranked Matchmaking")
})
g.Xit("Should return ranked Matchmaking as LobbyType", func() {
g.Assert(details.LobbyType).Equal(LobbyRankedMatchmaking)
g.Assert(details.LobbyType.GetName()).Equal("Ranked Matchmaking")
})
g.It("Should return 19-36 as score", func() {
g.Assert(details.Score.RadiantScore).Equal(19)
g.Assert(details.Score.DireScore).Equal(36)
})
g.It("Should return Dire as winner", func() {
g.Assert(details.Victory.DireWon()).IsTrue()
g.Assert(details.Victory.RadiantWon()).IsFalse()
g.Assert(details.Victory.GetWinningTeam()).Equal(Dire)
})
g.It("Should return correct time stamps", func() {
g.Assert(details.Duration).Equal(2552 * time.Second)
g.Assert(details.FirstBloodTime).Equal(18 * time.Second)
g.Assert(details.StartTime.Equal(time.Unix(1596363511, 0))).IsTrue()
g.Assert(details.PreGameDuration).Equal(90 * time.Second)
})
g.It("Should return correct BuildingState", func() {
g.Assert(details.BuildingsState).Equal(BuildingsState{
Dire: TeamBuildingsState{
Top: LaneBuildingsState{
T1Tower: false,
T2Tower: true,
T3Tower: true,
MeleeBarrack: true,
RangedBarrack: true,
},
Mid: LaneBuildingsState{
T1Tower: false,
T2Tower: true,
T3Tower: true,
MeleeBarrack: true,
RangedBarrack: true,
},
Bot: LaneBuildingsState{
T1Tower: false,
T2Tower: true,
T3Tower: true,
MeleeBarrack: true,
RangedBarrack: true,
},
T4TowerBot: true,
T4TowerTop: true,
},
Radiant: TeamBuildingsState{
Top: LaneBuildingsState{
T1Tower: false,
T2Tower: true,
T3Tower: true,
MeleeBarrack: true,
RangedBarrack: true,
},
Mid: LaneBuildingsState{
T1Tower: false,
T2Tower: false,
T3Tower: false,
MeleeBarrack: false,
RangedBarrack: false,
},
Bot: LaneBuildingsState{
T1Tower: false,
T2Tower: false,
T3Tower: true,
MeleeBarrack: true,
RangedBarrack: true,
},
T4TowerBot: false,
T4TowerTop: false,
},
})
})
g.It("Should return correct time stamps", func() {
g.Assert(details.Duration).Equal(2552 * time.Second)
g.Assert(details.FirstBloodTime).Equal(18 * time.Second)
g.Assert(details.StartTime.Equal(time.Unix(1596363511, 0))).IsTrue()
g.Assert(details.PreGameDuration).Equal(90 * time.Second)
})
g.It("Should return correct Picks and Bans", func() {
bansHeroesIds := []int{46, 105, 104, 41, 23, 82, 32}
bansTeams := []Victory{RadiantVictory, RadiantVictory, RadiantVictory, RadiantVictory, RadiantVictory, DireVictory, DireVictory}
p, f := details.PicksBans.GetPick(0)
g.Assert(f).IsTrue()
g.Assert(p.IsPick()).IsTrue()
p, f = details.PicksBans.GetPick(7)
g.Assert(f).IsTrue()
g.Assert(p.IsPick()).IsTrue()
g.Assert(p.IsRadiant()).IsTrue()
_, f = details.PicksBans.GetPick(17)
g.Assert(f).IsFalse()
for i, ban := range details.PicksBans.GetByPickType(Ban) {
g.Assert(ban.IsBan()).IsTrue()
g.Assert(ban.Hero.Id).Equal(bansHeroesIds[i])
g.Assert(ban.Order).Equal(10 + i)
g.Assert(ban.GetTeam() == int(bansTeams[i])).IsTrue()
}
picksHeroesIds := []int{35, 26, 50, 99, 75, 7, 47, 42, 11, 44}
picksIsDire := []bool{true, false, true, false, false, true, true, false, false, true}
for i, pick := range details.PicksBans.GetByPickType(Pick) {
g.Assert(pick.GetType()).Equal(Pick)
g.Assert(pick.Hero.Id).Equal(picksHeroesIds[i])
g.Assert(pick.Order).Equal(i)
g.Assert(pick.IsDire()).Equal(picksIsDire[i])
}
for _, pick := range details.PicksBans {
p, f := details.PicksBans.GetPickByHero(pick.Hero)
g.Assert(f).IsTrue()
g.Assert(p.Hero).Equal(pick.Hero)
}
for _, pick := range details.PicksBans.GetByTeam(Dire) {
g.Assert(pick.IsDire()).IsTrue()
}
})
g.Xit("Should return the correct stats for player 0", func() {
g.Assert(details.Radiant[0].Stats.Gold.Spent() == 9490).IsTrue()
g.Assert(details.Radiant[0].Stats.Gold.Spent().Raw() == 9490).IsTrue()
g.Assert(details.Radiant[0].Stats.Gold.Spent().ToString()).Equal("9.5k")
g.Assert(details.Radiant[0].Stats.Gold.Current() == 1250).IsTrue()
g.Assert(details.Radiant[0].Stats.Gold.NetWorth() == 10740).IsTrue()
g.Assert(details.Radiant[0].Stats.HeroDamage.Raw() == 23281).IsTrue()
g.Assert(details.Radiant[0].Stats.HeroDamage.Scaled() == 15776).IsTrue()
g.Assert(details.Radiant[0].Stats.TowerDamage.Raw() == 270).IsTrue()
g.Assert(details.Radiant[0].Stats.TowerDamage.Scaled() == 79).IsTrue()
g.Assert(details.Radiant[0].Stats.HeroHealing.Raw() == 0).IsTrue()
g.Assert(details.Radiant[0].Stats.HeroHealing.Scaled() == 0).IsTrue()
g.Assert(details.Radiant[0].Stats.Gold.Current().ToString()).Equal("1.3k")
g.Assert(details.Radiant[1].Stats.Gold.Current().ToString()).Equal("331")
})
g.Xit("Should return working stats", func() {
details.ForEachPlayer(func(p PlayerDetails) {
g.Assert(p.Stats.Gold.NetWorth()).Equal(p.Stats.Gold.Current() + p.Stats.Gold.Spent())
g.Assert(p.Stats.HeroDamage.ScalingFactor()).Equal(float64(p.Stats.HeroDamage.Scaled()) / float64(p.Stats.HeroDamage.Raw()))
g.Assert(p.Stats.TowerDamage.ScalingFactor()).Equal(float64(p.Stats.TowerDamage.Scaled()) / float64(p.Stats.TowerDamage.Raw()))
g.Assert(p.Stats.HeroHealing.ScalingFactor()).Equal(float64(p.Stats.HeroHealing.Scaled()) / float64(p.Stats.HeroHealing.Raw()))
})
})
g.It("Should return the correct items for player 0", func() {
g.Assert(details.Radiant[0].Items.Item0.Id == 63).IsTrue()
g.Assert(details.Radiant[0].Items.Item1.Id == 77).IsTrue()
g.Assert(details.Radiant[0].Items.Item2.Id == 236).IsTrue()
g.Assert(details.Radiant[0].Items.Item3.Id == 77).IsTrue()
g.Assert(details.Radiant[0].Items.Item4.Id == 485).IsTrue()
g.Assert(details.Radiant[0].Items.Item5.Id == 7).IsTrue()
g.Assert(details.Radiant[0].Items.BackpackItem0.Id == 0).IsTrue()
g.Assert(details.Radiant[0].Items.BackpackItem1.Id == 0).IsTrue()
g.Assert(details.Radiant[0].Items.BackpackItem2.Id == 0).IsTrue()
g.Assert(details.Radiant[0].Items.ItemNeutral.Id == 357).IsTrue()
})
g.Xit("Should return the correct AbilityBuild for player 0", func() {
g.Assert(details.Radiant[0].AbilityUpgrades.Count()).Equal(18)
aU, f := details.Radiant[0].AbilityUpgrades.GetByOrder(4)
g.Assert(f).IsTrue()
g.Assert(aU.Ability).Equal(5378)
g.Assert(aU.Level).Equal(5)
g.Assert(aU.Time).Equal(714 * time.Second)
_, f = details.Radiant[0].AbilityUpgrades.GetByOrder(18)
g.Assert(f).IsFalse()
aU, f = details.Radiant[0].AbilityUpgrades.GetByLevel(10)
g.Assert(f).IsTrue()
g.Assert(aU.Ability).Equal(5906)
g.Assert(aU.Level).Equal(10)
g.Assert(aU.Time).Equal(1343 * time.Second)
_, f = details.Radiant[0].AbilityUpgrades.GetByLevel(19)
g.Assert(f).IsFalse()
aUs := details.Radiant[0].AbilityUpgrades.GetByAbility(5378)
g.Assert(aUs.Count()).Equal(4)
for _, aU := range aUs {
g.Assert(aU.Ability).Equal(5378)
}
})
g.It("Should return working Abilities", func() {
details.Dire.ForEach(func(p PlayerDetails) {
for i, a := range p.AbilityUpgrades {
for _, aU := range p.AbilityUpgrades.GetByAbility(a.Ability) {
if aU.Ability == a.Ability {
goto success
}
}
g.Fail(fmt.Sprintf("missing required ability %d", a.Ability))
success:
aU, f := p.AbilityUpgrades.GetByOrder(i)
g.Assert(f).IsTrue()
g.Assert(aU).Equal(a)
aU, f = p.AbilityUpgrades.GetByLevel(a.Level)
g.Assert(f).IsTrue()
g.Assert(aU).Equal(a)
}
})
})
})
})
}
func TestDota2_GetMatchHistory_Integration(t *testing.T) {
g := Goblin(t)
api, _ := LoadConfigFromFile("config.yaml")
g.Describe("api.GetMatchHistory Integration Test", func() {
g.Describe("Basic", func() {
c := NewCursor()
games, err := api.GetMatchHistory(c)
g.It("Should not error", func() {
g.Assert(err).IsNil()
})
g.It("Should return games", func() {
g.Assert(games.Count() > 0).IsTrue()
})
g.It("Should modify the cursor", func() {
g.Assert(c.GetLastReceivedMatch() == games[games.Count()-1].MatchId).IsTrue()
})
})
g.Describe("Settings", func() {
c := NewCursor()
c.c.begin = 5572552442
oldId := c.GetLastReceivedMatch()
games, err := api.GetMatchHistory(c, HeroId(74), AccountId(107353159), MatchesRequested(3))
g.It("Should not error", func() {
g.Assert(err).IsNil()
})
g.It("Should return games", func() {
g.Assert(games.Count()).Equal(3)
})
g.It("Should modify the cursor", func() {
g.Assert(c.GetLastReceivedMatch() == games[games.Count()-1].MatchId).IsTrue()
})
g.It("Should take the cursor into account", func() {
for _, m := range games {
g.Assert(m.MatchId < oldId).IsTrue()
}
})
g.It("Should take Account Id parameter into account", func() {
for _, m := range games {
ok := false
m.ForEachPlayer(func(player Player) {
if player.AccountId == 107353159 {
ok = true
}
})
g.Assert(ok).IsTrue()
}
})
g.It("Should take Hero Id parameter into account", func() {
for _, m := range games {
_, f := m.GetByHeroId(74)
g.Assert(f).IsTrue()
}
})
})
})
}