96 lines
3.1 KiB
Go
96 lines
3.1 KiB
Go
package order
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
// TestServiceDependencyChecks 测试所有 Service 方法的依赖检查
|
|
func TestServiceCreateWithNilRepo(t *testing.T) {
|
|
svc := &Service{repo: nil}
|
|
_, err := svc.Create(t.Context(), 1, CreateRequest{ListingID: 100})
|
|
if !errors.Is(err, ErrDependencyUnavailable) {
|
|
t.Fatalf("Create() error = %v, want ErrDependencyUnavailable", err)
|
|
}
|
|
}
|
|
|
|
func TestServiceCreateWithZeroListingID(t *testing.T) {
|
|
svc := &Service{repo: &Repository{}}
|
|
_, err := svc.Create(t.Context(), 1, CreateRequest{ListingID: 0})
|
|
if !errors.Is(err, ErrInvalidRentHours) {
|
|
t.Fatalf("Create() error = %v, want ErrInvalidRentHours", err)
|
|
}
|
|
}
|
|
|
|
func TestServiceCancelWithNilRepo(t *testing.T) {
|
|
svc := &Service{repo: nil}
|
|
err := svc.Cancel(t.Context(), 1, 100)
|
|
if !errors.Is(err, ErrDependencyUnavailable) {
|
|
t.Fatalf("Cancel() error = %v, want ErrDependencyUnavailable", err)
|
|
}
|
|
}
|
|
|
|
func TestServicePayWithNilRepo(t *testing.T) {
|
|
svc := &Service{repo: nil}
|
|
err := svc.Pay(t.Context(), 1, 100)
|
|
if !errors.Is(err, ErrDependencyUnavailable) {
|
|
t.Fatalf("Pay() error = %v, want ErrDependencyUnavailable", err)
|
|
}
|
|
}
|
|
|
|
func TestServicePayWithZeroOrderID(t *testing.T) {
|
|
svc := &Service{repo: &Repository{}}
|
|
err := svc.Pay(t.Context(), 1, 0)
|
|
if !errors.Is(err, ErrOrderCannotPay) {
|
|
t.Fatalf("Pay() error = %v, want ErrOrderCannotPay", err)
|
|
}
|
|
}
|
|
|
|
func TestServiceSubmitHandoffWithNilRepo(t *testing.T) {
|
|
svc := &Service{repo: nil}
|
|
_, err := svc.SubmitHandoff(t.Context(), 1, 100, SubmitHandoffRequest{Content: "test"})
|
|
if !errors.Is(err, ErrDependencyUnavailable) {
|
|
t.Fatalf("SubmitHandoff() error = %v, want ErrDependencyUnavailable", err)
|
|
}
|
|
}
|
|
|
|
func TestServiceSubmitHandoffWithEmptyContent(t *testing.T) {
|
|
svc := &Service{repo: &Repository{}}
|
|
_, err := svc.SubmitHandoff(t.Context(), 1, 100, SubmitHandoffRequest{Content: ""})
|
|
if !errors.Is(err, ErrOrderCannotHandoff) {
|
|
t.Fatalf("SubmitHandoff() error = %v, want ErrOrderCannotHandoff", err)
|
|
}
|
|
}
|
|
|
|
func TestServiceConfirmReceiveWithNilRepo(t *testing.T) {
|
|
svc := &Service{repo: nil}
|
|
err := svc.ConfirmReceive(t.Context(), 1, 100)
|
|
if !errors.Is(err, ErrDependencyUnavailable) {
|
|
t.Fatalf("ConfirmReceive() error = %v, want ErrDependencyUnavailable", err)
|
|
}
|
|
}
|
|
|
|
func TestServiceSubmitReturnWithNilRepo(t *testing.T) {
|
|
svc := &Service{repo: nil}
|
|
_, err := svc.SubmitReturn(t.Context(), 1, 100, SubmitReturnRequest{Content: "test"})
|
|
if !errors.Is(err, ErrDependencyUnavailable) {
|
|
t.Fatalf("SubmitReturn() error = %v, want ErrDependencyUnavailable", err)
|
|
}
|
|
}
|
|
|
|
func TestServiceSubmitReturnWithEmptyContent(t *testing.T) {
|
|
svc := &Service{repo: &Repository{}}
|
|
_, err := svc.SubmitReturn(t.Context(), 1, 100, SubmitReturnRequest{Content: ""})
|
|
if !errors.Is(err, ErrOrderCannotReturn) {
|
|
t.Fatalf("SubmitReturn() error = %v, want ErrOrderCannotReturn", err)
|
|
}
|
|
}
|
|
|
|
func TestServiceSubmitCheckoutWithNilRepo(t *testing.T) {
|
|
svc := &Service{repo: nil}
|
|
_, err := svc.SubmitCheckout(t.Context(), 1, 100, SubmitCheckoutRequest{Content: "test"})
|
|
if !errors.Is(err, ErrDependencyUnavailable) {
|
|
t.Fatalf("SubmitCheckout() error = %v, want ErrDependencyUnavailable", err)
|
|
}
|
|
}
|