Skip to content

Commit 550c601

Browse files
committed
fix: address review feedback on InstrumentAmount migration
- Add round-trip assertions for PostingAmount fields in serialization test - Deduplicate cents-to-InstrumentAmount conversion in grpc_lifecycle.go to use shared buildPostingAmount helper
1 parent 94e8691 commit 550c601

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

services/payment-order/service/grpc_lifecycle.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -420,14 +420,7 @@ func (s *Service) reverseLedgerPosting(ctx context.Context, po *domain.PaymentOr
420420

421421
// Convert amount to InstrumentAmount format
422422
amountCents := domain.ToMinorUnits(po.Amount)
423-
majorUnits := amountCents / 100
424-
minorUnits := amountCents % 100
425-
amountStr := fmt.Sprintf("%d.%02d", majorUnits, minorUnits)
426-
postingAmount := &quantityv1.InstrumentAmount{
427-
Amount: amountStr,
428-
InstrumentCode: currencyCode,
429-
Version: 1,
430-
}
423+
postingAmount := buildPostingAmount(currencyCode, amountCents)
431424
valueDate := timestamppb.Now()
432425

433426
// Steps 2-3: Create CREDIT and DEBIT reversal postings

tests/proto/serialization_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,18 @@ func TestProtoSerialization(t *testing.T) {
9696
if decoded.PostingDirection != original.PostingDirection {
9797
t.Errorf("posting_direction mismatch: got %v, want %v", decoded.PostingDirection, original.PostingDirection)
9898
}
99+
if decoded.PostingAmount == nil {
100+
t.Fatal("posting_amount mismatch: got nil, want non-nil")
101+
}
102+
if decoded.PostingAmount.Amount != original.PostingAmount.Amount {
103+
t.Errorf("posting_amount.amount mismatch: got %v, want %v", decoded.PostingAmount.Amount, original.PostingAmount.Amount)
104+
}
105+
if decoded.PostingAmount.InstrumentCode != original.PostingAmount.InstrumentCode {
106+
t.Errorf("posting_amount.instrument_code mismatch: got %v, want %v", decoded.PostingAmount.InstrumentCode, original.PostingAmount.InstrumentCode)
107+
}
108+
if decoded.PostingAmount.Version != original.PostingAmount.Version {
109+
t.Errorf("posting_amount.version mismatch: got %v, want %v", decoded.PostingAmount.Version, original.PostingAmount.Version)
110+
}
99111
})
100112

101113
t.Run("Event message serialization", func(t *testing.T) {

0 commit comments

Comments
 (0)