Files
payments/pkg/domain/models/conversion_status_test.go
zeekay 7d727874d5 chore: rebrand Formance Payments -> Hanzo Payments (hanzo-fi)
- go.mod module path + all self-imports: github.com/formancehq/payments -> github.com/hanzo-fi/payments
  (1590 .go files / 3152 refs; 20 modules: root, pkg/client, pkg/domain, 18 ce/plugins).
  External dep kept: formancehq/go-libs.
- plugins: each ce/plugins/* consumed a *published* pkg/domain; added local
  'replace .../pkg/domain => ../../../pkg/domain' (consistent with root) so every
  standalone plugin module builds in-monorepo. compile-plugin.sh MOD var rebranded too.
- branding: README, LICENSE (dual MIT+EE; upstream copyright retained + Hanzo added),
  goreleaser (release images -> registry.hanzo.ai/hanzo-fi, OCI labels, homepage),
  proto go_package, renovate, speakeasy gen.yaml, connector-template *.gotpl.
- CI: removed Numary/Formance workflows + composite action; added canonical hanzo.yml +
  cicd.yml (hanzoai/ci, gated HANZO_CI_ENABLED) + secretless ci.yml (go build/vet).
- kept as data/compat keys: wire capability enums ALLOW_FORMANCE_*, generated SDK type
  client.Formance, domain field FormanceRedirectURL, OTEL_SERVICE_NAME, upstream base image.
- verified: go build ./... (default + -tags ee) + all 20 nested modules green.
2026-07-05 13:08:55 -07:00

90 lines
2.4 KiB
Go

package models_test
import (
"encoding/json"
"testing"
"github.com/hanzo-fi/payments/pkg/domain/models"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestConversionStatus(t *testing.T) {
t.Parallel()
t.Run("String", func(t *testing.T) {
t.Parallel()
assert.Equal(t, "UNKNOWN", models.CONVERSION_STATUS_UNKNOWN.String())
assert.Equal(t, "PENDING", models.CONVERSION_STATUS_PENDING.String())
assert.Equal(t, "COMPLETED", models.CONVERSION_STATUS_COMPLETED.String())
assert.Equal(t, "FAILED", models.CONVERSION_STATUS_FAILED.String())
assert.Equal(t, "UNKNOWN", models.ConversionStatus(999).String())
})
t.Run("FromString", func(t *testing.T) {
t.Parallel()
cases := []struct {
input string
expected models.ConversionStatus
hasError bool
}{
{"UNKNOWN", models.CONVERSION_STATUS_UNKNOWN, false},
{"PENDING", models.CONVERSION_STATUS_PENDING, false},
{"COMPLETED", models.CONVERSION_STATUS_COMPLETED, false},
{"FAILED", models.CONVERSION_STATUS_FAILED, false},
{"INVALID", models.CONVERSION_STATUS_UNKNOWN, true},
}
for _, tc := range cases {
result, err := models.ConversionStatusFromString(tc.input)
if tc.hasError {
require.Error(t, err)
} else {
require.NoError(t, err)
}
assert.Equal(t, tc.expected, result)
}
})
t.Run("MarshalJSON_UnmarshalJSON", func(t *testing.T) {
t.Parallel()
for _, s := range []models.ConversionStatus{
models.CONVERSION_STATUS_PENDING,
models.CONVERSION_STATUS_COMPLETED,
models.CONVERSION_STATUS_FAILED,
} {
data, err := json.Marshal(s)
require.NoError(t, err)
var result models.ConversionStatus
err = json.Unmarshal(data, &result)
require.NoError(t, err)
assert.Equal(t, s, result)
}
})
t.Run("Value_Scan", func(t *testing.T) {
t.Parallel()
for _, s := range []models.ConversionStatus{
models.CONVERSION_STATUS_PENDING,
models.CONVERSION_STATUS_COMPLETED,
} {
v, err := s.Value()
require.NoError(t, err)
var scanned models.ConversionStatus
err = scanned.Scan(v)
require.NoError(t, err)
assert.Equal(t, s, scanned)
}
_, err := models.CONVERSION_STATUS_UNKNOWN.Value()
require.Error(t, err)
})
t.Run("IsFinal", func(t *testing.T) {
t.Parallel()
assert.False(t, models.CONVERSION_STATUS_PENDING.IsFinal())
assert.True(t, models.CONVERSION_STATUS_COMPLETED.IsFinal())
assert.True(t, models.CONVERSION_STATUS_FAILED.IsFinal())
})
}