gw <-> po contracts tests

This commit is contained in:
Stephan D
2026-03-06 15:45:14 +01:00
parent 0f42a0e77f
commit 88b279dd78
13 changed files with 354 additions and 12 deletions

View File

@@ -0,0 +1,144 @@
package client
import (
"context"
"testing"
connectorv1 "github.com/tech/sendico/pkg/proto/connector/v1"
mntxv1 "github.com/tech/sendico/pkg/proto/gateway/mntx/v1"
"google.golang.org/grpc"
)
type stubConnectorClient struct {
submitReq *connectorv1.SubmitOperationRequest
getReq *connectorv1.GetOperationRequest
submitResp *connectorv1.SubmitOperationResponse
getResp *connectorv1.GetOperationResponse
}
func (s *stubConnectorClient) SubmitOperation(_ context.Context, in *connectorv1.SubmitOperationRequest, _ ...grpc.CallOption) (*connectorv1.SubmitOperationResponse, error) {
s.submitReq = in
if s.submitResp != nil {
return s.submitResp, nil
}
return &connectorv1.SubmitOperationResponse{}, nil
}
func (s *stubConnectorClient) GetOperation(_ context.Context, in *connectorv1.GetOperationRequest, _ ...grpc.CallOption) (*connectorv1.GetOperationResponse, error) {
s.getReq = in
if s.getResp != nil {
return s.getResp, nil
}
return &connectorv1.GetOperationResponse{}, nil
}
func TestCreateCardPayout_UsesOperationRefIdentity(t *testing.T) {
stub := &stubConnectorClient{
submitResp: &connectorv1.SubmitOperationResponse{
Receipt: &connectorv1.OperationReceipt{
OperationId: "payment-1:hop_4_card_payout_send",
Status: connectorv1.OperationStatus_OPERATION_WAITING,
ProviderRef: "provider-1",
},
},
}
client := &gatewayClient{client: stub, cfg: Config{}}
resp, err := client.CreateCardPayout(context.Background(), &mntxv1.CardPayoutRequest{
PayoutId: "payout-legacy-id",
OperationRef: "payment-1:hop_4_card_payout_send",
IdempotencyKey: "",
AmountMinor: 12345,
Currency: "RUB",
})
if err != nil {
t.Fatalf("CreateCardPayout returned error: %v", err)
}
if resp.GetPayout() == nil {
t.Fatal("expected payout")
}
if got, want := resp.GetPayout().GetPayoutId(), "payment-1:hop_4_card_payout_send"; got != want {
t.Fatalf("payout_id mismatch: got=%q want=%q", got, want)
}
if stub.submitReq == nil || stub.submitReq.GetOperation() == nil {
t.Fatal("expected submitted operation")
}
if got, want := stub.submitReq.GetOperation().GetOperationRef(), "payment-1:hop_4_card_payout_send"; got != want {
t.Fatalf("operation_ref mismatch: got=%q want=%q", got, want)
}
if got, want := stub.submitReq.GetOperation().GetIdempotencyKey(), "payment-1:hop_4_card_payout_send"; got != want {
t.Fatalf("idempotency_key mismatch: got=%q want=%q", got, want)
}
}
func TestGetCardPayoutStatus_UsesPayoutIDAsOperationID(t *testing.T) {
stub := &stubConnectorClient{
getResp: &connectorv1.GetOperationResponse{
Operation: &connectorv1.Operation{
OperationId: "payment-2:hop_4_card_payout_send",
Status: connectorv1.OperationStatus_OPERATION_PROCESSING,
},
},
}
client := &gatewayClient{client: stub, cfg: Config{}}
resp, err := client.GetCardPayoutStatus(context.Background(), &mntxv1.GetCardPayoutStatusRequest{
PayoutId: "payment-2:hop_4_card_payout_send",
})
if err != nil {
t.Fatalf("GetCardPayoutStatus returned error: %v", err)
}
if stub.getReq == nil {
t.Fatal("expected get operation request")
}
if got, want := stub.getReq.GetOperationId(), "payment-2:hop_4_card_payout_send"; got != want {
t.Fatalf("operation_id mismatch: got=%q want=%q", got, want)
}
if resp.GetPayout() == nil {
t.Fatal("expected payout")
}
if got, want := resp.GetPayout().GetPayoutId(), "payment-2:hop_4_card_payout_send"; got != want {
t.Fatalf("payout_id mismatch: got=%q want=%q", got, want)
}
}
func TestCreateCardTokenPayout_UsesOperationRefWhenReceiptOperationIDMissing(t *testing.T) {
stub := &stubConnectorClient{
submitResp: &connectorv1.SubmitOperationResponse{
Receipt: &connectorv1.OperationReceipt{
OperationId: "",
Status: connectorv1.OperationStatus_OPERATION_PROCESSING,
ProviderRef: "provider-2",
},
},
}
client := &gatewayClient{client: stub, cfg: Config{}}
resp, err := client.CreateCardTokenPayout(context.Background(), &mntxv1.CardTokenPayoutRequest{
PayoutId: "legacy-payout-id",
OperationRef: "payment-3:hop_4_card_payout_send_2",
IdempotencyKey: "",
AmountMinor: 777,
Currency: "RUB",
CardToken: "tok_123",
})
if err != nil {
t.Fatalf("CreateCardTokenPayout returned error: %v", err)
}
if stub.submitReq == nil || stub.submitReq.GetOperation() == nil {
t.Fatal("expected submitted operation")
}
if got, want := stub.submitReq.GetOperation().GetOperationRef(), "payment-3:hop_4_card_payout_send_2"; got != want {
t.Fatalf("operation_ref mismatch: got=%q want=%q", got, want)
}
if got, want := stub.submitReq.GetOperation().GetIdempotencyKey(), "payment-3:hop_4_card_payout_send_2"; got != want {
t.Fatalf("idempotency_key mismatch: got=%q want=%q", got, want)
}
if resp.GetPayout() == nil {
t.Fatal("expected payout")
}
if got, want := resp.GetPayout().GetPayoutId(), "payment-3:hop_4_card_payout_send_2"; got != want {
t.Fatalf("payout_id mismatch: got=%q want=%q", got, want)
}
}

View File

@@ -15,7 +15,7 @@ require (
github.com/tech/sendico/pkg v0.1.0
go.mongodb.org/mongo-driver/v2 v2.5.0
go.uber.org/zap v1.27.1
google.golang.org/grpc v1.79.1
google.golang.org/grpc v1.79.2
google.golang.org/protobuf v1.36.11
gopkg.in/yaml.v3 v3.0.1
)

View File

@@ -212,8 +212,8 @@ gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260226221140-a57be14db171 h1:ggcbiqK8WWh6l1dnltU4BgWGIGo+EVYxCaAPih/zQXQ=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260226221140-a57be14db171/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8=
google.golang.org/grpc v1.79.1 h1:zGhSi45ODB9/p3VAawt9a+O/MULLl9dpizzNNpq7flY=
google.golang.org/grpc v1.79.1/go.mod h1:KmT0Kjez+0dde/v2j9vzwoAScgEPx/Bw1CYChhHLrHQ=
google.golang.org/grpc v1.79.2 h1:fRMD94s2tITpyJGtBBn7MkMseNpOZU8ZxgC3MMBaXRU=
google.golang.org/grpc v1.79.2/go.mod h1:KmT0Kjez+0dde/v2j9vzwoAScgEPx/Bw1CYChhHLrHQ=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=