From 44de6e4817c69eaf09fe41838c6ca17f025278f2 Mon Sep 17 00:00:00 2001 From: Crimson Thompson Date: Fri, 27 Dec 2024 10:10:59 +0100 Subject: [PATCH] fix: ensure connector install v2 response is compatible to fctl --- internal/api/v2/handler_connectors_install.go | 10 +++++++++- test/e2e/api_accounts_test.go | 5 ++--- test/e2e/api_bank_accounts_test.go | 6 +++--- test/e2e/api_connectors_test.go | 19 +++++++++++-------- test/e2e/api_payments_test.go | 6 +++--- test/e2e/api_pools_test.go | 8 ++++---- 6 files changed, 32 insertions(+), 22 deletions(-) diff --git a/internal/api/v2/handler_connectors_install.go b/internal/api/v2/handler_connectors_install.go index 209dce16..f4954c2b 100644 --- a/internal/api/v2/handler_connectors_install.go +++ b/internal/api/v2/handler_connectors_install.go @@ -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") @@ -41,6 +47,8 @@ func connectorsInstall(backend backend.Backend) http.HandlerFunc { return } - api.Created(w, connectorID.String()) + api.Created(w, ConnectorInstallResponse{ + ConnectorID: connectorID.String(), + }) } } diff --git a/test/e2e/api_accounts_test.go b/test/e2e/api_accounts_test.go index 1c60c0b7..43f8048b 100644 --- a/test/e2e/api_accounts_test.go +++ b/test/e2e/api_accounts_test.go @@ -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 @@ -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))) diff --git a/test/e2e/api_bank_accounts_test.go b/test/e2e/api_bank_accounts_test.go index 5a5fbd60..c212a1f2 100644 --- a/test/e2e/api_bank_accounts_test.go +++ b/test/e2e/api_bank_accounts_test.go @@ -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 @@ -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))) }) diff --git a/test/e2e/api_connectors_test.go b/test/e2e/api_connectors_test.go index 377c885b..a94686e2 100644 --- a/test/e2e/api_connectors_test.go +++ b/test/e2e/api_connectors_test.go @@ -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" @@ -38,9 +39,8 @@ 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() @@ -48,6 +48,7 @@ var _ = Context("Payments API Connectors", func() { 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()) @@ -71,12 +72,13 @@ 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)) }) @@ -84,8 +86,7 @@ var _ = Context("Payments API Connectors", func() { When("uninstalling a connector", func() { var ( - connectorRes struct{ Data string } - id uuid.UUID + id uuid.UUID ) JustBeforeEach(func() { id = uuid.New() @@ -93,6 +94,7 @@ var _ = Context("Payments API Connectors", func() { 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()) @@ -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") }) }) diff --git a/test/e2e/api_payments_test.go b/test/e2e/api_payments_test.go index ff603117..833d7431 100644 --- a/test/e2e/api_payments_test.go +++ b/test/e2e/api_payments_test.go @@ -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 @@ -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, diff --git a/test/e2e/api_pools_test.go b/test/e2e/api_pools_test.go index 20685a65..6f3557c5 100644 --- a/test/e2e/api_pools_test.go +++ b/test/e2e/api_pools_test.go @@ -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 @@ -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() { @@ -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 @@ -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]