mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
93 lines
2.9 KiB
Go
93 lines
2.9 KiB
Go
//go:build it
|
|
|
|
package test_suite
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/hanzo-fi/go-libs/v5/pkg/observe/log"
|
|
"github.com/hanzo-fi/go-libs/v5/pkg/testing/deferred"
|
|
"github.com/hanzo-fi/payments/pkg/client/models/components"
|
|
evts "github.com/hanzo-fi/payments/pkg/events"
|
|
. "github.com/hanzo-fi/payments/pkg/testserver"
|
|
"github.com/google/uuid"
|
|
"github.com/nats-io/nats.go"
|
|
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
// This e2e test ensures that creating an account publishes the corresponding outbox event.
|
|
var _ = Context("Publishes events", Ordered, Serial, func() {
|
|
var (
|
|
db = UseTemplatedDatabase()
|
|
ctx = logging.TestingContext()
|
|
|
|
app *deferred.Deferred[*Server]
|
|
|
|
e chan *nats.Msg
|
|
|
|
defaultConnectorID string
|
|
)
|
|
|
|
app = NewTestServer(func() Configuration {
|
|
return Configuration{
|
|
Stack: stack,
|
|
NatsURL: natsServer.GetValue().ClientURL(),
|
|
PostgresConfiguration: db.GetValue().ConnectionOptions(),
|
|
TemporalNamespace: temporalServer.GetValue().DefaultNamespace(),
|
|
TemporalAddress: temporalServer.GetValue().Address(),
|
|
Output: GinkgoWriter,
|
|
OutboxPollingInterval: time.Second,
|
|
SkipOutboxScheduleCreation: false,
|
|
}
|
|
})
|
|
|
|
BeforeEach(func() {
|
|
var err error
|
|
defaultConnectorID, err = installConnector(ctx, app.GetValue(), uuid.New(), 3)
|
|
Expect(err).To(BeNil())
|
|
})
|
|
|
|
AfterEach(func() {
|
|
uninstallConnector(ctx, app.GetValue(), defaultConnectorID)
|
|
flushRemainingWorkflows(ctx)
|
|
})
|
|
|
|
It("creates an account on the default connector and publishes the account saved event", func() {
|
|
// Subscribe after connector install so no install-phase events are queued
|
|
e = Subscribe(GinkgoT(), app.GetValue())
|
|
|
|
// Create a simple v3 account on the default connector
|
|
createResponse, err := app.GetValue().SDK().Payments.V3.CreateAccount(ctx, &components.V3CreateAccountRequest{
|
|
Reference: "ref",
|
|
ConnectorID: defaultConnectorID,
|
|
AccountName: "foo",
|
|
Type: "INTERNAL",
|
|
CreatedAt: time.Now().UTC(),
|
|
})
|
|
Expect(err).To(BeNil())
|
|
Expect(createResponse.GetV3CreateAccountResponse().Data.ID).NotTo(BeEmpty())
|
|
|
|
// Verify the published event for account saved is eventually received on NATS
|
|
var expectedEventPayload = struct {
|
|
ConnectorID string `json:"connectorID"`
|
|
AccountID string `json:"id"`
|
|
Reference string `json:"reference"`
|
|
Type string `json:"type"`
|
|
Name string `json:"name"`
|
|
Provider string `json:"provider"`
|
|
}{
|
|
ConnectorID: defaultConnectorID,
|
|
AccountID: createResponse.GetV3CreateAccountResponse().Data.ID,
|
|
Reference: "ref",
|
|
Type: "INTERNAL",
|
|
Name: "foo",
|
|
Provider: "dummypay",
|
|
}
|
|
pollingInterval := app.GetValue().Config().OutboxPollingInterval
|
|
Eventually(e, pollingInterval*5, pollingInterval).
|
|
Should(Receive(Event(evts.EventTypeSavedAccounts, WithPayloadSubset(expectedEventPayload))))
|
|
})
|
|
})
|