35 lines
1.1 KiB
Go
35 lines
1.1 KiB
Go
package domain_test
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"cmbuyer/admin/internal/domain"
|
|
)
|
|
|
|
func TestPurchaseAttemptTransitions(t *testing.T) {
|
|
for _, test := range []struct {
|
|
current domain.AttemptStatus
|
|
next domain.AttemptStatus
|
|
allowed bool
|
|
}{
|
|
{domain.AttemptStatusClaimed, domain.AttemptStatusOrdering, true},
|
|
{domain.AttemptStatusOrdering, domain.AttemptStatusFenced, true},
|
|
{domain.AttemptStatusOrdering, domain.AttemptStatusFailed, true},
|
|
{domain.AttemptStatusFenced, domain.AttemptStatusOrdering, false},
|
|
{domain.AttemptStatusFenced, domain.AttemptStatusAbandoned, false},
|
|
{domain.AttemptStatus("UNKNOWN"), domain.AttemptStatusOrdering, false},
|
|
} {
|
|
got, err := domain.TransitionAttempt(test.current, test.next)
|
|
if test.allowed {
|
|
if err != nil || got != test.next {
|
|
t.Fatalf("TransitionAttempt(%s, %s) = (%s, %v)", test.current, test.next, got, err)
|
|
}
|
|
continue
|
|
}
|
|
if !errors.Is(err, domain.ErrInvalidAttemptTransition) || got != test.current {
|
|
t.Fatalf("invalid TransitionAttempt(%s, %s) = (%s, %v)", test.current, test.next, got, err)
|
|
}
|
|
}
|
|
}
|