mirror of
https://github.com/tiennm99/miti99bot.git
synced 2026-08-10 20:22:24 +00:00
feat: rename wc schedule commands
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user