Files
hfb_sys/backend/internal/modules/wallet/service_test.go
T
2026-06-10 02:12:02 +08:00

54 lines
1.5 KiB
Go

package wallet
import (
"context"
"errors"
"testing"
)
// TestServiceAccountWithNilRepo 测试依赖检查
func TestServiceAccountWithNilRepo(t *testing.T) {
svc := &Service{repo: nil}
ctx := context.Background()
_, err := svc.Account(ctx, 1)
if !errors.Is(err, ErrDependencyUnavailable) {
t.Fatalf("Account() error = %v, want ErrDependencyUnavailable", err)
}
}
func TestServiceLedgerWithNilRepo(t *testing.T) {
svc := &Service{repo: nil}
ctx := context.Background()
_, err := svc.Ledger(ctx, 1, 1, 10)
if !errors.Is(err, ErrDependencyUnavailable) {
t.Fatalf("Ledger() error = %v, want ErrDependencyUnavailable", err)
}
}
func TestServiceRechargeIsDisabled(t *testing.T) {
svc := &Service{repo: &Repository{}}
ctx := context.Background()
_, err := svc.Recharge(ctx, 1, RechargeRequest{AmountCent: 100})
if !errors.Is(err, ErrRechargeDisabled) {
t.Fatalf("Recharge() error = %v, want ErrRechargeDisabled", err)
}
}
func TestServiceWithdrawIsPending(t *testing.T) {
svc := &Service{repo: &Repository{}}
ctx := context.Background()
_, err := svc.Withdraw(ctx, 1, WithdrawRequest{AmountCent: 100})
if !errors.Is(err, ErrFeaturePending) {
t.Fatalf("Withdraw() error = %v, want ErrFeaturePending", err)
}
}
func TestServiceAdminLedgerWithNilRepo(t *testing.T) {
svc := &Service{repo: nil}
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)
}
}