Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests for /pass command #8

Merged
merged 3 commits into from
Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
on: [push, pull_request]
on: [push]
name: test
jobs:
lint:
Expand Down
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 an 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.")
}
}