Skip to content

Commit ecd229a

Browse files
committed
fixing spell_id parsing in TibiaSpellsSpell
- fixing tests - updating testdata for spells/overviewall
1 parent a2db3f8 commit ecd229a

File tree

4 files changed

+37
-55
lines changed

4 files changed

+37
-55
lines changed

src/TibiaSpellsOverview_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestOverviewAll(t *testing.T) {
2727

2828
assert := assert.New(t)
2929

30-
assert.Equal(142, len(spellsOverviewJson.Spells.Spells))
30+
assert.Equal(152, len(spellsOverviewJson.Spells.Spells))
3131

3232
firstSpell := spellsOverviewJson.Spells.Spells[0]
3333
assert.Equal("Animate Dead Rune", firstSpell.Name)
@@ -43,7 +43,7 @@ func TestOverviewAll(t *testing.T) {
4343
assert.True(firstSpell.TypeRune)
4444
assert.True(firstSpell.PremiumOnly)
4545

46-
findPersonSpell := spellsOverviewJson.Spells.Spells[53]
46+
findPersonSpell := spellsOverviewJson.Spells.Spells[60]
4747
assert.Equal("Find Person", findPersonSpell.Name)
4848
assert.Equal("findperson", findPersonSpell.Spell)
4949
assert.Equal("exiva \"name\"", findPersonSpell.Formula)

src/TibiaSpellsSpell.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func TibiaSpellsSpellImpl(spell string, BoxContentHTML string) (*SpellInformatio
8080
// creating empty vars for later use
8181
SpellsInfoVocation, SpellsInfoCity, RuneInfoVocation []string
8282
// var SpellsInfoName, RuneInfoName string
83-
SpellInformationSection, SpellName, SpellImageURL, SpellDescription, SpellsInfoFormula, SpellsInfoDamageType, RuneInfoDamageType string
83+
SpellInformationSection, SpellName, SpellID, SpellImageURL, SpellDescription, SpellsInfoFormula, SpellsInfoDamageType, RuneInfoDamageType string
8484
SpellsInfoCooldownAlone, SpellsInfoCooldownGroup, SpellsInfoSoulPoints, SpellsInfoAmount, SpellsInfoLevel, SpellsInfoMana, SpellsInfoPrice, RuneInfoLevel, RuneInfoMagicLevel int
8585
SpellsInfoGroupAttack, SpellsInfoGroupHealing, SpellsInfoGroupSupport, SpellsInfoTypeInstant, SpellsInfoTypeRune, RuneInfoGroupAttack, RuneInfoGroupHealing, RuneInfoGroupSupport, SpellsInfoPremium, SpellsHasSpellSection, SpellsHasRuneSection bool
8686

@@ -94,11 +94,12 @@ func TibiaSpellsSpellImpl(spell string, BoxContentHTML string) (*SpellInformatio
9494
return false
9595
}
9696

97-
// Get the name and image
97+
// Get the name, spell_id and image
9898
subma2 := SpellNameAndImageRegex.FindAllStringSubmatch(NameAndImageSection, -1)
9999
if len(subma2) > 0 {
100100
SpellName = TibiaDataSanitize0026String(subma2[0][2])
101101
SpellImageURL = subma2[0][1]
102+
SpellID = SpellImageURL[strings.Index(SpellImageURL, "library/")+8 : strings.Index(SpellImageURL, ".png")]
102103
}
103104

104105
s.Find(".TableContainer").Each(func(index int, s *goquery.Selection) {
@@ -275,7 +276,7 @@ func TibiaSpellsSpellImpl(spell string, BoxContentHTML string) (*SpellInformatio
275276
return &SpellInformationResponse{
276277
SpellData{
277278
Name: SpellName,
278-
Spell: strings.ToLower(SpellName),
279+
Spell: SpellID,
279280
ImageURL: SpellImageURL,
280281
Description: SpellDescription,
281282
HasSpellInformation: SpellsHasSpellSection,

src/TibiaSpellsSpell_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"io"
5+
"log"
56
"testing"
67

78
"github.com/TibiaData/tibiadata-api-go/src/static"
@@ -28,9 +29,11 @@ func TestFindPerson(t *testing.T) {
2829
assert := assert.New(t)
2930
spell := findPersonJson.Spell
3031

32+
log.Print(spell)
33+
3134
assert.Empty(spell.Description)
3235
assert.Equal("Find Person", spell.Name)
33-
assert.Equal("find person", spell.Spell)
36+
assert.Equal("findperson", spell.Spell)
3437
assert.True(spell.HasSpellInformation)
3538
assert.NotNil(spell.SpellInformation)
3639
assert.Equal("exiva 'name'", spell.SpellInformation.Formula)
@@ -78,7 +81,7 @@ func TestHeavyMagicMissileRune(t *testing.T) {
7881

7982
assert.Empty(spell.Description)
8083
assert.Equal("Heavy Magic Missile Rune", spell.Name)
81-
assert.Equal("heavy magic missile rune", spell.Spell)
84+
assert.Equal("heavymagicmissilerune", spell.Spell)
8285
assert.True(spell.HasSpellInformation)
8386
assert.NotNil(spell.SpellInformation)
8487
assert.Equal("adori vis", spell.SpellInformation.Formula)
@@ -180,7 +183,7 @@ func TestBruiseBane(t *testing.T) {
180183

181184
assert.Empty(spell.Description)
182185
assert.Equal("Bruise Bane", spell.Name)
183-
assert.Equal("bruise bane", spell.Spell)
186+
assert.Equal("bruisebane", spell.Spell)
184187
assert.True(spell.HasSpellInformation)
185188
assert.NotNil(spell.SpellInformation)
186189
assert.Equal("exura infir ico", spell.SpellInformation.Formula)
@@ -223,7 +226,7 @@ func TestCurePoisonRune(t *testing.T) {
223226

224227
assert.Empty(spell.Description)
225228
assert.Equal("Cure Poison Rune", spell.Name)
226-
assert.Equal("cure poison rune", spell.Spell)
229+
assert.Equal("curepoisonrune", spell.Spell)
227230
assert.True(spell.HasSpellInformation)
228231
assert.NotNil(spell.SpellInformation)
229232
assert.Equal("adana pox", spell.SpellInformation.Formula)
@@ -262,7 +265,7 @@ func TestConvinceCreatureRune(t *testing.T) {
262265

263266
assert.Empty(spell.Description)
264267
assert.Equal("Convince Creature Rune", spell.Name)
265-
assert.Equal("convince creature rune", spell.Spell)
268+
assert.Equal("convincecreaturerune", spell.Spell)
266269
assert.True(spell.HasSpellInformation)
267270
assert.NotNil(spell.SpellInformation)
268271
assert.Equal("adeta sio", spell.SpellInformation.Formula)

0 commit comments

Comments
 (0)