mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
- 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.
189 lines
4.5 KiB
Go
189 lines
4.5 KiB
Go
package models_test
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/hanzo-fi/payments/pkg/domain/models"
|
|
"github.com/google/uuid"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestWebhookStructs(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
t.Run("PSPWebhookConfig", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
// Given
|
|
config := models.PSPWebhookConfig{
|
|
Name: "test-webhook",
|
|
URLPath: "/webhooks/test",
|
|
}
|
|
|
|
// When
|
|
data, err := json.Marshal(config)
|
|
|
|
// Then
|
|
require.NoError(t, err)
|
|
var unmarshaled models.PSPWebhookConfig
|
|
err = json.Unmarshal(data, &unmarshaled)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, config.Name, unmarshaled.Name)
|
|
assert.Equal(t, config.URLPath, unmarshaled.URLPath)
|
|
})
|
|
|
|
t.Run("WebhookConfig", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
// Given
|
|
connectorID := models.ConnectorID{
|
|
Provider: "test",
|
|
Reference: uuid.New(),
|
|
}
|
|
config := models.WebhookConfig{
|
|
Name: "test-webhook",
|
|
ConnectorID: connectorID,
|
|
URLPath: "/webhooks/test",
|
|
}
|
|
|
|
// When
|
|
data, err := json.Marshal(config)
|
|
|
|
// Then
|
|
require.NoError(t, err)
|
|
var unmarshaled models.WebhookConfig
|
|
err = json.Unmarshal(data, &unmarshaled)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, config.Name, unmarshaled.Name)
|
|
assert.Equal(t, config.ConnectorID, unmarshaled.ConnectorID)
|
|
assert.Equal(t, config.URLPath, unmarshaled.URLPath)
|
|
})
|
|
|
|
t.Run("BasicAuth", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
// Given
|
|
auth := models.BasicAuth{
|
|
Username: "user",
|
|
Password: "pass",
|
|
}
|
|
|
|
// When
|
|
data, err := json.Marshal(auth)
|
|
|
|
// Then
|
|
require.NoError(t, err)
|
|
var unmarshaled models.BasicAuth
|
|
err = json.Unmarshal(data, &unmarshaled)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, auth.Username, unmarshaled.Username)
|
|
assert.Equal(t, auth.Password, unmarshaled.Password)
|
|
})
|
|
|
|
t.Run("PSPWebhook", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
// Given
|
|
auth := &models.BasicAuth{
|
|
Username: "user",
|
|
Password: "pass",
|
|
}
|
|
webhook := models.PSPWebhook{
|
|
BasicAuth: auth,
|
|
QueryValues: map[string][]string{
|
|
"key": {"value1", "value2"},
|
|
},
|
|
Headers: map[string][]string{
|
|
"Content-Type": {"application/json"},
|
|
},
|
|
Body: []byte(`{"test": "data"}`),
|
|
}
|
|
|
|
// When
|
|
data, err := json.Marshal(webhook)
|
|
|
|
// Then
|
|
require.NoError(t, err)
|
|
var unmarshaled models.PSPWebhook
|
|
err = json.Unmarshal(data, &unmarshaled)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, webhook.BasicAuth.Username, unmarshaled.BasicAuth.Username)
|
|
assert.Equal(t, webhook.BasicAuth.Password, unmarshaled.BasicAuth.Password)
|
|
assert.Equal(t, webhook.QueryValues, unmarshaled.QueryValues)
|
|
assert.Equal(t, webhook.Headers, unmarshaled.Headers)
|
|
assert.Equal(t, webhook.Body, unmarshaled.Body)
|
|
})
|
|
|
|
t.Run("Webhook", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
// Given
|
|
connectorID := models.ConnectorID{
|
|
Provider: "test",
|
|
Reference: uuid.New(),
|
|
}
|
|
auth := &models.BasicAuth{
|
|
Username: "user",
|
|
Password: "pass",
|
|
}
|
|
webhook := models.Webhook{
|
|
ID: "webhook123",
|
|
ConnectorID: connectorID,
|
|
BasicAuth: auth,
|
|
QueryValues: map[string][]string{
|
|
"key": {"value1", "value2"},
|
|
},
|
|
Headers: map[string][]string{
|
|
"Content-Type": {"application/json"},
|
|
},
|
|
Body: []byte(`{"test": "data"}`),
|
|
}
|
|
|
|
// When
|
|
data, err := json.Marshal(webhook)
|
|
|
|
// Then
|
|
require.NoError(t, err)
|
|
var unmarshaled models.Webhook
|
|
err = json.Unmarshal(data, &unmarshaled)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, webhook.ID, unmarshaled.ID)
|
|
assert.Equal(t, webhook.ConnectorID, unmarshaled.ConnectorID)
|
|
assert.Equal(t, webhook.BasicAuth.Username, unmarshaled.BasicAuth.Username)
|
|
assert.Equal(t, webhook.BasicAuth.Password, unmarshaled.BasicAuth.Password)
|
|
assert.Equal(t, webhook.QueryValues, unmarshaled.QueryValues)
|
|
assert.Equal(t, webhook.Headers, unmarshaled.Headers)
|
|
assert.Equal(t, webhook.Body, unmarshaled.Body)
|
|
})
|
|
|
|
t.Run("PSPWebhook without BasicAuth", func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
// Given
|
|
webhook := models.PSPWebhook{
|
|
QueryValues: map[string][]string{
|
|
"key": {"value"},
|
|
},
|
|
Headers: map[string][]string{
|
|
"Content-Type": {"application/json"},
|
|
},
|
|
Body: []byte(`{"test": "data"}`),
|
|
}
|
|
|
|
// When
|
|
data, err := json.Marshal(webhook)
|
|
|
|
// Then
|
|
require.NoError(t, err)
|
|
var unmarshaled models.PSPWebhook
|
|
err = json.Unmarshal(data, &unmarshaled)
|
|
require.NoError(t, err)
|
|
assert.Nil(t, unmarshaled.BasicAuth)
|
|
assert.Equal(t, webhook.QueryValues, unmarshaled.QueryValues)
|
|
assert.Equal(t, webhook.Headers, unmarshaled.Headers)
|
|
assert.Equal(t, webhook.Body, unmarshaled.Body)
|
|
})
|
|
}
|