package reconcile_test import ( "context" "testing" "time" "github.com/wangjia/pay/internal/accounts" "github.com/wangjia/pay/internal/model" "github.com/wangjia/pay/internal/reconcile" "github.com/wangjia/pay/internal/store" ) func TestUsageSourceRefreshAndInterface(t *testing.T) { db := model.OpenTestDB(t) s := store.NewOrderStore(db) now := time.Date(2026, 7, 10, 12, 0, 0, 0, time.UTC) paid := now.Add(-time.Hour) _ = s.CreateAttempt(&model.Attempt{OutTradeNo: "A", Channel: "alipay", AccountID: "acct-1", ProviderRef: "R-A", AmountMinor: 12000, Currency: "CNY", Status: model.AttemptPaid, PaidAt: &paid}) u := reconcile.NewUsageSource(s, func() time.Time { return now }) var _ accounts.UsageSource = u // 编译期断言满足接口 if u.TodayUsedMinor("acct-1") != 0 { t.Fatalf("刷新前应 0") } if err := u.Refresh(context.Background()); err != nil { t.Fatalf("refresh: %v", err) } if u.TodayUsedMinor("acct-1") != 12000 { t.Fatalf("刷新后 acct-1 应 12000, got %d", u.TodayUsedMinor("acct-1")) } if u.TodayUsedMinor("unknown") != 0 { t.Fatalf("未知账户应 0") } }