removed intent_ref from frontend
This commit is contained in:
@@ -107,9 +107,7 @@ func (r InitiatePayment) Validate() error {
|
||||
|
||||
type InitiatePayments struct {
|
||||
PaymentBase `json:",inline"`
|
||||
QuoteRef string `json:"quoteRef,omitempty"`
|
||||
IntentRef string `json:"intentRef,omitempty"`
|
||||
IntentRefs []string `json:"intentRefs,omitempty"`
|
||||
QuoteRef string `json:"quoteRef,omitempty"`
|
||||
}
|
||||
|
||||
func (r *InitiatePayments) Validate() error {
|
||||
@@ -120,35 +118,9 @@ func (r *InitiatePayments) Validate() error {
|
||||
return err
|
||||
}
|
||||
r.QuoteRef = strings.TrimSpace(r.QuoteRef)
|
||||
r.IntentRef = strings.TrimSpace(r.IntentRef)
|
||||
hasIntentRefsField := r.IntentRefs != nil
|
||||
|
||||
normalizedIntentRefs := make([]string, 0, len(r.IntentRefs))
|
||||
seen := make(map[string]struct{}, len(r.IntentRefs))
|
||||
for _, value := range r.IntentRefs {
|
||||
intentRef := strings.TrimSpace(value)
|
||||
if intentRef == "" {
|
||||
return merrors.InvalidArgument("intentRefs must not contain empty values", "intentRefs")
|
||||
}
|
||||
if _, exists := seen[intentRef]; exists {
|
||||
return merrors.InvalidArgument("intentRefs must contain unique values", "intentRefs")
|
||||
}
|
||||
seen[intentRef] = struct{}{}
|
||||
normalizedIntentRefs = append(normalizedIntentRefs, intentRef)
|
||||
}
|
||||
if hasIntentRefsField && len(normalizedIntentRefs) == 0 {
|
||||
return merrors.InvalidArgument("intentRefs must not be empty", "intentRefs")
|
||||
}
|
||||
r.IntentRefs = normalizedIntentRefs
|
||||
if len(r.IntentRefs) == 0 {
|
||||
r.IntentRefs = nil
|
||||
}
|
||||
|
||||
if r.QuoteRef == "" {
|
||||
return merrors.InvalidArgument("quoteRef is required", "quoteRef")
|
||||
}
|
||||
if r.IntentRef != "" && len(r.IntentRefs) > 0 {
|
||||
return merrors.DataConflict("intentRef and intentRefs are mutually exclusive")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -28,29 +28,11 @@ func TestValidateQuoteIdempotency(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestInitiatePaymentsValidateIntentSelectors(t *testing.T) {
|
||||
t.Run("accepts explicit intentRef", func(t *testing.T) {
|
||||
req := &InitiatePayments{
|
||||
PaymentBase: PaymentBase{IdempotencyKey: "idem-1"},
|
||||
QuoteRef: "quote-1",
|
||||
IntentRef: " intent-a ",
|
||||
}
|
||||
if err := req.Validate(); err != nil {
|
||||
t.Fatalf("expected no error, got %v", err)
|
||||
}
|
||||
if got, want := req.IntentRef, "intent-a"; got != want {
|
||||
t.Fatalf("intentRef mismatch: got=%q want=%q", got, want)
|
||||
}
|
||||
if req.IntentRefs != nil {
|
||||
t.Fatalf("expected nil intentRefs, got %#v", req.IntentRefs)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("accepts explicit intentRefs", func(t *testing.T) {
|
||||
func TestInitiatePaymentsValidate(t *testing.T) {
|
||||
t.Run("accepts quoteRef", func(t *testing.T) {
|
||||
req := &InitiatePayments{
|
||||
PaymentBase: PaymentBase{IdempotencyKey: "idem-1"},
|
||||
QuoteRef: " quote-1 ",
|
||||
IntentRefs: []string{" intent-a ", "intent-b"},
|
||||
}
|
||||
if err := req.Validate(); err != nil {
|
||||
t.Fatalf("expected no error, got %v", err)
|
||||
@@ -58,66 +40,14 @@ func TestInitiatePaymentsValidateIntentSelectors(t *testing.T) {
|
||||
if got, want := req.QuoteRef, "quote-1"; got != want {
|
||||
t.Fatalf("quoteRef mismatch: got=%q want=%q", got, want)
|
||||
}
|
||||
if got, want := len(req.IntentRefs), 2; got != want {
|
||||
t.Fatalf("intentRefs length mismatch: got=%d want=%d", got, want)
|
||||
}
|
||||
if got, want := req.IntentRefs[0], "intent-a"; got != want {
|
||||
t.Fatalf("intentRefs[0] mismatch: got=%q want=%q", got, want)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("rejects both intentRef and intentRefs", func(t *testing.T) {
|
||||
t.Run("rejects missing quoteRef", func(t *testing.T) {
|
||||
req := &InitiatePayments{
|
||||
PaymentBase: PaymentBase{IdempotencyKey: "idem-1"},
|
||||
QuoteRef: "quote-1",
|
||||
IntentRef: "intent-a",
|
||||
IntentRefs: []string{"intent-b"},
|
||||
}
|
||||
if err := req.Validate(); err == nil {
|
||||
t.Fatal("expected error")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("rejects empty intentRefs item", func(t *testing.T) {
|
||||
req := &InitiatePayments{
|
||||
PaymentBase: PaymentBase{IdempotencyKey: "idem-1"},
|
||||
QuoteRef: "quote-1",
|
||||
IntentRefs: []string{"intent-a", " "},
|
||||
}
|
||||
if err := req.Validate(); err == nil {
|
||||
t.Fatal("expected error")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("rejects empty intentRefs list", func(t *testing.T) {
|
||||
req := &InitiatePayments{
|
||||
PaymentBase: PaymentBase{IdempotencyKey: "idem-1"},
|
||||
QuoteRef: "quote-1",
|
||||
IntentRefs: []string{},
|
||||
}
|
||||
if err := req.Validate(); err == nil {
|
||||
t.Fatal("expected error")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("rejects duplicate intentRefs", func(t *testing.T) {
|
||||
req := &InitiatePayments{
|
||||
PaymentBase: PaymentBase{IdempotencyKey: "idem-1"},
|
||||
QuoteRef: "quote-1",
|
||||
IntentRefs: []string{"intent-a", " intent-a "},
|
||||
}
|
||||
if err := req.Validate(); err == nil {
|
||||
t.Fatal("expected error")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("accepts no selectors for backward compatibility", func(t *testing.T) {
|
||||
req := &InitiatePayments{
|
||||
PaymentBase: PaymentBase{IdempotencyKey: "idem-1"},
|
||||
QuoteRef: "quote-1",
|
||||
}
|
||||
if err := req.Validate(); err != nil {
|
||||
t.Fatalf("expected no error, got %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user