Files
GL/application/settlement/service_test.go
T

44 lines
1.4 KiB
Go

package settlement
import (
"context"
"testing"
"time"
"gl/domain/ledger"
)
type serviceRepository struct {
retriedID, actor, reason string
}
func (*serviceRepository) Enqueue(context.Context, ledger.Settlement) (ledger.Settlement, bool, error) {
return ledger.Settlement{}, false, nil
}
func (*serviceRepository) Get(context.Context, string, string) (ledger.Settlement, error) {
return ledger.Settlement{}, nil
}
func (r *serviceRepository) RetryByOperator(_ context.Context, id, actor, reason string, _ time.Time) (ledger.Settlement, error) {
r.retriedID, r.actor, r.reason = id, actor, reason
return ledger.Settlement{ID: id, Status: ledger.SettlementRetryable}, nil
}
func TestRetryByOperatorRequiresCompleteAuditIdentity(t *testing.T) {
service := NewService(&serviceRepository{})
if _, err := service.RetryByOperator(context.Background(), "id", "actor", ""); err == nil {
t.Fatal("expected missing reason to be rejected")
}
}
func TestRetryByOperatorPassesActorAndReasonToRepository(t *testing.T) {
repository := &serviceRepository{}
service := NewService(repository)
got, err := service.RetryByOperator(context.Background(), "id", "actor-7", "Horizon outage resolved")
if err != nil {
t.Fatal(err)
}
if got.Status != ledger.SettlementRetryable || repository.retriedID != "id" || repository.actor != "actor-7" || repository.reason != "Horizon outage resolved" {
t.Fatalf("unexpected retry: %+v repo=%+v", got, repository)
}
}