Skip to content

Commit

Permalink
fix: failing creature endpoints (#412)
Browse files Browse the repository at this point in the history
* fix: TibiaCreaturesOverview issues
* fix: TibiaCreaturesCreature issues
  • Loading branch information
tobiasehlert authored Nov 21, 2024
1 parent c91f196 commit a625880
Show file tree
Hide file tree
Showing 12 changed files with 5,104 additions and 4,299 deletions.
2 changes: 1 addition & 1 deletion src/TibiaCreaturesCreature.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type CreatureResponse struct {
}

var (
CreatureDataRegex = regexp.MustCompile(`.*;">(.*)<\/h2> <img src="(.*)"\/>.*<p>(.*)<\/p> <p>(.*)<\/p> <p>(.*)<\/p>.*`)
CreatureDataRegex = regexp.MustCompile(`.*;">(.*)<\/h2> <img src="(.*)"\/>.*<p>(.*)<\/p> <p>(.*)<\/p> <p>(.*)<\/p>.*`)
CreatureHitpointsRegex = regexp.MustCompile(`.*have (.*) hitpoints. (.*)`)
CreatureImmuneRegex = regexp.MustCompile(`.*are immune to (.*)`)
CreatureStrongRegex = regexp.MustCompile(`.*are strong against (.*)`)
Expand Down
27 changes: 24 additions & 3 deletions src/TibiaCreaturesCreature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestDemon(t *testing.T) {
assert.False(demonJson.Creature.Featured)
}

func TestQuaraPredatorFeatured(t *testing.T) {
func TestQuaraPredator(t *testing.T) {
file, err := static.TestFiles.Open("testdata/creatures/creature/quara predator.html")
if err != nil {
t.Fatalf("file opening error: %s", err)
Expand Down Expand Up @@ -108,14 +108,14 @@ func TestQuaraPredatorFeatured(t *testing.T) {
assert.False(quaraPredatorJson.Creature.BeConvinced)
assert.Equal(0, quaraPredatorJson.Creature.ConvincedMana)
assert.True(quaraPredatorJson.Creature.SeeInvisible)
assert.Equal(1600, quaraPredatorJson.Creature.ExperiencePoints)
assert.Equal(1850, quaraPredatorJson.Creature.ExperiencePoints)
assert.True(quaraPredatorJson.Creature.IsLootable)

assert.Equal(2, len(quaraPredatorJson.Creature.LootList))
assert.Equal("gold coins", quaraPredatorJson.Creature.LootList[0])
assert.Equal("quara bones", quaraPredatorJson.Creature.LootList[1])

assert.True(quaraPredatorJson.Creature.Featured)
assert.False(quaraPredatorJson.Creature.Featured)
}

func TestCentipede(t *testing.T) {
Expand Down Expand Up @@ -211,3 +211,24 @@ func TestLavaLurkers(t *testing.T) {
assert.Equal(1, len(lavalurkersJson.Creature.HealedBy))
assert.Equal("fire", lavalurkersJson.Creature.HealedBy[0])
}

func TestFeralWerecrocodilesFeatured(t *testing.T) {
file, err := static.TestFiles.Open("testdata/creatures/creature/feral werecrocodile.html")
if err != nil {
t.Fatalf("file opening error: %s", err)
}
defer file.Close()

data, err := io.ReadAll(file)
if err != nil {
t.Fatalf("File reading error: %s", err)
}

feralwerecrocodileJson, _ := TibiaCreaturesCreatureImpl("Feral Werecrocodiles", string(data), "")
assert := assert.New(t)

assert.Equal("Feral Werecrocodiles", feralwerecrocodileJson.Creature.Name)
assert.Equal("Feral Werecrocodiles", feralwerecrocodileJson.Creature.Race)

assert.False(feralwerecrocodileJson.Creature.Featured)
}
2 changes: 1 addition & 1 deletion src/TibiaCreaturesOverview.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TibiaCreaturesOverviewImpl(BoxContentHTML string, url string) (CreaturesOve
)

// Running query over each div
ReaderHTML.Find(".BoxContent div div").EachWithBreak(func(index int, s *goquery.Selection) bool {
ReaderHTML.Find(".Creatures div").EachWithBreak(func(index int, s *goquery.Selection) bool {
// Storing HTML into CreatureDivHTML
CreatureDivHTML, err := s.Html()
if err != nil {
Expand Down
14 changes: 10 additions & 4 deletions src/TibiaCreaturesOverview_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ func TestOverview(t *testing.T) {
information := creaturesJson.Information

assert.Equal("https://www.tibia.com/library/?subtopic=creatures", information.TibiaURLs[0])
assert.Equal("Minotaur Amazon", creaturesJson.Creatures.Boosted.Name)
assert.Equal("minotauramazon", creaturesJson.Creatures.Boosted.Race)
assert.Equal("https://static.tibia.com/images/global/header/monsters/minotauramazon.gif", creaturesJson.Creatures.Boosted.ImageURL)
assert.Equal("Feral Werecrocodile", creaturesJson.Creatures.Boosted.Name)
assert.Equal("feralwerecrocodile", creaturesJson.Creatures.Boosted.Race)
assert.Equal("https://static.tibia.com/images/global/header/monsters/feralwerecrocodile.gif", creaturesJson.Creatures.Boosted.ImageURL)

assert.Equal(638, len(creaturesJson.Creatures.Creatures))

Expand All @@ -41,11 +41,17 @@ func TestOverview(t *testing.T) {
assert.Equal("https://static.tibia.com/images/library/acidblob.gif", acidblob.ImageURL)
assert.False(acidblob.Featured)

feralwerecrocodile := creaturesJson.Creatures.Creatures[204]
assert.Equal("Feral Werecrocodiles", feralwerecrocodile.Name)
assert.Equal("feralwerecrocodile", feralwerecrocodile.Race)
assert.Equal("https://static.tibia.com/images/library/feralwerecrocodile.gif", feralwerecrocodile.ImageURL)
assert.True(feralwerecrocodile.Featured)

minotauramazon := creaturesJson.Creatures.Creatures[360]
assert.Equal("Minotaur Amazons", minotauramazon.Name)
assert.Equal("minotauramazon", minotauramazon.Race)
assert.Equal("https://static.tibia.com/images/library/minotauramazon.gif", minotauramazon.ImageURL)
assert.True(minotauramazon.Featured)
assert.False(minotauramazon.Featured)

quarapredator := creaturesJson.Creatures.Creatures[465]
assert.Equal("Quara Predators", quarapredator.Name)
Expand Down
1,186 changes: 587 additions & 599 deletions src/static/testdata/creatures/creature/centipede.html

Large diffs are not rendered by default.

Loading

0 comments on commit a625880

Please sign in to comment.