From 62ce63bd625170ff7fc994dae7790c52effc3c29 Mon Sep 17 00:00:00 2001 From: Paul Nicolas Date: Thu, 3 Apr 2025 12:03:50 +0200 Subject: [PATCH] feat(payments): remove integration tests --- .../suite/payments-connectors-dummy-pay.go | 110 ---------- .../suite/payments-connectors-generic.go | 193 ------------------ .../suite/payments-connectors-reset.go | 116 ----------- .../suite/payments-connectors-stripe.go | 84 -------- 4 files changed, 503 deletions(-) delete mode 100644 tests/integration/suite/payments-connectors-dummy-pay.go delete mode 100644 tests/integration/suite/payments-connectors-generic.go delete mode 100644 tests/integration/suite/payments-connectors-reset.go delete mode 100644 tests/integration/suite/payments-connectors-stripe.go diff --git a/tests/integration/suite/payments-connectors-dummy-pay.go b/tests/integration/suite/payments-connectors-dummy-pay.go deleted file mode 100644 index e0ed881e7b..0000000000 --- a/tests/integration/suite/payments-connectors-dummy-pay.go +++ /dev/null @@ -1,110 +0,0 @@ -package suite - -import ( - webhooks "github.com/formancehq/webhooks/pkg" - "io" - "net/http" - "net/http/httptest" - "os" - "path/filepath" - "time" - - "github.com/formancehq/stack/tests/integration/internal/modules" - - "github.com/formancehq/formance-sdk-go/v3/pkg/models/operations" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" - paymentEvents "github.com/formancehq/payments/pkg/events" - "github.com/formancehq/stack/libs/events" - . "github.com/formancehq/stack/tests/integration/internal" - "github.com/google/uuid" - "github.com/nats-io/nats.go" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" -) - -var _ = WithModules([]*Module{modules.Payments}, func() { - When("configuring dummy pay connector", func() { - var ( - msgs chan *nats.Msg - cancelSubscription func() - ) - JustBeforeEach(func() { - cancelSubscription, msgs = SubscribePayments() - - paymentsDir := filepath.Join(os.TempDir(), uuid.NewString()) - Expect(os.MkdirAll(paymentsDir, 0o777)).To(Succeed()) - response, err := Client().Payments.V1.InstallConnector( - TestContext(), - operations.InstallConnectorRequest{ - ConnectorConfig: shared.ConnectorConfig{ - DummyPayConfig: &shared.DummyPayConfig{ - FilePollingPeriod: ptr("1s"), - Directory: paymentsDir, - Name: "test", - NumberOfAccountsPreGenerated: ptr(int64(0)), - NumberOfPaymentsPreGenerated: ptr(int64(1)), - }, - }, - Connector: shared.ConnectorDummyPay, - }, - ) - Expect(err).ToNot(HaveOccurred()) - Expect(response.StatusCode).To(Equal(201)) - Expect(response.ConnectorResponse).ToNot(BeNil()) - }) - JustAfterEach(func() { - cancelSubscription() - }) - It("should trigger some events", func() { - msg := WaitOnChanWithTimeout(msgs, 20*time.Second) - Expect(events.Check(msg.Data, "payments", paymentEvents.EventTypeSavedPayments)).Should(Succeed()) - }) - It("should generate some payments", func() { - Eventually(func(g Gomega) []shared.Payment { - response, err := Client().Payments.V1.ListPayments( - TestContext(), - operations.ListPaymentsRequest{}, - ) - g.Expect(err).ToNot(HaveOccurred()) - g.Expect(response.StatusCode).To(Equal(200)) - - return response.PaymentsCursor.Cursor.Data - }).WithTimeout(10 * time.Second).ShouldNot(BeEmpty()) // TODO: Check other fields - }) - WithModules([]*Module{modules.Webhooks}, func() { - var ( - httpServer *httptest.Server - called chan []byte - secret = webhooks.NewSecret() - ) - BeforeEach(func() { - called = make(chan []byte) - httpServer = httptest.NewServer( - http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - defer close(called) - data, _ := io.ReadAll(r.Body) - called <- data - })) - DeferCleanup(func() { - httpServer.Close() - }) - - response, err := Client().Webhooks.V1.InsertConfig( - TestContext(), - shared.ConfigUser{ - Endpoint: httpServer.URL, - Secret: &secret, - EventTypes: []string{ - "payments.saved_payment", - }, - }, - ) - Expect(err).ToNot(HaveOccurred()) - Expect(response.StatusCode).To(Equal(http.StatusOK)) - }) - It("Should trigger a webhook", func() { - Eventually(called).Should(ReceiveEvent("payments", paymentEvents.EventTypeSavedPayments)) - }) - }) - }) -}) diff --git a/tests/integration/suite/payments-connectors-generic.go b/tests/integration/suite/payments-connectors-generic.go deleted file mode 100644 index 85691cf96d..0000000000 --- a/tests/integration/suite/payments-connectors-generic.go +++ /dev/null @@ -1,193 +0,0 @@ -package suite - -import ( - "math/big" - "time" - - "github.com/formancehq/formance-sdk-go/v3/pkg/models/operations" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/sdkerrors" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" - . "github.com/formancehq/stack/tests/integration/internal" - "github.com/formancehq/stack/tests/integration/internal/modules" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" -) - -const ( - fakeConnectorID = "eyJQcm92aWRlciI6Ik1PRFVMUiIsIlJlZmVyZW5jZSI6IjQyNDY5MjEwLTQ5YTMtNGQ0NS04OWQ1LWVmNWI3YWI4OTUwNyJ9" -) - -var _ = WithModules([]*Module{modules.Payments}, func() { - When("trying to create accounts of an non existent connector", func() { - BeforeEach(func() { - _, err := Client().Payments.V1.CreateAccount( - TestContext(), - shared.AccountRequest{ - AccountName: ptr("test"), - ConnectorID: fakeConnectorID, // not installed - CreatedAt: time.Now(), - Reference: "test1", - Type: shared.AccountTypeInternal, - }, - ) - Expect(err).NotTo(BeNil()) - Expect(err.(*sdkerrors.PaymentsErrorResponse).ErrorCode).To(Equal(shared.PaymentsErrorsEnumValidation)) - }) - It("Should fail with a 400", func() { - }) - }) -}) - -var _ = WithModules([]*Module{modules.Payments}, func() { - When("trying to create payments of an non existent connector", func() { - BeforeEach(func() { - _, err := Client().Payments.V1.CreatePayment( - TestContext(), - shared.PaymentRequest{ - Amount: big.NewInt(100), - Asset: "EUR/2", - ConnectorID: fakeConnectorID, - CreatedAt: time.Now(), - Reference: "test", - Scheme: shared.PaymentSchemeOther, - Status: shared.PaymentStatusSucceeded, - Type: shared.PaymentTypeTransfer, - }, - ) - Expect(err).NotTo(BeNil()) - Expect(err.(*sdkerrors.PaymentsErrorResponse).ErrorCode).To(Equal(shared.PaymentsErrorsEnumValidation)) - }) - It("Should fail with a 400", func() { - }) - }) -}) - -var _ = WithModules([]*Module{modules.Payments}, func() { - var ( - connectorID string - ) - BeforeEach(func() { - response, err := Client().Payments.V1.InstallConnector( - TestContext(), - operations.InstallConnectorRequest{ - ConnectorConfig: shared.ConnectorConfig{ - GenericConfig: &shared.GenericConfig{ - Name: "test", - }, - }, - Connector: shared.ConnectorGeneric, - }, - ) - Expect(err).ToNot(HaveOccurred()) - Expect(response.StatusCode).To(Equal(201)) - Expect(response.ConnectorResponse).ToNot(BeNil()) - - connectorID = response.ConnectorResponse.Data.ConnectorID - }) - When("creating accounts and payments", func() { - var ( - accountIDInternal1 string - accountIDInternal2 string - ) - BeforeEach(func() { - createAccountResponse, err := Client().Payments.V1.CreateAccount( - TestContext(), - shared.AccountRequest{ - AccountName: ptr("test 1"), - ConnectorID: connectorID, - CreatedAt: time.Now(), - Reference: "test1", - Type: shared.AccountTypeInternal, - }, - ) - Expect(err).ToNot(HaveOccurred()) - Expect(createAccountResponse.StatusCode).To(Equal(200)) - - accountIDInternal1 = createAccountResponse.PaymentsAccountResponse.Data.ID - - createAccountResponse, err = Client().Payments.V1.CreateAccount( - TestContext(), - shared.AccountRequest{ - AccountName: ptr("test 2"), - ConnectorID: connectorID, - CreatedAt: time.Now(), - Reference: "test2", - Type: shared.AccountTypeInternal, - }, - ) - Expect(err).ToNot(HaveOccurred()) - Expect(createAccountResponse.StatusCode).To(Equal(200)) - - accountIDInternal2 = createAccountResponse.PaymentsAccountResponse.Data.ID - - createPaymentResponse, err := Client().Payments.V1.CreatePayment( - TestContext(), - shared.PaymentRequest{ - Amount: big.NewInt(100), - Asset: "EUR/2", - ConnectorID: connectorID, - CreatedAt: time.Now(), - DestinationAccountID: &accountIDInternal2, - Reference: "p1", - Scheme: shared.PaymentSchemeOther, - SourceAccountID: &accountIDInternal1, - Status: shared.PaymentStatusSucceeded, - Type: shared.PaymentTypeTransfer, - }, - ) - Expect(err).ToNot(HaveOccurred()) - Expect(createPaymentResponse.StatusCode).To(Equal(200)) - - createPaymentResponse, err = Client().Payments.V1.CreatePayment( - TestContext(), - shared.PaymentRequest{ - Amount: big.NewInt(200), - Asset: "EUR/2", - ConnectorID: connectorID, - CreatedAt: time.Now(), - Reference: "p2", - DestinationAccountID: &accountIDInternal1, - Scheme: shared.PaymentSchemeOther, - Status: shared.PaymentStatusSucceeded, - Type: shared.PaymentTypePayIn, - }, - ) - Expect(err).ToNot(HaveOccurred()) - Expect(createPaymentResponse.StatusCode).To(Equal(200)) - - createPaymentResponse, err = Client().Payments.V1.CreatePayment( - TestContext(), - shared.PaymentRequest{ - Amount: big.NewInt(300), - Asset: "EUR/2", - ConnectorID: connectorID, - CreatedAt: time.Now(), - Reference: "p3", - SourceAccountID: &accountIDInternal1, - Scheme: shared.PaymentSchemeOther, - Status: shared.PaymentStatusFailed, - Type: shared.PaymentTypePayout, - }, - ) - Expect(err).ToNot(HaveOccurred()) - Expect(createPaymentResponse.StatusCode).To(Equal(200)) - }) - It("should be available on api", func() { - listAccountsResponse, err := Client().Payments.V1.PaymentslistAccounts( - TestContext(), - operations.PaymentslistAccountsRequest{}, - ) - Expect(err).ToNot(HaveOccurred()) - Expect(listAccountsResponse.StatusCode).To(Equal(200)) - Expect(listAccountsResponse.AccountsCursor.Cursor.Data).To(HaveLen(2)) - - listPaymentsResponse, err := Client().Payments.V1.ListPayments( - TestContext(), - operations.ListPaymentsRequest{}, - ) - Expect(err).ToNot(HaveOccurred()) - Expect(listPaymentsResponse.StatusCode).To(Equal(200)) - Expect(listPaymentsResponse.PaymentsCursor.Cursor.Data).To(HaveLen(3)) - }) - }) -}) diff --git a/tests/integration/suite/payments-connectors-reset.go b/tests/integration/suite/payments-connectors-reset.go deleted file mode 100644 index a4f233ec86..0000000000 --- a/tests/integration/suite/payments-connectors-reset.go +++ /dev/null @@ -1,116 +0,0 @@ -package suite - -import ( - "encoding/json" - "os" - "path/filepath" - "time" - - "github.com/formancehq/stack/tests/integration/internal/modules" - - "github.com/formancehq/formance-sdk-go/v3/pkg/models/operations" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" - paymentEvents "github.com/formancehq/payments/pkg/events" - "github.com/formancehq/stack/libs/events" - . "github.com/formancehq/stack/tests/integration/internal" - "github.com/google/uuid" - "github.com/nats-io/nats.go" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" -) - -var _ = WithModules([]*Module{modules.Payments, modules.Search}, func() { - var ( - connectorID string - existingPaymentID string - msgs chan *nats.Msg - cancelSubscription func() - ) - BeforeEach(func() { - cancelSubscription, msgs = SubscribePayments() - - paymentsDir := filepath.Join(os.TempDir(), uuid.NewString()) - Expect(os.MkdirAll(paymentsDir, 0o777)).To(Succeed()) - response, err := Client().Payments.V1.InstallConnector( - TestContext(), - operations.InstallConnectorRequest{ - ConnectorConfig: shared.ConnectorConfig{ - DummyPayConfig: &shared.DummyPayConfig{ - FilePollingPeriod: ptr("1s"), - Directory: paymentsDir, - Name: "test", - NumberOfPaymentsPreGenerated: ptr(int64(1)), - }, - }, - Connector: shared.ConnectorDummyPay, - }, - ) - Expect(err).ToNot(HaveOccurred()) - Expect(response.StatusCode).To(Equal(201)) - Expect(response.ConnectorResponse).ToNot(BeNil()) - Expect(response.ConnectorResponse.Data).ToNot(BeNil()) - connectorID = response.ConnectorResponse.Data.ConnectorID - - Eventually(func(g Gomega) bool { - response, err := Client().Search.V1.Search( - TestContext(), - shared.Query{ - Target: ptr("PAYMENT"), - }, - ) - g.Expect(err).ToNot(HaveOccurred()) - g.Expect(response.StatusCode).To(Equal(200)) - if len(response.Response.Cursor.Data) == 0 { - return false - } - existingPaymentID = response.Response.Cursor.Data[0]["id"].(string) - return true - }).Should(BeTrue()) - }) - AfterEach(func() { - cancelSubscription() - }) - When("resetting connector", func() { - BeforeEach(func() { - response, err := Client().Payments.V1.ResetConnectorV1( - TestContext(), - operations.ResetConnectorV1Request{ - Connector: shared.ConnectorDummyPay, - ConnectorID: connectorID, - }, - ) - Expect(err).ToNot(HaveOccurred()) - Expect(response.StatusCode).To(Equal(204)) - }) - It("should trigger some events", func() { - var msg *nats.Msg - Eventually(func(g Gomega) bool { - msg = WaitOnChanWithTimeout(msgs, 5*time.Second) - type typedMessage struct { - Type string `json:"type"` - } - - tm := &typedMessage{} - g.Expect(json.Unmarshal(msg.Data, tm)).To(Succeed()) - return tm.Type == paymentEvents.EventTypeConnectorReset - }).Should(BeTrue()) - - Expect(events.Check(msg.Data, "payments", paymentEvents.EventTypeConnectorReset)).Should(Succeed()) - }) - It("should delete payments on search service", func() { - Eventually(func(g Gomega) []map[string]any { - response, err := Client().Search.V1.Search( - TestContext(), - shared.Query{ - Target: ptr("PAYMENT"), - Terms: []string{"id=" + existingPaymentID}, - }, - ) - g.Expect(err).ToNot(HaveOccurred()) - g.Expect(response.StatusCode).To(Equal(200)) - - return response.Response.Cursor.Data - }).Should(BeEmpty()) - }) - }) -}) diff --git a/tests/integration/suite/payments-connectors-stripe.go b/tests/integration/suite/payments-connectors-stripe.go deleted file mode 100644 index 016df7ab48..0000000000 --- a/tests/integration/suite/payments-connectors-stripe.go +++ /dev/null @@ -1,84 +0,0 @@ -package suite - -import ( - "os" - "time" - - "github.com/formancehq/stack/tests/integration/internal/modules" - - "github.com/formancehq/formance-sdk-go/v3/pkg/models/operations" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" - paymentEvents "github.com/formancehq/payments/pkg/events" - "github.com/formancehq/stack/libs/events" - . "github.com/formancehq/stack/tests/integration/internal" - "github.com/nats-io/nats.go" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" -) - -var _ = WithModules([]*Module{modules.Payments, modules.Search}, func() { - When("configuring stripe connector", func() { - var ( - msgs chan *nats.Msg - cancelSubscription func() - ) - BeforeEach(func() { - apiKey := os.Getenv("STRIPE_API_KEY") - if apiKey == "" { - Skip("No stripe api key provided") - } - - cancelSubscription, msgs = SubscribePayments() - - response, err := Client().Payments.V1.InstallConnector( - TestContext(), - operations.InstallConnectorRequest{ - ConnectorConfig: shared.ConnectorConfig{ - StripeConfig: &shared.StripeConfig{ - APIKey: apiKey, - Name: "stripe-test", - }, - }, - Connector: shared.ConnectorStripe, - }, - ) - Expect(err).ToNot(HaveOccurred()) - Expect(response.StatusCode).To(Equal(201)) - Expect(response.ConnectorResponse).ToNot(BeNil()) - Expect(response.ConnectorResponse.Data).ToNot(BeNil()) - }) - AfterEach(func() { - cancelSubscription() - }) - It("should trigger some events", func() { - msg := WaitOnChanWithTimeout(msgs, 5*time.Second) - Expect(events.Check(msg.Data, "payments", paymentEvents.EventTypeSavedPayments)).Should(Succeed()) - }) - It("should generate some payments", func() { - Eventually(func(g Gomega) []shared.Payment { - response, err := Client().Payments.V1.ListPayments( - TestContext(), - operations.ListPaymentsRequest{}, - ) - g.Expect(err).ToNot(HaveOccurred()) - g.Expect(response.StatusCode).To(Equal(200)) - return response.PaymentsCursor.Cursor.Data - }).ShouldNot(BeEmpty()) // TODO: Check other fields - }) - It("should be ingested on search", func() { - Eventually(func(g Gomega) bool { - response, err := Client().Search.V1.Search( - TestContext(), - shared.Query{ - Target: ptr("PAYMENT"), - }, - ) - g.Expect(err).ToNot(HaveOccurred()) - g.Expect(response.StatusCode).To(Equal(200)) - g.Expect(response.Response.Cursor.Data).NotTo(BeEmpty()) - - return true - }).Should(BeTrue()) - }) - }) -})