From cee1daeea928d120d91f0bf1faab29f35619254e Mon Sep 17 00:00:00 2001 From: tiennm99 Date: Wed, 1 Jul 2026 10:42:56 +0700 Subject: [PATCH] feat: rename wc schedule commands --- cmd/server/main_test.go | 2 +- internal/modules/wc/handlers.go | 9 --------- internal/modules/wc/handlers_test.go | 25 ++++++++++++++++++------- internal/modules/wc/wc.go | 8 +------- internal/modules/wc/wc_test.go | 2 +- telegram-commands.json | 6 +----- 6 files changed, 22 insertions(+), 30 deletions(-) diff --git a/cmd/server/main_test.go b/cmd/server/main_test.go index 2bd0fb9..0c95eb0 100644 --- a/cmd/server/main_test.go +++ b/cmd/server/main_test.go @@ -62,7 +62,7 @@ func TestFactoriesIncludesExpectedModules(t *testing.T) { for _, name := range []string{ "gold_price", "gold_topup", "gold_buy", "gold_sell", "gold_stats", "coin_price", "coin_topup", "coin_buy", "coin_sell", "coin_stats", - "wc", "wc_today", "wc_week", "wc_subscribe", "wc_unsubscribe", + "wc", "wc_this_week", "wc_subscribe", "wc_unsubscribe", } { if _, ok := reg.AllCommands[name]; !ok { t.Fatalf("missing command %s", name) diff --git a/internal/modules/wc/handlers.go b/internal/modules/wc/handlers.go index ba9f134..e890b2c 100644 --- a/internal/modules/wc/handlers.go +++ b/internal/modules/wc/handlers.go @@ -44,15 +44,6 @@ func (s *state) handleSchedule(ctx context.Context, b *bot.Bot, update *models.U return s.replyForRange(ctx, b, msg, parsed.Date, addDays(parsed.Date, 1), false) } -func (s *state) handleToday(ctx context.Context, b *bot.Bot, update *models.Update) error { - msg := update.Message - if msg == nil { - return nil - } - from := ictDayStartOf(s.now()) - return s.replyForRange(ctx, b, msg, from, addDays(from, 1), false) -} - func (s *state) handleWeek(ctx context.Context, b *bot.Bot, update *models.Update) error { msg := update.Message if msg == nil { diff --git a/internal/modules/wc/handlers_test.go b/internal/modules/wc/handlers_test.go index 673b31e..d7bb1b0 100644 --- a/internal/modules/wc/handlers_test.go +++ b/internal/modules/wc/handlers_test.go @@ -34,8 +34,7 @@ func installWC(t *testing.T, bodyJSON string, now time.Time) (*testutil.Recordin Name: "wc", Commands: []modules.Command{ {Name: "wc", Visibility: modules.VisibilityPublic, Description: "x", Handler: s.handleSchedule}, - {Name: "wc_today", Visibility: modules.VisibilityPublic, Description: "x", Handler: s.handleToday}, - {Name: "wc_week", Visibility: modules.VisibilityPublic, Description: "x", Handler: s.handleWeek}, + {Name: "wc_this_week", Visibility: modules.VisibilityPublic, Description: "x", Handler: s.handleWeek}, {Name: "wc_subscribe", Visibility: modules.VisibilityPublic, Description: "x", Handler: s.handleSubscribe}, {Name: "wc_unsubscribe", Visibility: modules.VisibilityPublic, Description: "x", Handler: s.handleUnsubscribe}, }, @@ -50,9 +49,9 @@ func installWC(t *testing.T, bodyJSON string, now time.Time) (*testutil.Recordin var fakeNow = time.Date(2026, 6, 12, 5, 0, 0, 0, time.UTC) -func TestHandleToday_RendersHTML(t *testing.T) { +func TestHandleSchedule_DefaultsToToday(t *testing.T) { rb, _ := installWC(t, sampleMatchesBody, fakeNow) - rb.Bot.ProcessUpdate(context.Background(), testutil.NewPrivateMessage(1, "/wc_today")) + rb.Bot.ProcessUpdate(context.Background(), testutil.NewPrivateMessage(1, "/wc")) got := rb.LastSent() if got.Method != "sendMessage" { @@ -76,6 +75,18 @@ func TestHandleSchedule_BadDateInput(t *testing.T) { } } +func TestHandleWeek_RendersThisWeek(t *testing.T) { + rb, _ := installWC(t, sampleMatchesBody, fakeNow) + rb.Bot.ProcessUpdate(context.Background(), testutil.NewPrivateMessage(1, "/wc_this_week")) + + got := rb.LastSent().Text() + for _, want := range []string{"Mon Jun 8", "Sun Jun 14", "MEX vs RSA", "CAN vs SUI"} { + if !strings.Contains(got, want) { + t.Fatalf("missing %q in:\n%s", want, got) + } + } +} + func TestHandleSubscribe_AddsAndIsIdempotent(t *testing.T) { rb, store := installWC(t, sampleMatchesBody, fakeNow) rb.Bot.ProcessUpdate(context.Background(), testutil.NewPrivateMessage(7, "/wc_subscribe")) @@ -105,7 +116,7 @@ func TestHandleSubscribe_ForumTopic(t *testing.T) { } } -func TestHandleToday_MissingToken(t *testing.T) { +func TestHandleSchedule_MissingToken(t *testing.T) { rb := testutil.NewRecordingBot(t) col := storage.NewMemoryProvider().Collection("wc") s := &state{ @@ -115,14 +126,14 @@ func TestHandleToday_MissingToken(t *testing.T) { client: &Client{}, nowFn: func() time.Time { return fakeNow }, } - cmd := modules.Command{Name: "wc_today", Visibility: modules.VisibilityPublic, Description: "x", Handler: s.handleToday} + cmd := modules.Command{Name: "wc", Visibility: modules.VisibilityPublic, Description: "x", Handler: s.handleSchedule} reg := &modules.Registry{ Modules: []modules.Module{{Name: "wc", Commands: []modules.Command{cmd}}}, AllCommands: map[string]modules.Command{cmd.Name: cmd}, } modules.Install(rb.Bot, reg, modules.Auth{}) - rb.Bot.ProcessUpdate(context.Background(), testutil.NewPrivateMessage(1, "/wc_today")) + rb.Bot.ProcessUpdate(context.Background(), testutil.NewPrivateMessage(1, "/wc")) if got := rb.LastSent().Text(); !strings.Contains(got, "WC_FOOTBALL_DATA_TOKEN") { t.Fatalf("reply = %q, want missing token hint", got) } diff --git a/internal/modules/wc/wc.go b/internal/modules/wc/wc.go index ec24391..8008651 100644 --- a/internal/modules/wc/wc.go +++ b/internal/modules/wc/wc.go @@ -22,13 +22,7 @@ func New(deps modules.Deps) modules.Module { Handler: s.handleSchedule, }, { - Name: "wc_today", - Visibility: modules.VisibilityPublic, - Description: "Today's World Cup matches (scores if available)", - Handler: s.handleToday, - }, - { - Name: "wc_week", + Name: "wc_this_week", Visibility: modules.VisibilityPublic, Description: "World Cup matches for this week (Mon-Sun, ICT)", Handler: s.handleWeek, diff --git a/internal/modules/wc/wc_test.go b/internal/modules/wc/wc_test.go index 5b5d29f..36a75e2 100644 --- a/internal/modules/wc/wc_test.go +++ b/internal/modules/wc/wc_test.go @@ -13,7 +13,7 @@ func TestNewRegistersExpectedCommandsAndCron(t *testing.T) { for _, cmd := range mod.Commands { got[cmd.Name] = true } - for _, name := range []string{"wc", "wc_today", "wc_week", "wc_subscribe", "wc_unsubscribe"} { + for _, name := range []string{"wc", "wc_this_week", "wc_subscribe", "wc_unsubscribe"} { if !got[name] { t.Fatalf("missing command %s", name) } diff --git a/telegram-commands.json b/telegram-commands.json index 89c4552..642c180 100644 --- a/telegram-commands.json +++ b/telegram-commands.json @@ -61,11 +61,7 @@ "description": "World Cup matches for a date" }, { - "command": "wc_today", - "description": "Today's World Cup matches" - }, - { - "command": "wc_week", + "command": "wc_this_week", "description": "World Cup matches for this week" }, {