Files
cmroubao/backend-api/internal/transport/webui/preflight_error_test.go
T

46 lines
1.4 KiB
Go

package webui
import (
"errors"
"testing"
"cmroubao/backend-api/internal/domain"
)
func TestMapFreightPreflightErrorUsesStablePublicErrors(t *testing.T) {
testCases := []struct {
err error
want error
}{
{domain.ErrFreightSourceOCRInvalid, ErrOCRServiceInvalid},
{domain.ErrFreightSourceNotConfigured, ErrERPNotConfigured},
{domain.ErrFreightSourceLoginRejected, ErrERPLoginRejected},
{domain.ErrFreightSourceProtocol, ErrERPProtocol},
{domain.ErrFreightSourceUnavailable, ErrERPUnavailable},
}
for _, testCase := range testCases {
actual := mapFreightPreflightError(testCase.err)
if !errors.Is(actual, testCase.want) || !errors.Is(actual, testCase.err) {
t.Fatalf("mapFreightPreflightError(%v) = %v", testCase.err, actual)
}
}
}
func TestMapFreightCreateErrorPreservesPreflightErrors(t *testing.T) {
for _, testCase := range []struct {
err error
want error
}{
{domain.ErrFreightSourceOCRInvalid, ErrOCRServiceInvalid},
{domain.ErrFreightSourceNotConfigured, ErrERPNotConfigured},
{domain.ErrFreightSourceLoginRejected, ErrERPLoginRejected},
{domain.ErrFreightSourceProtocol, ErrERPProtocol},
{domain.ErrFreightSourceUnavailable, ErrERPUnavailable},
} {
actual := mapFreightCreateError(testCase.err)
if !errors.Is(actual, testCase.want) || !errors.Is(actual, testCase.err) {
t.Fatalf("mapFreightCreateError(%v) = %v", testCase.err, actual)
}
}
}