31 lines
821 B
Go
31 lines
821 B
Go
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")
|
|
}
|
|
}
|