feat(t237): import freight orders synchronously

This commit is contained in:
QiuSW
2026-07-29 12:11:56 +08:00
parent 4bce1e162c
commit 8d5b88f4a2
18 changed files with 653 additions and 97 deletions
@@ -5,6 +5,7 @@ import (
"testing"
"cmroubao/backend-api/internal/domain"
"cmroubao/backend-api/internal/usecase"
)
func TestMapFreightPreflightErrorUsesStablePublicErrors(t *testing.T) {
@@ -14,6 +15,8 @@ func TestMapFreightPreflightErrorUsesStablePublicErrors(t *testing.T) {
}{
{domain.ErrFreightSourceOCRInvalid, ErrOCRServiceInvalid},
{domain.ErrFreightSourceNotConfigured, ErrERPNotConfigured},
{domain.ErrFreightSourceSessionNeeded, ErrERPSessionNeeded},
{domain.ErrFreightSourceNotFound, ErrERPFreightNotFound},
{domain.ErrFreightSourceLoginRejected, ErrERPLoginRejected},
{domain.ErrFreightSourceProtocol, ErrERPProtocol},
{domain.ErrFreightSourceUnavailable, ErrERPUnavailable},
@@ -33,6 +36,8 @@ func TestMapFreightCreateErrorPreservesPreflightErrors(t *testing.T) {
}{
{domain.ErrFreightSourceOCRInvalid, ErrOCRServiceInvalid},
{domain.ErrFreightSourceNotConfigured, ErrERPNotConfigured},
{domain.ErrFreightSourceSessionNeeded, ErrERPSessionNeeded},
{domain.ErrFreightSourceNotFound, ErrERPFreightNotFound},
{domain.ErrFreightSourceLoginRejected, ErrERPLoginRejected},
{domain.ErrFreightSourceProtocol, ErrERPProtocol},
{domain.ErrFreightSourceUnavailable, ErrERPUnavailable},
@@ -43,3 +48,23 @@ func TestMapFreightCreateErrorPreservesPreflightErrors(t *testing.T) {
}
}
}
func TestMapFreightCreateErrorUsesStableSyncErrors(t *testing.T) {
for _, testCase := range []struct {
code string
want error
}{
{"FREIGHT_SYNC_BUSY", ErrFreightSyncBusy},
{"FREIGHT_SYNC_TIMEOUT", ErrFreightSyncTimeout},
} {
source := &usecase.Error{
Kind: usecase.ErrorKindUnavailable,
Code: testCase.code,
Fields: map[string]string{},
}
actual := mapFreightCreateError(source)
if !errors.Is(actual, testCase.want) || !errors.Is(actual, source) {
t.Fatalf("mapFreightCreateError(%s) = %v", testCase.code, actual)
}
}
}