Files
fgueryandGitHub 599477b709 fix(EN-549): remove config and connector dependencies (#622)
* chore: rename RunNextTasks workflow

* feat: added a trimmed down type for connector only containing the id

* feat: make runNextTask use connectorIdOnly

* feat: added isScheduledForDeletion to plugin interface

* feat: add scheduledForDeletion at plugin level

* feat: refactor manager.Load to take a connector instead of parts of it

* feat: saves the connector's scheduledFOrDeletion into the plugin

* feat: use plugin.IsScheduledForDeletion instead of loading connector

* fix: make e2e tests less flaky

* fix: remove config from most request types

* feat: (WIP) remove config from runNextTask

* fix: remove unneeded method definitions in each plugin

* fix: simplify RunNextFlow as anyway we need to change the parameters

* fix: add a workflow compatible with previous version for runNextTasks

* fix(EN-577): added back RunSendEvents as a deprecated workflow

* fix(EN-577): added back RunUpdatePaymentInitiationFromPayment as a deprecated workflow

* fix: fix linting directives

* fix: replace old usage with refactored one

* fix: added back missing deprecated activities

* fix: ensure fetch_next_balance works with v3.0 code

* fix: simplify a bit the versionning etc

* fix: quick refactor before applying solution elsewhere

* fix: add back RunSendEvents and RunNextTask child workflows where necessary for backward compatibility

* fix: add back missing activity, seems like it's mandatory?

* fix: run payment initiation update as child workflow when necessary

* fix: missing activy call in test, refine some todos

* fix: lint

* fix: ensure we always reload plugins into the manager -- so exposing isScheduledForDeletion

* fix: ensure we stop storing clear config in temporal

* fix: make store config support plain text config

* fix: some comments

* fix: change runSendEvent workflow to be match what we had in 3.0

* feat: enable worker versionning to avoid workflow from new version to get executed on old code

* fix: lint

* fix: revert worker versionning

* fix: minor code review comments

* fix: add context to Encrypt & Decrypt methods

* fix: improve lint, add couple tests

* fix: use atomic to handle isScheduledForDeletion

* fix: make create_events work on migration

* fix: avoid returning channel; just send what is needed in runSendEventAsChildWorkflow and runNextTaskAsChildWorkflow

* fix: remove extra call to installWorkflow on start plugin

* fix: typo in error log line

* fix: simplify errChan initialization

* fix: clarify feature flag names
2026-01-05 11:09:45 +00:00

148 lines
5.1 KiB
Go

package connectors
import (
"encoding/json"
"io"
"testing"
"time"
"github.com/formancehq/go-libs/v3/logging"
"github.com/formancehq/payments/internal/connectors/plugins/registry"
"github.com/formancehq/payments/internal/models"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
// force load of plugins to registry
_ "github.com/formancehq/payments/internal/connectors/plugins/public"
)
func TestManager_Load(t *testing.T) {
t.Parallel()
minimumPollingPeriod := time.Second
defaultPollingPeriod := 3 * time.Minute
logger := logging.NewDefaultLogger(io.Discard, false, false, false)
tests := map[string]struct {
provider string
expectedConfig models.Config
rawConfig json.RawMessage
expectError bool
strictMode bool
isScheduledForDeletion bool
}{
"unregistered plugin provider": {
provider: "test",
expectedConfig: models.Config{},
rawConfig: json.RawMessage(`{}`),
expectError: true,
strictMode: true,
},
"invalid config for provider": {
provider: registry.DummyPSPName,
expectedConfig: models.Config{},
rawConfig: json.RawMessage(`{}`),
expectError: true,
strictMode: true,
},
"provider config present - base config error": {
provider: registry.DummyPSPName,
expectedConfig: models.Config{},
rawConfig: json.RawMessage(`{"directory":"/tmp"}`),
expectError: true,
strictMode: true,
},
"base config present - provider specific config error": {
provider: registry.DummyPSPName,
expectedConfig: models.Config{},
rawConfig: json.RawMessage(`{"name":"base config present - provider specific config error"}`),
expectError: true,
strictMode: true,
},
"polling period issues ignored when not in strict mode": {
provider: registry.DummyPSPName,
expectedConfig: models.Config{Name: "polling period issues ignored when not in strict mode", PollingPeriod: time.Second},
rawConfig: json.RawMessage(`{"name":"polling period issues ignored when not in strict mode","pollingPeriod":"1s","directory":"/tmp"}`),
expectError: false,
strictMode: false,
},
"successful load": {
provider: registry.DummyPSPName,
expectedConfig: models.Config{Name: "successful load", PollingPeriod: 40 * time.Minute},
rawConfig: json.RawMessage(`{"name":"successful load","directory":"/tmp","pollingPeriod":"40m"}`),
expectError: false,
strictMode: true,
},
"polling period is set to default when missing": {
provider: registry.DummyPSPName,
expectedConfig: models.Config{Name: "polling period is set to default when missing", PollingPeriod: defaultPollingPeriod},
rawConfig: json.RawMessage(`{"name":"polling period is set to default when missing","directory":"/tmp"}`),
expectError: false,
strictMode: true,
},
"connector is scheduled for deletion": {
provider: registry.DummyPSPName,
expectedConfig: models.Config{Name: "connector is scheduled for deletion", PollingPeriod: 40 * time.Minute},
rawConfig: json.RawMessage(`{"name":"connector is scheduled for deletion","directory":"/tmp","pollingPeriod":"40m"}`),
expectError: false,
strictMode: false,
isScheduledForDeletion: true,
},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
manager := NewManager(logger, false, defaultPollingPeriod, minimumPollingPeriod)
connectorID := models.ConnectorID{Reference: uuid.New(), Provider: tt.provider}
connector := models.Connector{
ConnectorBase: models.ConnectorBase{
ID: connectorID,
Provider: tt.provider,
},
Config: tt.rawConfig,
ScheduledForDeletion: tt.isScheduledForDeletion,
}
returnedName, _, err := manager.Load(connector, false, tt.strictMode)
if tt.expectError {
require.Error(t, err)
_, err := manager.GetConfig(connectorID)
require.Error(t, err)
assert.ErrorIs(t, err, ErrNotFound)
_, err = manager.Get(connectorID)
assert.Error(t, err)
assert.ErrorIs(t, err, ErrNotFound)
} else {
require.NoError(t, err)
assert.Contains(t, manager.connectors, connectorID.String())
config, err := manager.GetConfig(connectorID)
assert.NoError(t, err)
assert.Equal(t, tt.expectedConfig, config)
plugin, err := manager.Get(connectorID)
assert.NoError(t, err)
assert.Equal(t, name, plugin.Name())
assert.Equal(t, returnedName, plugin.Name())
assert.Equal(t, tt.isScheduledForDeletion, plugin.IsScheduledForDeletion())
}
})
}
}
func TestManager_Unload(t *testing.T) {
t.Parallel()
minimumPollingPeriod := time.Second
logger := logging.NewDefaultLogger(io.Discard, false, false, false)
manager := NewManager(logger, false, time.Minute, minimumPollingPeriod)
connectorID := models.ConnectorID{Reference: uuid.New(), Provider: registry.DummyPSPName}
manager.connectors[connectorID.String()] = connector{}
manager.Unload(connectorID)
assert.NotContains(t, manager.connectors, connectorID.String())
}