Skip to content

Commit

Permalink
Add tests for each of the sections
Browse files Browse the repository at this point in the history
  • Loading branch information
simivar committed Jun 29, 2023
1 parent 00c6776 commit 66bcc70
Show file tree
Hide file tree
Showing 5 changed files with 2,463 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/TibiaForumSection.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func TibiaForumSectionImpl(BoxContentHTML string) (*ForumSectionResponse, error)
BoardsData = append(BoardsData, SectionBoard{
ID: TibiaDataStringToInteger(subma1[0][1]),
Name: subma1[0][2],
Description: subma1[0][3],
Description: TibiaDataSanitizeEscapedString(subma1[0][3]),
Posts: TibiaDataStringToInteger(subma1[0][4]),
Threads: TibiaDataStringToInteger(subma1[0][5]),
LastPost: SectionBoardLastPost{
Expand Down
123 changes: 122 additions & 1 deletion src/TibiaForumSection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"
)

func TestForumsSectionWorldboard(t *testing.T) {
func TestForumsSectionWorldBoard(t *testing.T) {
file, err := static.TestFiles.Open("testdata/forums/section/worldboard.html")
if err != nil {
t.Fatalf("file opening error: %s", err)
Expand Down Expand Up @@ -48,3 +48,124 @@ func TestForumsSectionWorldboard(t *testing.T) {
assert.Equal("Mad Mustazza", alumbra.LastPost.CharacterName)
assert.Equal("2023-06-04T15:51:13Z", alumbra.LastPost.PostedAt)
}

func TestForumsSectionSupportBoards(t *testing.T) {
file, err := static.TestFiles.Open("testdata/forums/section/supportboards.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)
}

boardsJson, err := TibiaForumSectionImpl(string(data))
if err != nil {
t.Fatal(err)
}

assert := assert.New(t)

assert.Equal(3, len(boardsJson.Boards))

paymentSupport := boardsJson.Boards[0]
assert.Equal(20, paymentSupport.ID)
assert.Equal("Payment Support", paymentSupport.Name)
assert.Equal("Here you can ask questions on orders, payments and other payment issues.", paymentSupport.Description)
assert.Equal(14468, paymentSupport.Threads)
assert.Equal(56032, paymentSupport.Posts)
assert.Equal(39400410, paymentSupport.LastPost.ID)
assert.Equal("Dorieta", paymentSupport.LastPost.CharacterName)
assert.Equal("2023-06-29T11:24:33Z", paymentSupport.LastPost.PostedAt)

technicalSupport := boardsJson.Boards[1]
assert.Equal(13, technicalSupport.ID)
assert.Equal("Technical Support", technicalSupport.Name)
assert.Equal("Here you can ask for help if you have a technical problem that is related to Tibia.", technicalSupport.Description)
assert.Equal(64722, technicalSupport.Threads)
assert.Equal(301828, technicalSupport.Posts)
assert.Equal(39400354, technicalSupport.LastPost.ID)
assert.Equal("Dio Sorcer", technicalSupport.LastPost.CharacterName)
assert.Equal("2023-06-29T01:47:59Z", technicalSupport.LastPost.PostedAt)

help := boardsJson.Boards[2]
assert.Equal(113174, help.ID)
assert.Equal("Help", help.Name)
assert.Equal("Here you can ask other players all kind of questions about Tibia. Note that members of the CipSoft team will usually not reply here.", help.Description)
assert.Equal(22788, help.Threads)
assert.Equal(106713, help.Posts)
assert.Equal(39400248, help.LastPost.ID)
assert.Equal("Dekraken durinars", help.LastPost.CharacterName)
assert.Equal("2023-06-28T17:17:45Z", help.LastPost.PostedAt)
}

func TestForumsSectionCommunityBoards(t *testing.T) {
file, err := static.TestFiles.Open("testdata/forums/section/communityboards.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)
}

boardsJson, err := TibiaForumSectionImpl(string(data))
if err != nil {
t.Fatal(err)
}

assert := assert.New(t)

assert.Equal(6, len(boardsJson.Boards))

gameplay := boardsJson.Boards[0]
assert.Equal(120835, gameplay.ID)
assert.Equal("Gameplay (English Only)", gameplay.Name)
assert.Equal("Here is the place to talk about quests, achievements and the general gameplay of Tibia.", gameplay.Description)
assert.Equal(35364, gameplay.Threads)
assert.Equal(335328, gameplay.Posts)
assert.Equal(39400492, gameplay.LastPost.ID)
assert.Equal("Dreamsphere", gameplay.LastPost.CharacterName)
assert.Equal("2023-06-29T19:59:41Z", gameplay.LastPost.PostedAt)

auditorium := boardsJson.Boards[5]
assert.Equal(89516, auditorium.ID)
assert.Equal("Auditorium (English Only)", auditorium.Name)
assert.Equal("Meet Tibia's community managers and give feedback on news articles and Tibia related topics. State your opinion and see what others think and have to say.", auditorium.Description)
}

func TestForumsSectionTradeBoards(t *testing.T) {
file, err := static.TestFiles.Open("testdata/forums/section/tradeboards.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)
}

boardsJson, err := TibiaForumSectionImpl(string(data))
if err != nil {
t.Fatal(err)
}

assert := assert.New(t)

assert.Equal(90, len(boardsJson.Boards))

adra := boardsJson.Boards[0]
assert.Equal(146485, adra.ID)
assert.Equal("Adra - Trade", adra.Name)
assert.Equal("Use this board to make Tibia related trade offers on the game world Adra. Note that all trades must conform to the Tibia Rules.", adra.Description)
assert.Equal(540, adra.Threads)
assert.Equal(599, adra.Posts)
assert.Equal(39400121, adra.LastPost.ID)
assert.Equal("Arge Reotona", adra.LastPost.CharacterName)
assert.Equal("2023-06-28T09:15:31Z", adra.LastPost.PostedAt)
}
Loading

0 comments on commit 66bcc70

Please sign in to comment.