Files

25 lines
761 B
Go

package store_test
import (
"testing"
"time"
"github.com/wangjia/pay/internal/model"
"github.com/wangjia/pay/internal/store"
)
func TestOrphanStoreRecordIdempotent(t *testing.T) {
os := store.NewOrphanStore(model.OpenTestDB(t))
o := &model.OrphanPayment{Channel: "crypto", AccountID: "cry-1", TxID: "TX-1",
AmountMinor: 12345, Currency: "USDT", DetectedAt: time.Now()}
first, err := os.Record(o)
if err != nil || !first {
t.Fatalf("首次应记入, first=%v err=%v", first, err)
}
again, err := os.Record(&model.OrphanPayment{Channel: "crypto", AccountID: "cry-1", TxID: "TX-1",
AmountMinor: 12345, Currency: "USDT", DetectedAt: time.Now()})
if err != nil || again {
t.Fatalf("同 tx_id 应幂等 no-op, again=%v err=%v", again, err)
}
}