move api/server to api/edge/bff
This commit is contained in:
136
api/edge/bff/interface/api/sresponse/payment_test.go
Normal file
136
api/edge/bff/interface/api/sresponse/payment_test.go
Normal file
@@ -0,0 +1,136 @@
|
||||
package sresponse
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
orchestrationv2 "github.com/tech/sendico/pkg/proto/payments/orchestration/v2"
|
||||
quotationv2 "github.com/tech/sendico/pkg/proto/payments/quotation/v2"
|
||||
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
|
||||
)
|
||||
|
||||
func TestToUserVisibleOperationsFiltersByVisibility(t *testing.T) {
|
||||
steps := []*orchestrationv2.StepExecution{
|
||||
{
|
||||
StepRef: "hidden",
|
||||
ReportVisibility: orchestrationv2.ReportVisibility_REPORT_VISIBILITY_HIDDEN,
|
||||
},
|
||||
{
|
||||
StepRef: "user",
|
||||
StepCode: "hop.4.card_payout.send",
|
||||
State: orchestrationv2.StepExecutionState_STEP_EXECUTION_STATE_RUNNING,
|
||||
ReportVisibility: orchestrationv2.ReportVisibility_REPORT_VISIBILITY_USER,
|
||||
},
|
||||
{
|
||||
StepRef: "unspecified",
|
||||
StepCode: "hop.4.card_payout.observe",
|
||||
State: orchestrationv2.StepExecutionState_STEP_EXECUTION_STATE_COMPLETED,
|
||||
ReportVisibility: orchestrationv2.ReportVisibility_REPORT_VISIBILITY_UNSPECIFIED,
|
||||
},
|
||||
{
|
||||
StepRef: "backoffice",
|
||||
ReportVisibility: orchestrationv2.ReportVisibility_REPORT_VISIBILITY_BACKOFFICE,
|
||||
},
|
||||
}
|
||||
|
||||
ops := toUserVisibleOperations(steps)
|
||||
if len(ops) != 2 {
|
||||
t.Fatalf("operations count mismatch: got=%d want=2", len(ops))
|
||||
}
|
||||
if got, want := ops[0].StepRef, "user"; got != want {
|
||||
t.Fatalf("first operation step_ref mismatch: got=%q want=%q", got, want)
|
||||
}
|
||||
if got, want := ops[1].StepRef, "unspecified"; got != want {
|
||||
t.Fatalf("second operation step_ref mismatch: got=%q want=%q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestToPaymentFailureUsesVisibleOperationsOnly(t *testing.T) {
|
||||
dto := toPayment(&orchestrationv2.Payment{
|
||||
PaymentRef: "pay-1",
|
||||
State: orchestrationv2.OrchestrationState_ORCHESTRATION_STATE_FAILED,
|
||||
StepExecutions: []*orchestrationv2.StepExecution{
|
||||
{
|
||||
StepRef: "hidden_failed",
|
||||
StepCode: "edge.1_2.ledger.debit",
|
||||
State: orchestrationv2.StepExecutionState_STEP_EXECUTION_STATE_FAILED,
|
||||
ReportVisibility: orchestrationv2.ReportVisibility_REPORT_VISIBILITY_HIDDEN,
|
||||
Failure: &orchestrationv2.Failure{
|
||||
Category: sharedv1.PaymentFailureCode_FAILURE_LEDGER,
|
||||
Message: "internal hold release failure",
|
||||
},
|
||||
},
|
||||
{
|
||||
StepRef: "user_failed",
|
||||
StepCode: "hop.4.card_payout.send",
|
||||
State: orchestrationv2.StepExecutionState_STEP_EXECUTION_STATE_FAILED,
|
||||
ReportVisibility: orchestrationv2.ReportVisibility_REPORT_VISIBILITY_USER,
|
||||
Failure: &orchestrationv2.Failure{
|
||||
Category: sharedv1.PaymentFailureCode_FAILURE_CHAIN,
|
||||
Message: "card declined",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
if dto == nil {
|
||||
t.Fatal("expected non-nil payment dto")
|
||||
}
|
||||
if got, want := dto.FailureCode, "failure_chain"; got != want {
|
||||
t.Fatalf("failure_code mismatch: got=%q want=%q", got, want)
|
||||
}
|
||||
if got, want := dto.FailureReason, "card declined"; got != want {
|
||||
t.Fatalf("failure_reason mismatch: got=%q want=%q", got, want)
|
||||
}
|
||||
if len(dto.Operations) != 1 {
|
||||
t.Fatalf("operations count mismatch: got=%d want=1", len(dto.Operations))
|
||||
}
|
||||
if got, want := dto.Operations[0].StepRef, "user_failed"; got != want {
|
||||
t.Fatalf("visible operation mismatch: got=%q want=%q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestToPaymentIgnoresHiddenFailures(t *testing.T) {
|
||||
dto := toPayment(&orchestrationv2.Payment{
|
||||
PaymentRef: "pay-2",
|
||||
State: orchestrationv2.OrchestrationState_ORCHESTRATION_STATE_FAILED,
|
||||
StepExecutions: []*orchestrationv2.StepExecution{
|
||||
{
|
||||
StepRef: "hidden_failed",
|
||||
StepCode: "edge.1_2.ledger.release",
|
||||
State: orchestrationv2.StepExecutionState_STEP_EXECUTION_STATE_FAILED,
|
||||
ReportVisibility: orchestrationv2.ReportVisibility_REPORT_VISIBILITY_BACKOFFICE,
|
||||
Failure: &orchestrationv2.Failure{
|
||||
Category: sharedv1.PaymentFailureCode_FAILURE_LEDGER,
|
||||
Message: "backoffice only failure",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
if dto == nil {
|
||||
t.Fatal("expected non-nil payment dto")
|
||||
}
|
||||
if got := dto.FailureCode; got != "" {
|
||||
t.Fatalf("expected empty failure_code, got=%q", got)
|
||||
}
|
||||
if got := dto.FailureReason; got != "" {
|
||||
t.Fatalf("expected empty failure_reason, got=%q", got)
|
||||
}
|
||||
if len(dto.Operations) != 0 {
|
||||
t.Fatalf("expected no visible operations, got=%d", len(dto.Operations))
|
||||
}
|
||||
}
|
||||
|
||||
func TestToPaymentQuote_MapsIntentRef(t *testing.T) {
|
||||
dto := toPaymentQuote("ationv2.PaymentQuote{
|
||||
QuoteRef: "quote-1",
|
||||
IntentRef: "intent-1",
|
||||
})
|
||||
if dto == nil {
|
||||
t.Fatal("expected non-nil quote dto")
|
||||
}
|
||||
if got, want := dto.QuoteRef, "quote-1"; got != want {
|
||||
t.Fatalf("quote_ref mismatch: got=%q want=%q", got, want)
|
||||
}
|
||||
if got, want := dto.IntentRef, "intent-1"; got != want {
|
||||
t.Fatalf("intent_ref mismatch: got=%q want=%q", got, want)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user