diff --git a/README.md b/README.md index 5d86525..9f8f5d5 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Plug-n-play Telegram bot framework in Go. Runs on AWS Lambda + DynamoDB + EventB | Module | What it does | |---|---| | `util` | `/help`, `/info`, `/stickerid` | -| `misc` | Coin flip, dice, RNG utilities | +| `misc` | `/ping`, `/mstats`, `/trongtruonghop` disclaimer | | `wordle` | Daily Wordle game | | `loldle` | League-of-Legends "guess the champion" | | `lolschedule` | Pro-match schedule + daily push | diff --git a/internal/modules/misc/handlers_test.go b/internal/modules/misc/handlers_test.go index 0b68a1d..b7a9944 100644 --- a/internal/modules/misc/handlers_test.go +++ b/internal/modules/misc/handlers_test.go @@ -6,6 +6,8 @@ import ( "testing" "time" + "github.com/go-telegram/bot/models" + "github.com/tiennm99/miti99bot/internal/modules" "github.com/tiennm99/miti99bot/internal/storage" "github.com/tiennm99/miti99bot/internal/testutil" @@ -86,6 +88,83 @@ func TestMstats_DeniedToNonAdmin(t *testing.T) { } } +// trongTruongHopUpdate is the inline counterpart of testutil.NewPrivateMessage +// for cases that need control over From (username, names). The dispatcher +// requires a bot_command entity, so we lift that from the helper API by reusing +// NewPrivateMessage and overwriting From. +func trongTruongHopUpdate(t *testing.T, text string, from *models.User) *models.Update { + t.Helper() + u := testutil.NewPrivateMessage(from.ID, text) + u.Message.From = from + return u +} + +func TestTrongTruongHop_DefaultArgUsesVNG(t *testing.T) { + rb, _ := installMisc(t, 999) + rb.Bot.ProcessUpdate(context.Background(), trongTruongHopUpdate(t, "/trongtruonghop", + &models.User{ID: 7, Username: "boss", FirstName: "Boss"})) + + got := rb.LastSent().Text() + if !strings.Contains(got, "VNG") { + t.Errorf("reply missing default target VNG: %q", got) + } + if n := strings.Count(got, "@boss"); n != 2 { + t.Errorf("reply mentions @boss %d times, want 2: %q", n, got) + } +} + +func TestTrongTruongHop_CustomArg(t *testing.T) { + rb, _ := installMisc(t, 999) + rb.Bot.ProcessUpdate(context.Background(), trongTruongHopUpdate(t, "/trongtruonghop Acme Corp", + &models.User{ID: 7, Username: "boss", FirstName: "Boss"})) + + got := rb.LastSent().Text() + if !strings.Contains(got, "Acme Corp") { + t.Errorf("reply missing custom arg Acme Corp: %q", got) + } + if strings.Contains(got, "VNG") { + t.Errorf("reply unexpectedly contains default VNG: %q", got) + } +} + +func TestTrongTruongHop_HTMLEscapesArg(t *testing.T) { + rb, _ := installMisc(t, 999) + rb.Bot.ProcessUpdate(context.Background(), trongTruongHopUpdate(t, "/trongtruonghop