This commit is contained in:
yml
2026-06-10 02:12:02 +08:00
parent 992d4ed234
commit c517349db6
6 changed files with 388 additions and 69 deletions
@@ -1,6 +1,7 @@
package wallet
import (
"context"
"errors"
"testing"
)
@@ -8,7 +9,8 @@ import (
// TestServiceAccountWithNilRepo 测试依赖检查
func TestServiceAccountWithNilRepo(t *testing.T) {
svc := &Service{repo: nil}
_, err := svc.Account(1)
ctx := context.Background()
_, err := svc.Account(ctx, 1)
if !errors.Is(err, ErrDependencyUnavailable) {
t.Fatalf("Account() error = %v, want ErrDependencyUnavailable", err)
}
@@ -16,7 +18,8 @@ func TestServiceAccountWithNilRepo(t *testing.T) {
func TestServiceLedgerWithNilRepo(t *testing.T) {
svc := &Service{repo: nil}
_, err := svc.Ledger(1, 1, 10)
ctx := context.Background()
_, err := svc.Ledger(ctx, 1, 1, 10)
if !errors.Is(err, ErrDependencyUnavailable) {
t.Fatalf("Ledger() error = %v, want ErrDependencyUnavailable", err)
}
@@ -24,7 +27,8 @@ func TestServiceLedgerWithNilRepo(t *testing.T) {
func TestServiceRechargeIsDisabled(t *testing.T) {
svc := &Service{repo: &Repository{}}
_, err := svc.Recharge(1, RechargeRequest{AmountCent: 100})
ctx := context.Background()
_, err := svc.Recharge(ctx, 1, RechargeRequest{AmountCent: 100})
if !errors.Is(err, ErrRechargeDisabled) {
t.Fatalf("Recharge() error = %v, want ErrRechargeDisabled", err)
}
@@ -32,7 +36,8 @@ func TestServiceRechargeIsDisabled(t *testing.T) {
func TestServiceWithdrawIsPending(t *testing.T) {
svc := &Service{repo: &Repository{}}
_, err := svc.Withdraw(1, WithdrawRequest{AmountCent: 100})
ctx := context.Background()
_, err := svc.Withdraw(ctx, 1, WithdrawRequest{AmountCent: 100})
if !errors.Is(err, ErrFeaturePending) {
t.Fatalf("Withdraw() error = %v, want ErrFeaturePending", err)
}
@@ -40,7 +45,8 @@ func TestServiceWithdrawIsPending(t *testing.T) {
func TestServiceAdminLedgerWithNilRepo(t *testing.T) {
svc := &Service{repo: nil}
_, err := svc.AdminLedger(AdminLedgerQuery{Page: 1, PageSize: 10})
ctx := context.Background()
_, err := svc.AdminLedger(ctx, AdminLedgerQuery{Page: 1, PageSize: 10})
if !errors.Is(err, ErrDependencyUnavailable) {
t.Fatalf("AdminLedger() error = %v, want ErrDependencyUnavailable", err)
}