2c94b53a9e
ci-pangolin / Cleartext Scan — Android 禁明文 (pull_request) Successful in 24s
ci-pangolin / Portable SQL — 可移植性 (mysql/sqlite) (pull_request) Successful in 23s
ci-pangolin / Lint — shellcheck (pull_request) Successful in 6s
ci-pangolin / OpenAPI Sync Check (pull_request) Successful in 36s
ci-pangolin / Flutter — analyze + test (pull_request) Successful in 34s
ci-pangolin / Codegen Drift — token 生成物未漂移 (pull_request) Successful in 3s
ci-pangolin / DS-flow — 原型/跨端同源/代码色单源闸 (pull_request) Successful in 3s
ci-pangolin / Go — build + test (pull_request) Failing after 11s
ci-pangolin / E2E Smoke — L4 进程级端到端 (pull_request) Failing after 10s
ci-pangolin / Redline Scan — 脱敏 (UI 文案) (pull_request) Failing after 10m52s
ci-pangolin / Go — integration (mysql/redis testcontainers) (pull_request) Failing after 4m33s
ci-pangolin / Golden — 视觉回归 (全量:components/auth/desktop/tablet) (pull_request) Failing after 19s
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01P9G7E3wmAYL9KeYCVZVsqu
75 lines
1.8 KiB
Go
75 lines
1.8 KiB
Go
package reward
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/wangjia/pangolin/server/internal/codes"
|
|
)
|
|
|
|
type fakeChecker struct{ member bool }
|
|
|
|
func (f fakeChecker) IsMember(_ context.Context, _, _ string) (bool, error) { return f.member, nil }
|
|
|
|
func newTgSvc(t *testing.T, db *sql.DB, member bool) *Service {
|
|
g := codes.NewService(codes.NewStore(db), nil, 5, time.Hour)
|
|
s := NewService(db, NewStore(db), g, Config{TgDays: 3}, time.Now)
|
|
s.SetTelegram("bot", "@ch", "tok", "sec")
|
|
s.SetMemberChecker(fakeChecker{member: member})
|
|
return s
|
|
}
|
|
|
|
func TestClaimTelegram_MemberGrantsOnce(t *testing.T) {
|
|
db := openDB(t)
|
|
seedU(t, db, 1, "u1")
|
|
s := newTgSvc(t, db, true)
|
|
res, err := s.ClaimTelegram(context.Background(), 1, "tg-777")
|
|
if err != nil || res != ClaimGranted {
|
|
t.Fatalf("claim1: %v %v", res, err)
|
|
}
|
|
if d := proDays(t, db, 1); d < 3 {
|
|
t.Fatalf("pro days=%d", d)
|
|
}
|
|
// 再领 → 已领取过(唯一守卫),不再发
|
|
res2, err2 := s.ClaimTelegram(context.Background(), 1, "tg-777")
|
|
if err2 != nil || res2 != ClaimAlready {
|
|
t.Fatalf("claim2: %v %v", res2, err2)
|
|
}
|
|
}
|
|
|
|
func TestClaimTelegram_NonMemberNoGrant(t *testing.T) {
|
|
db := openDB(t)
|
|
seedU(t, db, 1, "u1")
|
|
s := newTgSvc(t, db, false)
|
|
res, err := s.ClaimTelegram(context.Background(), 1, "tg-1")
|
|
if err != nil || res != ClaimNotMember {
|
|
t.Fatalf("claim: %v %v", res, err)
|
|
}
|
|
if d := proDays(t, db, 1); d >= 3 {
|
|
t.Fatalf("granted days to non-member: %d", d)
|
|
}
|
|
}
|
|
|
|
func TestTgMsgSetFor_LanguageSelection(t *testing.T) {
|
|
cases := []struct {
|
|
lang string
|
|
zh bool
|
|
}{
|
|
{"zh-hans", true},
|
|
{"zh", true},
|
|
{"zh-CN", true},
|
|
{"en", false},
|
|
{"de", false},
|
|
{"", false},
|
|
}
|
|
for _, c := range cases {
|
|
got := tgMsgSetFor(c.lang)
|
|
isZH := got.granted == tgMsgsZH.granted
|
|
if isZH != c.zh {
|
|
t.Fatalf("lang=%q: expected zh=%v, got zh=%v", c.lang, c.zh, isZH)
|
|
}
|
|
}
|
|
}
|