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]>
203 lines
4.1 KiB
Go
203 lines
4.1 KiB
Go
package models_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/formancehq/payments/internal/models"
|
|
"github.com/google/uuid"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestConnectorID(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
t.Run("String", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
// Given
|
|
id := models.ConnectorID{
|
|
Provider: "stripe",
|
|
Reference: uuid.MustParse("00000000-0000-0000-0000-000000000001"),
|
|
}
|
|
|
|
// When
|
|
result := id.String()
|
|
|
|
// Then
|
|
assert.NotEmpty(t, result)
|
|
decoded, err := models.ConnectorIDFromString(result)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, id.Provider, decoded.Provider)
|
|
assert.Equal(t, id.Reference, decoded.Reference)
|
|
})
|
|
|
|
t.Run("ConnectorIDFromString", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
t.Run("valid ID", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
// Given
|
|
original := models.ConnectorID{
|
|
Provider: "stripe",
|
|
Reference: uuid.MustParse("00000000-0000-0000-0000-000000000001"),
|
|
}
|
|
idStr := original.String()
|
|
|
|
// When
|
|
id, err := models.ConnectorIDFromString(idStr)
|
|
|
|
// Then
|
|
require.NoError(t, err)
|
|
assert.Equal(t, original.Provider, id.Provider)
|
|
assert.Equal(t, original.Reference.String(), id.Reference.String())
|
|
})
|
|
|
|
t.Run("illegal base64", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
// Given
|
|
invalidStr := "invalid-format"
|
|
|
|
// When
|
|
_, err := models.ConnectorIDFromString(invalidStr)
|
|
|
|
// Then
|
|
assert.Error(t, err)
|
|
assert.Contains(t, err.Error(), "invalid character")
|
|
})
|
|
|
|
t.Run("invalid JSON", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
// Given
|
|
invalidJSON := "eyJQcm92aWRlciI6InN0cmlwZSJ9" // Base64 of {"Provider":"stripe"} - missing Reference field
|
|
|
|
// When
|
|
id, err := models.ConnectorIDFromString(invalidJSON)
|
|
|
|
// Then
|
|
assert.Equal(t, models.ConnectorID{Provider: "stripe"}, id)
|
|
assert.NoError(t, err)
|
|
})
|
|
|
|
t.Run("empty string", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
// Given
|
|
emptyStr := ""
|
|
|
|
// When
|
|
_, err := models.ConnectorIDFromString(emptyStr)
|
|
|
|
// Then
|
|
assert.Error(t, err)
|
|
assert.Contains(t, err.Error(), "JSON input")
|
|
})
|
|
})
|
|
|
|
t.Run("MustConnectorIDFromString", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
// Given
|
|
original := models.ConnectorID{
|
|
Provider: "stripe",
|
|
Reference: uuid.MustParse("00000000-0000-0000-0000-000000000001"),
|
|
}
|
|
idStr := original.String()
|
|
|
|
// When
|
|
id := models.MustConnectorIDFromString(idStr)
|
|
|
|
// Then
|
|
assert.Equal(t, original.Provider, id.Provider)
|
|
assert.Equal(t, original.Reference.String(), id.Reference.String())
|
|
})
|
|
|
|
t.Run("Value", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
// Given
|
|
id := models.ConnectorID{
|
|
Provider: "stripe",
|
|
Reference: uuid.MustParse("00000000-0000-0000-0000-000000000001"),
|
|
}
|
|
|
|
// When
|
|
val, err := id.Value()
|
|
|
|
// Then
|
|
require.NoError(t, err)
|
|
assert.Equal(t, id.String(), val)
|
|
})
|
|
|
|
t.Run("Scan", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
t.Run("valid string", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
// Given
|
|
original := models.ConnectorID{
|
|
Provider: "stripe",
|
|
Reference: uuid.MustParse("00000000-0000-0000-0000-000000000001"),
|
|
}
|
|
idStr := original.String()
|
|
var id1 models.ConnectorID
|
|
|
|
// When
|
|
err := id1.Scan(idStr)
|
|
|
|
// Then
|
|
require.NoError(t, err)
|
|
assert.Equal(t, original.Provider, id1.Provider)
|
|
assert.Equal(t, original.Reference.String(), id1.Reference.String())
|
|
})
|
|
|
|
t.Run("invalid type", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
// Given
|
|
var id2 models.ConnectorID
|
|
invalidValue := 123
|
|
|
|
// When
|
|
err := id2.Scan(invalidValue)
|
|
|
|
// Then
|
|
assert.Error(t, err)
|
|
assert.Contains(t, err.Error(), "failed to parse connector id")
|
|
})
|
|
|
|
t.Run("illegal base64", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
// Given
|
|
var id3 models.ConnectorID
|
|
invalidStr := "invalid-format"
|
|
|
|
// When
|
|
err := id3.Scan(invalidStr)
|
|
|
|
// Then
|
|
assert.Error(t, err)
|
|
assert.Contains(t, err.Error(), "failed to parse connector id")
|
|
})
|
|
|
|
t.Run("nil value", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
// Given
|
|
var id4 models.ConnectorID
|
|
|
|
// When
|
|
err := id4.Scan(nil)
|
|
|
|
// Then
|
|
assert.Error(t, err)
|
|
assert.Contains(t, err.Error(), "connector id is nil")
|
|
})
|
|
})
|
|
}
|