Files
tiennm99 629b513c91 feat(games): move /wordle and /loldle to the web games and add /loldledaily
/wordle and /loldle now send the wordle and loldle BotFather games in an
unlimited mode: each player gets their own word or champion, saved after
every guess, with a New game button. Cards the bot did not record as
unlimited, including the daily cards, play the daily puzzle. The helper
commands keep working on the player's round.

/loldledaily mirrors /wordledaily: one champion per day at 07:00 ICT,
subscribe and unsubscribe, the morning recap and the live group results.

The daily and unlimited machinery is shared in util/guessgame, the old
in-chat wordle module is removed, and a one-time startup migration carries
each player's stats and unfinished round over without changing old data.
2026-10-10 09:29:48 +07:00

59 lines
1.7 KiB
Go

package loldle
import (
"context"
"testing"
"github.com/tiennm99/tiennm99bot/internal/storage"
)
func newLoldleConfig() ConfigStore {
return storage.Typed[roundConfig](storage.NewMemoryProvider().Collection("loldle"))
}
func TestGetMaxGuesses_DefaultsAndOverrides(t *testing.T) {
ctx := context.Background()
cfg := newLoldleConfig()
if n, _ := getMaxGuesses(ctx, cfg, "u1"); n != MaxGuesses {
t.Errorf("missing config → %d, want %d", n, MaxGuesses)
}
if err := setMaxGuesses(ctx, cfg, "u1", 5); err != nil {
t.Fatal(err)
}
if n, _ := getMaxGuesses(ctx, cfg, "u1"); n != 5 {
t.Errorf("after setMax(5): %d, want 5", n)
}
}
func TestSetMaxGuesses_ValidatesRange(t *testing.T) {
ctx := context.Background()
cfg := newLoldleConfig()
for _, n := range []int{0, -1, MaxGuessesCap + 1, 100} {
if err := setMaxGuesses(ctx, cfg, "u1", n); err == nil {
t.Errorf("setMaxGuesses(%d) should error", n)
}
}
if err := setMaxGuesses(ctx, cfg, "u1", 1); err != nil {
t.Errorf("setMaxGuesses(1) should succeed: %v", err)
}
if err := setMaxGuesses(ctx, cfg, "u1", MaxGuessesCap); err != nil {
t.Errorf("setMaxGuesses(cap) should succeed: %v", err)
}
}
func TestGetMaxGuesses_OutOfRangeIgnored(t *testing.T) {
ctx := context.Background()
cfg := newLoldleConfig()
// Inject a corrupt config to simulate manual store tampering or a stale
// schema; getMaxGuesses must fall back to the default rather than
// returning a wild value to handlers.
if err := cfg.Put(ctx, configKey("u1"), roundConfig{MaxGuesses: 100}); err != nil {
t.Fatal(err)
}
if n, _ := getMaxGuesses(ctx, cfg, "u1"); n != MaxGuesses {
t.Errorf("out-of-range config → %d, want %d (default)", n, MaxGuesses)
}
}