Skip to content

Commit

Permalink
Merge pull request #235 from formancehq/fix/v2-payments-install-req
Browse files Browse the repository at this point in the history
fix: (v2) ensure connector install v2 response is compatible to fctl
  • Loading branch information
laouji authored Dec 27, 2024
2 parents e40f482 + 44de6e4 commit 7471062
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 22 deletions.
10 changes: 9 additions & 1 deletion internal/api/v2/handler_connectors_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ import (
"go.opentelemetry.io/otel/attribute"
)

// NOTE: in order to maintain previous version compatibility, we need to keep the
// same response structure as the previous version of the API
type ConnectorInstallResponse struct {
ConnectorID string `json:"connectorID"`
}

func connectorsInstall(backend backend.Backend) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx, span := otel.Tracer().Start(r.Context(), "v2_connectorsInstall")
Expand Down Expand Up @@ -41,6 +47,8 @@ func connectorsInstall(backend backend.Backend) http.HandlerFunc {
return
}

api.Created(w, connectorID.String())
api.Created(w, ConnectorInstallResponse{
ConnectorID: connectorID.String(),
})
}
}
5 changes: 2 additions & 3 deletions test/e2e/api_accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var _ = Context("Payments API Accounts", func() {
func(ver int) {
e = Subscribe(GinkgoT(), app.GetValue())
connectorConf := newConnectorConfigurationFn()(uuid.New())
err = ConnectorInstall(ctx, app.GetValue(), ver, connectorConf, &connectorRes)
err = ConnectorInstall(ctx, app.GetValue(), 3, connectorConf, &connectorRes)
Expect(err).To(BeNil())

createRequest.ConnectorID = connectorRes.Data
Expand Down Expand Up @@ -98,9 +98,8 @@ var _ = Context("Payments API Accounts", func() {
connectorConf := newConnectorConfigurationFn()(uuid.New())
_, err := GeneratePSPData(connectorConf.Directory)
Expect(err).To(BeNil())
ver = 3

err = ConnectorInstall(ctx, app.GetValue(), ver, connectorConf, &connectorRes)
err = ConnectorInstall(ctx, app.GetValue(), 3, connectorConf, &connectorRes)
Expect(err).To(BeNil())
Eventually(e).WithTimeout(2 * time.Second).Should(Receive(Event(evts.EventTypeSavedAccounts)))

Expand Down
6 changes: 3 additions & 3 deletions test/e2e/api_bank_accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ var _ = Context("Payments API Bank Accounts", func() {
ver int
createRes struct{ Data v2.BankAccountResponse }
forwardReq v2.BankAccountsForwardToConnectorRequest
connectorRes struct{ Data string }
connectorRes struct{ Data v2.ConnectorInstallResponse }
res struct{ Data v2.BankAccountResponse }
e chan *nats.Msg
err error
Expand All @@ -202,11 +202,11 @@ var _ = Context("Payments API Bank Accounts", func() {
Expect(err.Error()).To(ContainSubstring("400"))
})
It("should be ok", func() {
forwardReq = v2.BankAccountsForwardToConnectorRequest{ConnectorID: connectorRes.Data}
forwardReq = v2.BankAccountsForwardToConnectorRequest{ConnectorID: connectorRes.Data.ConnectorID}
err = ForwardBankAccount(ctx, app.GetValue(), ver, id.String(), &forwardReq, &res)
Expect(err).To(BeNil())
Expect(res.Data.RelatedAccounts).To(HaveLen(1))
Expect(res.Data.RelatedAccounts[0].ConnectorID).To(Equal(connectorRes.Data))
Expect(res.Data.RelatedAccounts[0].ConnectorID).To(Equal(connectorRes.Data.ConnectorID))

Eventually(e).Should(Receive(Event(evts.EventTypeSavedBankAccount)))
})
Expand Down
19 changes: 11 additions & 8 deletions test/e2e/api_connectors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/formancehq/go-libs/v2/bun/bunpaginate"
"github.com/formancehq/go-libs/v2/logging"
v2 "github.com/formancehq/payments/internal/api/v2"
v3 "github.com/formancehq/payments/internal/api/v3"
"github.com/formancehq/payments/internal/models"
. "github.com/formancehq/payments/pkg/testserver"
Expand Down Expand Up @@ -38,16 +39,16 @@ var _ = Context("Payments API Connectors", func() {

When("installing a connector", func() {
var (
connectorRes struct{ Data string }
id uuid.UUID
workflowID string
id uuid.UUID
workflowID string
)
JustBeforeEach(func() {
id = uuid.New()
})

It("should be ok with v3", func() {
ver := 3
var connectorRes struct{ Data string }
connectorConf := newConnectorConfigurationFn()(id)
err := ConnectorInstall(ctx, app.GetValue(), ver, connectorConf, &connectorRes)
Expect(err).To(BeNil())
Expand All @@ -71,28 +72,29 @@ var _ = Context("Payments API Connectors", func() {

It("should be ok with v2", func() {
ver := 2
var connectorRes struct{ Data v2.ConnectorInstallResponse }
connectorConf := newConnectorConfigurationFn()(id)
err := ConnectorInstall(ctx, app.GetValue(), ver, connectorConf, &connectorRes)
Expect(err).To(BeNil())

getRes := struct{ Data ConnectorConf }{}
err = ConnectorConfig(ctx, app.GetValue(), ver, connectorRes.Data, &getRes)
err = ConnectorConfig(ctx, app.GetValue(), ver, connectorRes.Data.ConnectorID, &getRes)
Expect(err).To(BeNil())
Expect(getRes.Data).To(Equal(connectorConf))
})
})

When("uninstalling a connector", func() {
var (
connectorRes struct{ Data string }
id uuid.UUID
id uuid.UUID
)
JustBeforeEach(func() {
id = uuid.New()
})

It("should be ok with v3", func() {
ver := 3
var connectorRes struct{ Data string }
connectorConf := newConnectorConfigurationFn()(id)
err := ConnectorInstall(ctx, app.GetValue(), ver, connectorConf, &connectorRes)
Expect(err).To(BeNil())
Expand All @@ -113,13 +115,14 @@ var _ = Context("Payments API Connectors", func() {

It("should be ok with v2", func() {
ver := 2
var connectorRes struct{ Data v2.ConnectorInstallResponse }
connectorConf := newConnectorConfigurationFn()(id)
err := ConnectorInstall(ctx, app.GetValue(), ver, connectorConf, &connectorRes)
Expect(err).To(BeNil())

err = ConnectorUninstall(ctx, app.GetValue(), ver, connectorRes.Data, nil)
err = ConnectorUninstall(ctx, app.GetValue(), ver, connectorRes.Data.ConnectorID, nil)
Expect(err).To(BeNil())
blockTillWorkflowComplete(ctx, connectorRes.Data, "uninstall")
blockTillWorkflowComplete(ctx, connectorRes.Data.ConnectorID, "uninstall")
})
})

Expand Down
6 changes: 3 additions & 3 deletions test/e2e/api_payments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ var _ = Context("Payments API Payments", func() {

When("creating a new payment with v2", func() {
var (
connectorRes struct{ Data string }
connectorRes struct{ Data v2.ConnectorInstallResponse }
createResponse struct{ Data v2.PaymentResponse }
getResponse struct{ Data v2.PaymentResponse }
e chan *nats.Msg
Expand All @@ -127,10 +127,10 @@ var _ = Context("Payments API Payments", func() {
})

It("should be ok", func() {
debtorID, creditorID := setupDebtorAndCreditorAccounts(ctx, app.GetValue(), e, ver, connectorRes.Data, createdAt)
debtorID, creditorID := setupDebtorAndCreditorAccounts(ctx, app.GetValue(), e, ver, connectorRes.Data.ConnectorID, createdAt)
createRequest := v2.CreatePaymentRequest{
Reference: "ref",
ConnectorID: connectorRes.Data,
ConnectorID: connectorRes.Data.ConnectorID,
CreatedAt: createdAt,
Amount: initialAmount,
Asset: asset,
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/api_pools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ var _ = Context("Payments API Pools", func() {

When("creating a new pool with v2", func() {
var (
connectorRes struct{ Data string }
connectorRes struct{ Data v2.ConnectorInstallResponse }
connectorID string
e chan *nats.Msg
ver int
Expand All @@ -131,7 +131,7 @@ var _ = Context("Payments API Pools", func() {
connectorConf := newConnectorConfigurationFn()(uuid.New())
err := ConnectorInstall(ctx, app.GetValue(), ver, connectorConf, &connectorRes)
Expect(err).To(BeNil())
connectorID = connectorRes.Data
connectorID = connectorRes.Data.ConnectorID
})

It("should be ok when underlying accounts exist", func() {
Expand Down Expand Up @@ -268,7 +268,7 @@ var _ = Context("Payments API Pools", func() {

When("adding and removing accounts to a pool with v2", func() {
var (
connectorRes struct{ Data string }
connectorRes struct{ Data v2.ConnectorInstallResponse }
connectorID string
accountIDs []string
extraAccountIDs []string
Expand All @@ -285,7 +285,7 @@ var _ = Context("Payments API Pools", func() {
connectorConf := newConnectorConfigurationFn()(uuid.New())
err := ConnectorInstall(ctx, app.GetValue(), ver, connectorConf, &connectorRes)
Expect(err).To(BeNil())
connectorID = connectorRes.Data
connectorID = connectorRes.Data.ConnectorID
ids := setupAccounts(ctx, app.GetValue(), e, ver, connectorID, 4)
accountIDs = ids[0:2]
extraAccountIDs = ids[2:4]
Expand Down

0 comments on commit 7471062

Please sign in to comment.