Skip to content

Commit

Permalink
Add unit tests for /pass command
Browse files Browse the repository at this point in the history
  • Loading branch information
ryukinix committed Aug 10, 2020
1 parent 9c6e781 commit 9afd435
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions troll_shield_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,68 @@ func TestReportKills(t *testing.T) {
reportKills(&bot, &update, int64(11))
reportKills(&bot, &update, int64(10))
}

func TestExtractPassUserName(t *testing.T) {
tableTest := []struct {
input string
expected string
}{
{
"/pass @lerax",
"@lerax",
},
{
"/pass First Name",
"First Name",
},
}

for _, test := range tableTest {
if got := extractPassUserName(test.input); got != test.expected {
t.Errorf("Expected %q, got %q", test.expected, got)
}

}
}

func TestPassList(t *testing.T) {

bot := BotMockup{}
update := telegram.Update{}
message := telegram.Message{}
chat := telegram.Chat{}
message.Chat = &chat
message.Text = "/pass @lerax"
update.Message = &message
user := telegram.User{UserName: "lerax"}

// adding test
addPassList(&bot, &update)
t.Logf("passList: %v", passList)
if pass, ok := hasPass(user); pass != "@lerax" && ok != true {
t.Errorf("User @lerax should have a pass: pass=%v, ok=%v", pass, ok)
}

// removing test
t.Logf("passList: %v", passList)
removePassList(&bot, &update, "@lerax")
if pass, ok := hasPass(user); ok != false {
t.Errorf("User @lerax should not have more a pass: pass=%v, ok=%v", pass, ok)
}
}

func TestFromAdminEvent(t *testing.T) {
update := telegram.Update{}
message := telegram.Message{}
user := telegram.User{UserName: "lerax"}
message.From = &user
update.Message = &message
if got := fromAdminEvent(&update); got == false {
t.Errorf("lerax is a eternal admin, it should be true")
}

user.UserName = "delduca"
if got := fromAdminEvent(&update); got == true {
t.Errorf("delduca should not even being a member, neither admin.")
}
}

0 comments on commit 9afd435

Please sign in to comment.