mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
* feat(models): add bank bridge models * feat(storage): add bank bridge migrations and functions * feat(engine): add bank bridge workflows * feat(connectors): add plaid bank bridge connector * feat(events): add bank bridge events * feat(api): add bank bridge router * feat(*): bank bridge boilerplate * fix nil pointer crash * add more check when getting link attempts + change enum * fix tests * remove print * fixes after reviews * add specific table for access tokens * fixes after reviews * fix go mod tidy * remove indexes + null default * plaid: add tests * *: add more tests * fix after rebase
59 lines
1.8 KiB
Go
59 lines
1.8 KiB
Go
package v2
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
|
|
"github.com/formancehq/payments/internal/api/backend"
|
|
"github.com/formancehq/payments/internal/models"
|
|
"github.com/google/uuid"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
"go.uber.org/mock/gomock"
|
|
)
|
|
|
|
var _ = Describe("API v2 Connector Webhooks", func() {
|
|
var (
|
|
handlerFn http.HandlerFunc
|
|
connID models.ConnectorID
|
|
config json.RawMessage
|
|
)
|
|
BeforeEach(func() {
|
|
connID = models.ConnectorID{Reference: uuid.New(), Provider: "psp"}
|
|
config = json.RawMessage("{}")
|
|
})
|
|
|
|
Context("webhooks connector", func() {
|
|
var (
|
|
w *httptest.ResponseRecorder
|
|
m *backend.MockBackend
|
|
)
|
|
BeforeEach(func() {
|
|
w = httptest.NewRecorder()
|
|
ctrl := gomock.NewController(GinkgoT())
|
|
m = backend.NewMockBackend(ctrl)
|
|
handlerFn = connectorsWebhooks(m)
|
|
})
|
|
|
|
It("should return a bad request error when connector ID is invalid", func(ctx SpecContext) {
|
|
req := prepareQueryRequest(http.MethodGet, "connectorID", "invalid")
|
|
handlerFn(w, req)
|
|
|
|
assertExpectedResponse(w.Result(), http.StatusBadRequest, ErrInvalidID)
|
|
})
|
|
|
|
It("should return an internal server error when backend returns error", func(ctx SpecContext) {
|
|
m.EXPECT().ConnectorsHandleWebhooks(gomock.Any(), "/", "/", gomock.Any()).Return(fmt.Errorf("connector webhooks err"))
|
|
handlerFn(w, prepareJSONRequestWithQuery(http.MethodPost, "connectorID", connID.String(), &config))
|
|
assertExpectedResponse(w.Result(), http.StatusInternalServerError, "INTERNAL")
|
|
})
|
|
|
|
It("should return status ok on success", func(ctx SpecContext) {
|
|
m.EXPECT().ConnectorsHandleWebhooks(gomock.Any(), "/", "/", gomock.Any()).Return(nil)
|
|
handlerFn(w, prepareJSONRequestWithQuery(http.MethodPost, "connectorID", connID.String(), &config))
|
|
assertExpectedResponse(w.Result(), http.StatusOK, "")
|
|
})
|
|
})
|
|
})
|