Files

30 lines
1011 B
Go

package reconcile_test
import (
"context"
"testing"
"github.com/wangjia/pay/internal/model"
"github.com/wangjia/pay/internal/reconcile"
"github.com/wangjia/pay/internal/store"
)
func TestCryptoReservationLoaderFiltersPendingCrypto(t *testing.T) {
db := model.OpenTestDB(t)
s := store.NewOrderStore(db)
// 两条 attempt:crypto pending(要)、alipay pending(不要)。
_ = s.CreateAttempt(&model.Attempt{OutTradeNo: "O1", Channel: "crypto", ProviderRef: "CRYPTO-O1-12",
AmountMinor: 100, Currency: "USDT", Status: model.AttemptPending})
_ = s.CreateAttempt(&model.Attempt{OutTradeNo: "O2", Channel: "alipay", ProviderRef: "AL-O2",
AmountMinor: 200, Currency: "CNY", Status: model.AttemptPending})
loader := reconcile.CryptoReservationLoader(s)
items, err := loader(context.Background())
if err != nil {
t.Fatalf("loader: %v", err)
}
if len(items) != 1 || items[0].ProviderRef != "CRYPTO-O1-12" || items[0].AmountMinor != 100 {
t.Fatalf("只应含 crypto pending, got %+v", items)
}
}