Files
pay/internal/store/attempt_accounts_test.go
T

40 lines
1.2 KiB
Go

package store_test
import (
"testing"
"github.com/wangjia/pay/internal/model"
"github.com/wangjia/pay/internal/store"
)
func TestAttemptAccountIDs(t *testing.T) {
s := store.NewOrderStore(model.OpenTestDB(t))
if err := s.CreateOrder(&model.OrderV2{OutTradeNo: "PAY-AC1", Subject: "x", AmountMinor: 100, Currency: "USDT", Status: model.OrderPendingV2}); err != nil {
t.Fatalf("order: %v", err)
}
for _, tc := range []struct{ ref, acct string }{{"R1", "a1"}, {"R2", "a2"}, {"R3", "a1"}} {
if err := s.CreateAttempt(&model.Attempt{
OutTradeNo: "PAY-AC1", Channel: "fake", AccountID: tc.acct, Provider: "fake",
ProviderRef: tc.ref, RenderType: "crypto_address", AmountMinor: 100, Currency: "USDT",
Status: model.AttemptPending,
}); err != nil {
t.Fatalf("attempt %s: %v", tc.ref, err)
}
}
ids, err := s.AttemptAccountIDs("PAY-AC1", "fake")
if err != nil {
t.Fatalf("AttemptAccountIDs: %v", err)
}
set := map[string]bool{}
for _, id := range ids {
set[id] = true
}
if len(set) != 2 || !set["a1"] || !set["a2"] {
t.Fatalf("应含 distinct a1,a2, got %v", ids)
}
// 其它渠道 / 其它单不串。
if got, _ := s.AttemptAccountIDs("PAY-AC1", "alipay"); len(got) != 0 {
t.Fatalf("别的渠道应空, got %v", got)
}
}