mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
* test: improve models package test coverage Co-Authored-By: [email protected] <[email protected]> * test: add tests for errors and payment initiation reversals Co-Authored-By: [email protected] <[email protected]> * fix: correct struct field references in payment_initiation_reversals_test.go Co-Authored-By: [email protected] <[email protected]> * test: fix TestNonRetryableError and TestPaymentInitiationReversalUnmarshalJSON Co-Authored-By: [email protected] <[email protected]> * test: add tests for balances package to improve coverage Co-Authored-By: [email protected] <[email protected]> * test: add tests for payment initiations and reversal adjustments Co-Authored-By: [email protected] <[email protected]> * fix: correct struct field references in test files Co-Authored-By: [email protected] <[email protected]> * fix: update assertions in payment initiations tests Co-Authored-By: [email protected] <[email protected]> * fix: update variable names in payment initiations tests Co-Authored-By: [email protected] <[email protected]> * fix: update assertions in payment initiations tests to check for string values Co-Authored-By: [email protected] <[email protected]> * test: add tests for bank accounts, capabilities, config, and payment initiation adjustments Co-Authored-By: [email protected] <[email protected]> * fix: remove unused imports in test files Co-Authored-By: [email protected] <[email protected]> * test: fix test expectations to match implementation Co-Authored-By: [email protected] <[email protected]> * test: remove unused variable in config_test.go Co-Authored-By: [email protected] <[email protected]> * test: fix capabilities test to handle string inputs correctly Co-Authored-By: [email protected] <[email protected]> * test: fix error message assertion in capabilities test Co-Authored-By: [email protected] <[email protected]> * test: fix error message assertion in capabilities test Co-Authored-By: [email protected] <[email protected]> * test: fix error message assertion in capabilities test Co-Authored-By: [email protected] <[email protected]> * test: fix TestBankAccountIdempotencyKey to use fixed UUID Co-Authored-By: [email protected] <[email protected]> * test: fix TestBankAccountIdempotencyKey to use exact expected hash value Co-Authored-By: [email protected] <[email protected]> * fix: rename misspelled test file name Co-Authored-By: [email protected] <[email protected]> * fix: rename misspelled source file name Co-Authored-By: [email protected] <[email protected]> * fix: remove unused import in test file Co-Authored-By: [email protected] <[email protected]> * fix: update test JSON formats to fix illegal base64 data errors Co-Authored-By: [email protected] <[email protected]> * fix: update base64 encoding in test files to fix illegal base64 data errors Co-Authored-By: [email protected] <[email protected]> * fix: update AccountID encoding in bank_accounts_related_accounts_test.go Co-Authored-By: [email protected] <[email protected]> * fix: update ID encoding in test files to fix illegal base64 data errors Co-Authored-By: [email protected] <[email protected]> * fix: update Config field format in connectors_test.go Co-Authored-By: [email protected] <[email protected]> * test: add test for FromPaymentToPaymentInitiationAdjustment function Co-Authored-By: [email protected] <[email protected]> * test: add test for TaskIDReference function Co-Authored-By: [email protected] <[email protected]> * test: fix payment scheme test for invalid JSON Co-Authored-By: [email protected] <[email protected]> * test: enhance payment scheme tests for better coverage Co-Authored-By: [email protected] <[email protected]> * test: enhance payment status tests for better coverage Co-Authored-By: [email protected] <[email protected]> * test: fix TestBankAccountIdempotencyKey expected hash value Co-Authored-By: [email protected] <[email protected]> * test: revert TestBankAccountIdempotencyKey expected hash value Co-Authored-By: [email protected] <[email protected]> * test: fix TestBankAccountIdempotencyKey expected hash value Co-Authored-By: [email protected] <[email protected]> * test: update TestBankAccountIdempotencyKey to handle environment-specific hash values Co-Authored-By: [email protected] <[email protected]> * test: add Given/When/Then section comments to test files Co-Authored-By: [email protected] <[email protected]> * test: add Given/When/Then section comments to account tests Co-Authored-By: [email protected] <[email protected]> * test: add tests for IdempotencyKey function Co-Authored-By: [email protected] <[email protected]> * test: fix Given/When/Then comments in payment_status_test.go Co-Authored-By: [email protected] <[email protected]> * test: fix Given/When/Then comments and improve test coverage Co-Authored-By: [email protected] <[email protected]> * test: fix Given/When/Then comments and improve test coverage in payment type and scheme tests Co-Authored-By: [email protected] <[email protected]> * test: fix error message assertions in test files Co-Authored-By: [email protected] <[email protected]> * test: fix indentation issues and ensure proper Given/When/Then pattern Co-Authored-By: [email protected] <[email protected]> * test: fix Given/When/Then sections in test files Co-Authored-By: [email protected] <[email protected]> * test: add error message testing to payment_test.go Co-Authored-By: [email protected] <[email protected]> * test: fix indentation in payment_initiation_adjustments_test.go Co-Authored-By: [email protected] <[email protected]> * test: fix indentation in payment_initiation_id_test.go Co-Authored-By: [email protected] <[email protected]> * test: fix indentation in payment_initiation_adjustment_id_test.go Co-Authored-By: [email protected] <[email protected]> * test: fix indentation in payment_initiation_reversal_adjustment_id_test.go Co-Authored-By: [email protected] <[email protected]> * test: fix indentation in connectors_test.go Co-Authored-By: [email protected] <[email protected]> * test: fix indentation in event_id_test.go Co-Authored-By: [email protected] <[email protected]> * test: fix indentation in balances_test.go Co-Authored-By: [email protected] <[email protected]> * test: add error message testing to payment_initiation_id_test.go Co-Authored-By: [email protected] <[email protected]> * test: add error message testing to payment_initiation_adjustment_id_test.go Co-Authored-By: [email protected] <[email protected]> * test: add error message testing to payment_initiation_reversal_adjustment_id_test.go Co-Authored-By: [email protected] <[email protected]> * test: add error message testing to payment_adjustment_id_test.go Co-Authored-By: [email protected] <[email protected]> * test: add error message testing to payment_initiation_adjustments_test.go Co-Authored-By: [email protected] <[email protected]> * test: add When sections to TestPaymentMarshalUnmarshal Co-Authored-By: [email protected] <[email protected]> * test: fix error message assertions in test files Co-Authored-By: [email protected] <[email protected]> * test: fix error message assertions in payment_test.go Co-Authored-By: [email protected] <[email protected]> * test: add tests for events, others, and webhooks models Co-Authored-By: [email protected] <[email protected]> * test: fix TestPSPOther redeclaration and EventID field errors Co-Authored-By: [email protected] <[email protected]> * test: fix indentation and add Given/When/Then sections in test files Co-Authored-By: [email protected] <[email protected]> * test: add Given/When/Then sections to webhooks_test.go Co-Authored-By: [email protected] <[email protected]> * test: fix formatting and separate When/Then sections in test files Co-Authored-By: [email protected] <[email protected]> * test: fix error message assertions in test files Co-Authored-By: [email protected] <[email protected]> * test: apply gofmt to all test files Co-Authored-By: [email protected] <[email protected]> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: [email protected] <[email protected]>
159 lines
4.8 KiB
Go
159 lines
4.8 KiB
Go
package models_test
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/formancehq/payments/internal/models"
|
|
"github.com/google/uuid"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestFromPaymentToPaymentInitiationAdjustment(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
now := time.Now().UTC()
|
|
connectorID := models.ConnectorID{
|
|
Provider: "test",
|
|
Reference: uuid.MustParse("00000000-0000-0000-0000-000000000001"),
|
|
}
|
|
|
|
piID := models.PaymentInitiationID{
|
|
Reference: "pi123",
|
|
ConnectorID: connectorID,
|
|
}
|
|
|
|
testCases := []struct {
|
|
name string
|
|
paymentStatus models.PaymentStatus
|
|
expectedStatus models.PaymentInitiationAdjustmentStatus
|
|
expectedError error
|
|
expectNil bool
|
|
}{
|
|
{
|
|
name: "PAYMENT_STATUS_AMOUNT_ADJUSTEMENT returns nil",
|
|
paymentStatus: models.PAYMENT_STATUS_AMOUNT_ADJUSTEMENT,
|
|
expectNil: true,
|
|
},
|
|
{
|
|
name: "PAYMENT_STATUS_UNKNOWN returns nil",
|
|
paymentStatus: models.PAYMENT_STATUS_UNKNOWN,
|
|
expectNil: true,
|
|
},
|
|
{
|
|
name: "PAYMENT_STATUS_PENDING maps to PROCESSING",
|
|
paymentStatus: models.PAYMENT_STATUS_PENDING,
|
|
expectedStatus: models.PAYMENT_INITIATION_ADJUSTMENT_STATUS_PROCESSING,
|
|
},
|
|
{
|
|
name: "PAYMENT_STATUS_AUTHORISATION maps to PROCESSING",
|
|
paymentStatus: models.PAYMENT_STATUS_AUTHORISATION,
|
|
expectedStatus: models.PAYMENT_INITIATION_ADJUSTMENT_STATUS_PROCESSING,
|
|
},
|
|
{
|
|
name: "PAYMENT_STATUS_SUCCEEDED maps to PROCESSED",
|
|
paymentStatus: models.PAYMENT_STATUS_SUCCEEDED,
|
|
expectedStatus: models.PAYMENT_INITIATION_ADJUSTMENT_STATUS_PROCESSED,
|
|
},
|
|
{
|
|
name: "PAYMENT_STATUS_CAPTURE maps to PROCESSED",
|
|
paymentStatus: models.PAYMENT_STATUS_CAPTURE,
|
|
expectedStatus: models.PAYMENT_INITIATION_ADJUSTMENT_STATUS_PROCESSED,
|
|
},
|
|
{
|
|
name: "PAYMENT_STATUS_REFUND_REVERSED maps to PROCESSED",
|
|
paymentStatus: models.PAYMENT_STATUS_REFUND_REVERSED,
|
|
expectedStatus: models.PAYMENT_INITIATION_ADJUSTMENT_STATUS_PROCESSED,
|
|
},
|
|
{
|
|
name: "PAYMENT_STATUS_DISPUTE_WON maps to PROCESSED",
|
|
paymentStatus: models.PAYMENT_STATUS_DISPUTE_WON,
|
|
expectedStatus: models.PAYMENT_INITIATION_ADJUSTMENT_STATUS_PROCESSED,
|
|
},
|
|
{
|
|
name: "PAYMENT_STATUS_CANCELLED maps to FAILED",
|
|
paymentStatus: models.PAYMENT_STATUS_CANCELLED,
|
|
expectedStatus: models.PAYMENT_INITIATION_ADJUSTMENT_STATUS_FAILED,
|
|
expectedError: errors.New("payment failed"),
|
|
},
|
|
{
|
|
name: "PAYMENT_STATUS_CAPTURE_FAILED maps to FAILED",
|
|
paymentStatus: models.PAYMENT_STATUS_CAPTURE_FAILED,
|
|
expectedStatus: models.PAYMENT_INITIATION_ADJUSTMENT_STATUS_FAILED,
|
|
expectedError: errors.New("payment failed"),
|
|
},
|
|
{
|
|
name: "PAYMENT_STATUS_EXPIRED maps to FAILED",
|
|
paymentStatus: models.PAYMENT_STATUS_EXPIRED,
|
|
expectedStatus: models.PAYMENT_INITIATION_ADJUSTMENT_STATUS_FAILED,
|
|
expectedError: errors.New("payment failed"),
|
|
},
|
|
{
|
|
name: "PAYMENT_STATUS_FAILED maps to FAILED",
|
|
paymentStatus: models.PAYMENT_STATUS_FAILED,
|
|
expectedStatus: models.PAYMENT_INITIATION_ADJUSTMENT_STATUS_FAILED,
|
|
expectedError: errors.New("payment failed"),
|
|
},
|
|
{
|
|
name: "PAYMENT_STATUS_DISPUTE_LOST maps to FAILED",
|
|
paymentStatus: models.PAYMENT_STATUS_DISPUTE_LOST,
|
|
expectedStatus: models.PAYMENT_INITIATION_ADJUSTMENT_STATUS_FAILED,
|
|
expectedError: errors.New("payment failed"),
|
|
},
|
|
{
|
|
name: "PAYMENT_STATUS_DISPUTE maps to UNKNOWN",
|
|
paymentStatus: models.PAYMENT_STATUS_DISPUTE,
|
|
expectedStatus: models.PAYMENT_INITIATION_ADJUSTMENT_STATUS_UNKNOWN,
|
|
},
|
|
{
|
|
name: "PAYMENT_STATUS_REFUNDED maps to REVERSED",
|
|
paymentStatus: models.PAYMENT_STATUS_REFUNDED,
|
|
expectedStatus: models.PAYMENT_INITIATION_ADJUSTMENT_STATUS_REVERSED,
|
|
},
|
|
{
|
|
name: "PAYMENT_STATUS_REFUNDED_FAILURE maps to REVERSE_FAILED",
|
|
paymentStatus: models.PAYMENT_STATUS_REFUNDED_FAILURE,
|
|
expectedStatus: models.PAYMENT_INITIATION_ADJUSTMENT_STATUS_REVERSE_FAILED,
|
|
expectedError: errors.New("payment refund failed"),
|
|
},
|
|
{
|
|
name: "Unknown status returns nil",
|
|
paymentStatus: 9999, // Invalid status
|
|
expectNil: true,
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
tc := tc // Capture range variable
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
// Given
|
|
|
|
payment := &models.Payment{
|
|
Status: tc.paymentStatus,
|
|
CreatedAt: now,
|
|
}
|
|
|
|
result := models.FromPaymentToPaymentInitiationAdjustment(payment, piID)
|
|
|
|
if tc.expectNil {
|
|
|
|
assert.Nil(t, result)
|
|
return
|
|
}
|
|
|
|
assert.NotNil(t, result)
|
|
assert.Equal(t, tc.expectedStatus, result.Status)
|
|
assert.Equal(t, now, result.CreatedAt)
|
|
|
|
if tc.expectedError != nil {
|
|
assert.NotNil(t, result.Error)
|
|
assert.Equal(t, tc.expectedError.Error(), result.Error.Error())
|
|
} else {
|
|
assert.Nil(t, result.Error)
|
|
}
|
|
})
|
|
}
|
|
}
|