fix(lolschedule): silence empty daily push

This commit is contained in:
2026-06-30 09:01:40 +07:00
parent 8c45381e62
commit 03445e18f9
2 changed files with 38 additions and 5 deletions
+6 -4
View File
@@ -188,6 +188,7 @@ func runDailyPush(ctx context.Context, s *state, sender messageSender) error {
}
filtered := FilterMajor(events)
text := RenderToday(filtered, from)
disableNotification := len(filtered) == 0
// Idempotency gate: claim today's push before sending. A lost claim means
// another trigger already pushed (or is pushing) for this UTC date, so we
@@ -216,10 +217,11 @@ func runDailyPush(ctx context.Context, s *state, sender messageSender) error {
}
}
if _, err := sender.SendMessage(ctx, &bot.SendMessageParams{
ChatID: sub.ChatID,
MessageThreadID: sub.ThreadID,
Text: text,
ParseMode: models.ParseModeHTML,
ChatID: sub.ChatID,
MessageThreadID: sub.ThreadID,
Text: text,
ParseMode: models.ParseModeHTML,
DisableNotification: disableNotification,
}); err != nil {
log.Warn("lolschedule daily push send failed",
"chat", sub.ChatID, "thread", sub.ThreadID, "err", err)
+32 -1
View File
@@ -106,7 +106,7 @@ func TestRunDailyPush_NoSubscribers(t *testing.T) {
}
}
func TestRunDailyPush_SendsToAllSubscribers(t *testing.T) {
func TestRunDailyPush_SendsEmptyScheduleSilently(t *testing.T) {
s := newTestState(t)
seedFreshCache(t, s.cache, nil) // empty schedule still produces a "no matches" message
@@ -142,6 +142,37 @@ func TestRunDailyPush_SendsToAllSubscribers(t *testing.T) {
if call.MessageThreadID != 0 {
t.Errorf("send %d: thread got %d, want 0 (no topic)", i, call.MessageThreadID)
}
if !call.DisableNotification {
t.Errorf("send %d: DisableNotification got false, want true for empty schedule", i)
}
}
}
func TestRunDailyPush_SendsMatchScheduleWithNotification(t *testing.T) {
s := newTestState(t)
seedFreshCache(t, s.cache, []ScheduleEvent{{
StartTime: "2026-05-10T06:00:00Z",
State: "unstarted",
League: League{Name: "LCK", Slug: "lck"},
Match: Match{
Teams: []Team{{Code: "T1"}, {Code: "GEN"}},
Strategy: Strategy{Count: 3},
},
}})
if _, err := addSubscriber(context.Background(), s.subscribers, 100, 0); err != nil {
t.Fatalf("addSubscriber: %v", err)
}
sender := &fakeSender{}
if err := runDailyPush(context.Background(), s, sender); err != nil {
t.Fatalf("runDailyPush: %v", err)
}
if len(sender.calls) != 1 {
t.Fatalf("expected 1 send, got %d", len(sender.calls))
}
if sender.calls[0].DisableNotification {
t.Fatalf("DisableNotification got true, want false when today's match list is non-empty")
}
}