feat(server/reward): TG 绑定 token 签发/消费 + GET /v1/tasks/telegram/start

This commit is contained in:
wangjia
2026-07-13 07:49:31 +08:00
parent d23f7bca8f
commit e23cd5e1bd
4 changed files with 130 additions and 0 deletions
@@ -0,0 +1,30 @@
package reward
import (
"context"
"testing"
"time"
"github.com/wangjia/pangolin/server/internal/codes"
)
func TestTelegramToken_IssueThenConsumeOnce(t *testing.T) {
db := openDB(t)
seedU(t, db, 5, "u5")
g := codes.NewService(codes.NewStore(db), nil, 5, time.Hour)
s := NewService(db, NewStore(db), g, Config{TgDays: 3}, time.Now)
s.SetTelegram("pangolin_reward_bot", "@pangolin_app", "bot-token", "wh-secret") // 内存兜底(rdb nil)
tok, err := s.IssueTelegramToken(context.Background(), 5)
if err != nil || tok == "" {
t.Fatalf("issue: %q %v", tok, err)
}
uid, ok, _ := s.ConsumeTelegramToken(context.Background(), tok)
if !ok || uid != 5 {
t.Fatalf("consume: %d %v", uid, ok)
}
_, ok2, _ := s.ConsumeTelegramToken(context.Background(), tok)
if ok2 {
t.Fatalf("token consumable twice")
}
}