This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gl/domain/ledger"
|
||||
@@ -14,6 +15,15 @@ type EnqueueRepository interface {
|
||||
Enqueue(context.Context, ledger.Settlement) (ledger.Settlement, bool, error)
|
||||
Get(context.Context, string, string) (ledger.Settlement, error)
|
||||
RetryByOperator(context.Context, string, string, string, time.Time) (ledger.Settlement, error)
|
||||
IgnoreByOperator(context.Context, string, string, string) (ledger.Settlement, error)
|
||||
}
|
||||
|
||||
func (s *Service) IgnoreByOperator(ctx context.Context, settlementID, actorID, reason string) (ledger.Settlement, error) {
|
||||
settlementID, actorID, reason = strings.TrimSpace(settlementID), strings.TrimSpace(actorID), strings.TrimSpace(reason)
|
||||
if settlementID == "" || actorID == "" || reason == "" || len([]rune(reason)) > 500 {
|
||||
return ledger.Settlement{}, fmt.Errorf("settlement id, actor id, and a reason of at most 500 characters are required")
|
||||
}
|
||||
return s.repository.IgnoreByOperator(ctx, settlementID, actorID, reason)
|
||||
}
|
||||
|
||||
func (s *Service) RetryByOperator(ctx context.Context, settlementID, actorID, reason string) (ledger.Settlement, error) {
|
||||
|
||||
@@ -23,6 +23,28 @@ func (r *serviceRepository) RetryByOperator(_ context.Context, id, actor, reason
|
||||
return ledger.Settlement{ID: id, Status: ledger.SettlementRetryable}, nil
|
||||
}
|
||||
|
||||
func (r *serviceRepository) IgnoreByOperator(_ context.Context, id, actor, reason string) (ledger.Settlement, error) {
|
||||
r.retriedID, r.actor, r.reason = id, actor, reason
|
||||
return ledger.Settlement{ID: id, Status: ledger.SettlementIgnored}, nil
|
||||
}
|
||||
|
||||
func TestIgnoreByOperatorRequiresReviewedAuditIdentity(t *testing.T) {
|
||||
repository := &serviceRepository{}
|
||||
service := NewService(repository)
|
||||
for _, reason := range []string{"", " "} {
|
||||
if _, err := service.IgnoreByOperator(context.Background(), "id", "actor", reason); err == nil {
|
||||
t.Fatal("expected blank review reason to be rejected")
|
||||
}
|
||||
}
|
||||
if repository.retriedID != "" {
|
||||
t.Fatal("invalid dismissal reached repository")
|
||||
}
|
||||
got, err := service.IgnoreByOperator(context.Background(), "id", "actor-7", " cannot complete ")
|
||||
if err != nil || got.Status != ledger.SettlementIgnored || repository.actor != "actor-7" || repository.reason != "cannot complete" {
|
||||
t.Fatalf("unexpected dismissal: %+v repo=%+v err=%v", got, repository, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRetryByOperatorRequiresCompleteAuditIdentity(t *testing.T) {
|
||||
service := NewService(&serviceRepository{})
|
||||
if _, err := service.RetryByOperator(context.Background(), "id", "actor", ""); err == nil {
|
||||
|
||||
Reference in New Issue
Block a user