Skip to content

Commit

Permalink
remove testing code for supers
Browse files Browse the repository at this point in the history
  • Loading branch information
umputun committed Dec 7, 2023
1 parent 5ada0b2 commit dae69b8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion app/events/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (l *TelegramListener) procEvents(update tbapi.Update) error {
banUserStr := l.getBanUsername(resp, update)
if l.SuperUsers.IsSuper(msg.From.Username) {
log.Printf("[DEBUG] superuser %s requested ban, ignored", banUserStr)
l.forwardToAdmin(banUserStr, msg) // forward to admin here is for testing only
// l.forwardToAdmin(banUserStr, msg) //nolint forward to admin here is for testing only

Check failure on line 188 in app/events/telegram.go

View workflow job for this annotation

GitHub Actions / build

commentedOutCode: may want to remove commented-out code (gocritic)
return nil
}
banSuccessMessage := fmt.Sprintf("[INFO] %s banned by bot for %v", banUserStr, resp.BanInterval)
Expand Down
66 changes: 33 additions & 33 deletions app/events/telegram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,39 +164,39 @@ func TestTelegramListener_DoWithBotBan(t *testing.T) {
})

//nolint
// t.Run("test ban of the channel on behalf of the superuser", func(t *testing.T) {
// mockLogger.ResetCalls()
// mockAPI.ResetCalls()
// updMsg := tbapi.Update{
// Message: &tbapi.Message{
// ReplyToMessage: &tbapi.Message{
// SenderChat: &tbapi.Chat{
// ID: 54321,
// UserName: "original_bot",
// },
// },
// Chat: &tbapi.Chat{ID: 123},
// Text: "text 543",
// From: &tbapi.User{UserName: "admin", ID: 555},
// Date: int(time.Date(2020, 2, 11, 19, 37, 55, 9, time.UTC).Unix()),
// },
// }
//
// updChan := make(chan tbapi.Update, 1)
// updChan <- updMsg
// close(updChan)
// mockAPI.GetUpdatesChanFunc = func(config tbapi.UpdateConfig) tbapi.UpdatesChannel { return updChan }
//
// err := l.Do(ctx)
// assert.EqualError(t, err, "telegram update chan closed")
// require.Equal(t, 1, len(mockLogger.SaveCalls()))
// assert.Equal(t, "text 543", mockLogger.SaveCalls()[0].Msg.Text)
// assert.Equal(t, "admin", mockLogger.SaveCalls()[0].Msg.From.Username)
// assert.Equal(t, "bot's answer for admin", mockLogger.SaveCalls()[0].Response.Text)
// assert.Equal(t, 1, len(mockAPI.SendCalls()))
// assert.Equal(t, "bot's answer for admin", mockAPI.SendCalls()[0].C.(tbapi.MessageConfig).Text)
// require.Equal(t, 0, len(mockAPI.RequestCalls()))
// })
t.Run("test ban of the channel on behalf of the superuser", func(t *testing.T) {
mockLogger.ResetCalls()
mockAPI.ResetCalls()
updMsg := tbapi.Update{
Message: &tbapi.Message{
ReplyToMessage: &tbapi.Message{
SenderChat: &tbapi.Chat{
ID: 54321,
UserName: "original_bot",
},
},
Chat: &tbapi.Chat{ID: 123},
Text: "text 543",
From: &tbapi.User{UserName: "admin", ID: 555},
Date: int(time.Date(2020, 2, 11, 19, 37, 55, 9, time.UTC).Unix()),
},
}

updChan := make(chan tbapi.Update, 1)
updChan <- updMsg
close(updChan)
mockAPI.GetUpdatesChanFunc = func(config tbapi.UpdateConfig) tbapi.UpdatesChannel { return updChan }

err := l.Do(ctx)
assert.EqualError(t, err, "telegram update chan closed")
require.Equal(t, 1, len(mockLogger.SaveCalls()))
assert.Equal(t, "text 543", mockLogger.SaveCalls()[0].Msg.Text)
assert.Equal(t, "admin", mockLogger.SaveCalls()[0].Msg.From.Username)
assert.Equal(t, "bot's answer for admin", mockLogger.SaveCalls()[0].Response.Text)
assert.Equal(t, 1, len(mockAPI.SendCalls()))
assert.Equal(t, "bot's answer for admin", mockAPI.SendCalls()[0].C.(tbapi.MessageConfig).Text)
require.Equal(t, 0, len(mockAPI.RequestCalls()))
})
}

func TestTelegramListener_DoDeleteMessages(t *testing.T) {
Expand Down

0 comments on commit dae69b8

Please sign in to comment.