-
Notifications
You must be signed in to change notification settings - Fork 4
/
scraper_test.go
570 lines (486 loc) · 15 KB
/
scraper_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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
package godestone
import (
"fmt"
"testing"
"time"
"github.com/karashiiro/bingode"
"github.com/xivapi/godestone/v2/provider/models"
)
var langCodes = []SiteLang{EN, JA, FR, DE, "zh"}
var bin = bingode.New()
func failIfNil(t *testing.T, label string, input interface{}) {
if input == nil {
t.Errorf(fmt.Sprintf("%s is nil; expected non-nil object", label))
}
}
func failIfFalse(t *testing.T, label string, input bool) {
if !input {
t.Errorf(fmt.Sprintf("%s is false; expected true", label))
}
}
func failIfStringEmpty(t *testing.T, label string, input string) {
if input == "" {
t.Errorf(fmt.Sprintf("%s is empty; expected non-empty string", label))
}
}
func failIfNumberZero(t *testing.T, label string, input int64) {
if input == 0 {
t.Errorf(fmt.Sprintf("%s is zero; expected nonzero value", label))
}
}
func failIfOlderThanGameRelease(t *testing.T, label string, input time.Time) {
release, _ := time.Parse("2006-Jan-02", "2013-Aug-16") // Early access began on the 24th, but there are multiple timestamps for the 16th. Wikipedia probably left something out.
inputStr, _ := input.MarshalText()
if input.Before(release) {
t.Errorf(fmt.Sprintf("%s is older than the game's release date; got %s", label, string(inputStr)))
}
}
func failIfGCInvalid(t *testing.T, label string, input *models.NamedEntity) {
if input == nil || input.Name == "" {
var got string
if input == nil {
got = "nil"
} else {
got = input.Name
}
t.Errorf(fmt.Sprintf("%s is not a valid Grand Company; got %s", label, got))
}
}
var characterIds = []uint32{
11166211, // Achievements private
9426169, // No mounts/minions or achievements; missing most things
9575452, // Pretty filled-out character; Miqo'te (the apostrophe screwed things up at one point)
23345328, // Failing mount
}
func TestFetchCharacter(t *testing.T) {
t.Parallel()
for _, lang := range langCodes {
s := NewScraper(bin, lang)
t.Run("SiteLang: "+string(lang), func(t *testing.T) {
t.Parallel()
for _, id := range characterIds {
t.Run("Character ID "+fmt.Sprint(id), func(t *testing.T) {
c, err := s.FetchCharacter(id)
if err != nil {
if lang == SiteLang("zh") { // A-OK, there is no Chinese website
return
}
t.Errorf(err.Error())
return
}
failIfNil(t, "Character active ClassJob", c.ActiveClassJob)
for _, cj := range c.ClassJobs {
failIfNumberZero(t, "Character ClassJob ID for "+cj.Name, int64(cj.ClassID))
}
failIfStringEmpty(t, "Character avatar", c.Avatar)
failIfStringEmpty(t, "Character DC", c.DC)
failIfNumberZero(t, "Character gender", int64(c.Gender))
failIfStringEmpty(t, "Character deity", c.GuardianDeity.Name)
failIfStringEmpty(t, "Character deity icon", c.GuardianDeity.Icon)
failIfNumberZero(t, "Character ID", int64(c.ID))
failIfStringEmpty(t, "Character name", c.Name)
failIfStringEmpty(t, "Character nameday", c.Nameday)
failIfStringEmpty(t, "Character portrait", c.Portrait)
failIfStringEmpty(t, "Character race", c.Race.Name)
failIfStringEmpty(t, "Character town", c.Town.Name)
failIfStringEmpty(t, "Character town icon", c.Town.Icon)
failIfStringEmpty(t, "Character tribe", c.Tribe.Name)
failIfStringEmpty(t, "Character world", c.World)
})
}
})
}
}
func TestFetchCharacterAchievements(t *testing.T) {
t.Parallel()
for _, lang := range langCodes {
s := NewScraper(bin, lang)
t.Run("SiteLang: "+string(lang), func(t *testing.T) {
t.Parallel()
for _, id := range characterIds {
t.Run("Character ID "+fmt.Sprint(id), func(t *testing.T) {
achievements, aai, err := s.FetchCharacterAchievements(id)
if err != nil {
if lang == SiteLang("zh") {
return
}
t.Errorf(err.Error())
return
}
if aai.TotalAchievementPoints > 0 {
failIfNumberZero(t, "Total achievements", int64(aai.TotalAchievements))
failIfFalse(t, "Achievements private", !aai.Private)
}
if aai.TotalAchievements > 0 {
failIfNumberZero(t, "Total achievement points", int64(aai.TotalAchievementPoints))
failIfFalse(t, "Achievements private", !aai.Private)
}
for _, achievement := range achievements {
failIfNumberZero(t, "Achievement ID", int64(achievement.ID))
failIfStringEmpty(t, "Achievement name", achievement.Name)
failIfStringEmpty(t, "Achievement English name", achievement.NameEN)
failIfStringEmpty(t, "Achievement Japanese name", achievement.NameJA)
failIfStringEmpty(t, "Achievement German name", achievement.NameDE)
failIfStringEmpty(t, "Achievement French name", achievement.NameFR)
}
})
}
})
}
}
func TestFetchCharacterMinions(t *testing.T) {
t.Parallel()
for _, lang := range langCodes {
s := NewScraper(bin, lang)
t.Run("SiteLang: "+string(lang), func(t *testing.T) {
t.Parallel()
for _, id := range characterIds {
t.Run("Character ID "+fmt.Sprint(id), func(t *testing.T) {
minions, err := s.FetchCharacterMinions(id)
if err != nil {
if lang == SiteLang("zh") {
return
}
t.Errorf(err.Error())
return
}
for _, minion := range minions {
failIfNumberZero(t, "Minion ID", int64(minion.ID))
failIfStringEmpty(t, "Minion name", minion.Name)
failIfStringEmpty(t, "Minion icon", minion.Icon)
failIfStringEmpty(t, "Minion English name", minion.NameEN)
failIfStringEmpty(t, "Minion Japanese name", minion.NameJA)
failIfStringEmpty(t, "Minion German name", minion.NameDE)
failIfStringEmpty(t, "Minion French name", minion.NameFR)
}
})
}
})
}
}
func TestFetchCharacterMounts(t *testing.T) {
t.Parallel()
for _, lang := range langCodes {
s := NewScraper(bin, lang)
t.Run("SiteLang: "+string(lang), func(t *testing.T) {
t.Parallel()
for _, id := range characterIds {
t.Run("Character ID "+fmt.Sprint(id), func(t *testing.T) {
mounts, err := s.FetchCharacterMounts(id)
if err != nil {
if lang == SiteLang("zh") {
return
}
t.Errorf(err.Error())
return
}
for _, mount := range mounts {
failIfNumberZero(t, "Mount ID", int64(mount.ID))
failIfStringEmpty(t, "Mount name", mount.Name)
failIfStringEmpty(t, "Mount icon", mount.Icon)
failIfStringEmpty(t, "Mount English name", mount.NameEN)
failIfStringEmpty(t, "Mount Japanese name", mount.NameJA)
failIfStringEmpty(t, "Mount German name", mount.NameDE)
failIfStringEmpty(t, "Mount French name", mount.NameFR)
}
})
}
})
}
}
var linkshellIds = []string{"20547673299961415", "19703248369746483", "10414574138338845"}
func TestFetchLinkshell(t *testing.T) {
t.Parallel()
for _, lang := range langCodes {
s := NewScraper(bin, lang)
t.Run("SiteLang: "+string(lang), func(t *testing.T) {
t.Parallel()
for _, id := range linkshellIds {
t.Run("Linkshell ID "+id, func(t *testing.T) {
ls, err := s.FetchLinkshell(id)
if err != nil {
if lang == SiteLang("zh") {
return
}
t.Errorf(err.Error())
return
}
failIfStringEmpty(t, "Linkshell name", ls.Name)
failIfStringEmpty(t, "Linkshell ID", ls.ID)
if len(ls.Members) == 0 {
t.Errorf("Linkshell has no members")
}
for _, member := range ls.Members {
failIfStringEmpty(t, "Member avatar", member.Avatar)
failIfNumberZero(t, "Member ID", int64(member.ID))
failIfStringEmpty(t, "Member name", member.Name)
failIfStringEmpty(t, "Member world", member.World)
failIfStringEmpty(t, "Member DC", member.DC)
}
})
}
})
}
}
var cwlsIds = []string{
"4b8af89f50a062b4b15650ecf6583f7ac9ad8065",
"4e7baf2e534e3fcd13edf24f554ddeb8b9efa1b5",
"3b417d2c5390d9ebf62d35bd63f67fe26eb3d828",
}
func TestFetchCWLS(t *testing.T) {
t.Parallel()
for _, lang := range langCodes {
s := NewScraper(bin, lang)
t.Run("SiteLang: "+string(lang), func(t *testing.T) {
t.Parallel()
for _, id := range cwlsIds {
t.Run("CWLS ID "+id, func(t *testing.T) {
cwls, err := s.FetchCWLS(id)
if err != nil {
if lang == SiteLang("zh") {
return
}
t.Errorf(err.Error())
return
}
failIfStringEmpty(t, "CWLS name", cwls.Name)
failIfStringEmpty(t, "CWLS ID", cwls.ID)
failIfStringEmpty(t, "CWLS DC", cwls.DC)
if len(cwls.Members) == 0 {
t.Errorf("CWLS has no members")
}
for _, member := range cwls.Members {
failIfStringEmpty(t, "Member avatar", member.Avatar)
failIfNumberZero(t, "Member ID", int64(member.ID))
failIfStringEmpty(t, "Member name", member.Name)
failIfStringEmpty(t, "Member world", member.World)
failIfStringEmpty(t, "Member DC", member.DC)
}
})
}
})
}
}
var pvpTeamIds = []string{
"253c62269c624bc115902cea98e84fe082b79f85",
"a9b97f78cd9a59a6c71adb6d35ca8f902faf12d6",
"bbe7823327192ab12ad5b8215f5d07f1b8edabed",
}
func TestFetchPVPTeam(t *testing.T) {
t.Parallel()
for _, lang := range langCodes {
s := NewScraper(bin, lang)
t.Run("SiteLang: "+string(lang), func(t *testing.T) {
t.Parallel()
for _, id := range pvpTeamIds {
t.Run("PVP team ID "+id, func(t *testing.T) {
pvpTeam, err := s.FetchPVPTeam(id)
if err != nil {
if lang == SiteLang("zh") {
return
}
t.Errorf(err.Error())
return
}
failIfStringEmpty(t, "PVP team name", pvpTeam.Name)
failIfStringEmpty(t, "PVP team ID", pvpTeam.ID)
failIfStringEmpty(t, "PVP team DC", pvpTeam.DC)
failIfOlderThanGameRelease(t, "PVP team formation", pvpTeam.Formed)
if len(pvpTeam.Members) == 0 {
t.Errorf("PVP team has no members")
}
for _, member := range pvpTeam.Members {
failIfStringEmpty(t, "Member avatar", member.Avatar)
failIfNumberZero(t, "Member ID", int64(member.ID))
failIfStringEmpty(t, "Member name", member.Name)
failIfStringEmpty(t, "Member world", member.World)
failIfStringEmpty(t, "Member DC", member.DC)
}
})
}
})
}
}
var fcIds = []string{
"9231816286156096656",
"9230268173784187532",
"9232660711086230486",
}
func TestFetchFreeCompany(t *testing.T) {
t.Parallel()
for _, lang := range langCodes {
s := NewScraper(bin, lang)
t.Run("SiteLang: "+string(lang), func(t *testing.T) {
t.Parallel()
for _, id := range fcIds {
t.Run("FC ID "+id, func(t *testing.T) {
fc, err := s.FetchFreeCompany(id)
if err != nil {
if lang == SiteLang("zh") {
return
}
t.Errorf(err.Error())
return
}
failIfStringEmpty(t, "FC active state", string(fc.Active))
failIfStringEmpty(t, "FC name", fc.Name)
failIfStringEmpty(t, "FC ID", fc.ID)
failIfStringEmpty(t, "FC world", fc.DC)
failIfStringEmpty(t, "FC DC", fc.DC)
failIfStringEmpty(t, "FC recruitment status", string(fc.Recruitment))
failIfOlderThanGameRelease(t, "FC formation", fc.Formed)
})
}
})
}
}
func TestFetchFreeCompanyMembers(t *testing.T) {
t.Parallel()
for _, lang := range langCodes {
s := NewScraper(bin, lang)
t.Run("SiteLang: "+string(lang), func(t *testing.T) {
t.Parallel()
for _, id := range fcIds {
t.Run("FC ID "+id, func(t *testing.T) {
for member := range s.FetchFreeCompanyMembers(id) {
if member.Error != nil {
if lang == SiteLang("zh") {
return
}
t.Errorf(member.Error.Error())
return
}
failIfStringEmpty(t, "Member avatar", member.Avatar)
failIfNumberZero(t, "Member ID", int64(member.ID))
failIfStringEmpty(t, "Member name", member.Name)
failIfStringEmpty(t, "Member world", member.World)
failIfStringEmpty(t, "Member DC", member.DC)
}
})
}
})
}
}
func TestSearchFreeCompanies(t *testing.T) {
t.Parallel()
for _, lang := range langCodes {
s := NewScraper(bin, lang)
t.Run("SiteLang: "+string(lang), func(t *testing.T) {
t.Parallel()
opts := FreeCompanyOptions{}
for fc := range s.SearchFreeCompanies(opts) {
if fc.Error != nil {
if lang == SiteLang("zh") {
return
}
t.Errorf(fc.Error.Error())
return
}
failIfStringEmpty(t, "FC active state", string(fc.Active))
failIfNumberZero(t, "FC active members", int64(fc.ActiveMembers))
failIfGCInvalid(t, "FC Grand Company", fc.GrandCompany)
failIfStringEmpty(t, "FC ID", fc.ID)
failIfStringEmpty(t, "FC name", fc.Name)
failIfStringEmpty(t, "FC world", fc.World)
failIfStringEmpty(t, "FC DC", fc.DC)
failIfStringEmpty(t, "FC estate", fc.Estate)
failIfOlderThanGameRelease(t, "FC formed", fc.Formed)
}
})
}
}
func TestSearchCharacters(t *testing.T) {
t.Parallel()
for _, lang := range langCodes {
s := NewScraper(bin, lang)
t.Run("SiteLang: "+string(lang), func(t *testing.T) {
t.Parallel()
opts := CharacterOptions{
World: "leviathan",
}
for character := range s.SearchCharacters(opts) {
if character.Error != nil {
if lang == SiteLang("zh") {
return
}
t.Errorf(character.Error.Error())
return
}
failIfStringEmpty(t, "Character avatar", character.Avatar)
failIfNumberZero(t, "Character ID", int64(character.ID))
failIfStringEmpty(t, "Character name", character.Name)
failIfStringEmpty(t, "Character world", character.World)
failIfStringEmpty(t, "Character DC", character.DC)
}
})
}
}
func TestSearchCWLS(t *testing.T) {
t.Parallel()
for _, lang := range langCodes {
s := NewScraper(bin, lang)
t.Run("SiteLang: "+string(lang), func(t *testing.T) {
t.Parallel()
opts := CWLSOptions{}
for cwls := range s.SearchCWLS(opts) {
if cwls.Error != nil {
if lang == SiteLang("zh") {
return
}
t.Errorf(cwls.Error.Error())
return
}
failIfStringEmpty(t, "CWLS ID", cwls.ID)
failIfStringEmpty(t, "CWLS name", cwls.Name)
failIfStringEmpty(t, "CWLS DC", cwls.DC)
failIfNumberZero(t, "CWLS active members", int64(cwls.ActiveMembers))
}
})
}
}
func TestSearchLinkshells(t *testing.T) {
t.Parallel()
for _, lang := range langCodes {
s := NewScraper(bin, lang)
t.Run("SiteLang: "+string(lang), func(t *testing.T) {
t.Parallel()
opts := LinkshellOptions{}
for ls := range s.SearchLinkshells(opts) {
if ls.Error != nil {
if lang == SiteLang("zh") {
return
}
t.Errorf(ls.Error.Error())
return
}
failIfStringEmpty(t, "Linkshell ID", ls.ID)
failIfStringEmpty(t, "Linkshell name", ls.Name)
failIfStringEmpty(t, "Linkshell world", ls.World)
failIfStringEmpty(t, "Linkshell DC", ls.DC)
failIfNumberZero(t, "Linkshell active members", int64(ls.ActiveMembers))
}
})
}
}
func TestSearchPVPTeams(t *testing.T) {
t.Parallel()
for _, lang := range langCodes {
s := NewScraper(bin, lang)
t.Run("SiteLang: "+string(lang), func(t *testing.T) {
t.Parallel()
opts := PVPTeamOptions{}
for ls := range s.SearchPVPTeams(opts) {
if ls.Error != nil {
if lang == SiteLang("zh") {
return
}
t.Errorf(ls.Error.Error())
return
}
failIfStringEmpty(t, "PVP team ID", ls.ID)
failIfStringEmpty(t, "PVP team name", ls.Name)
failIfStringEmpty(t, "PVP team DC", ls.DC)
}
})
}
}