feat(v2): LimitAware 真实用量源——DBUsageSource 快照 + 对账 job 周期聚合当日已收(替 NopUsage)
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user