Files
payments/internal/api/v3/handler_accounts_balances_test.go

66 lines
1.9 KiB
Go

package v3
import (
"fmt"
"net/http"
"net/http/httptest"
"github.com/hanzo-fi/go-libs/v5/pkg/storage/bun/paginate"
"github.com/hanzo-fi/payments/internal/api/backend"
"github.com/hanzo-fi/payments/pkg/domain/models"
"github.com/google/uuid"
. "github.com/onsi/ginkgo/v2"
"go.uber.org/mock/gomock"
)
var _ = Describe("API v3 Accounts Balances", func() {
var (
handlerFn http.HandlerFunc
accID models.AccountID
)
BeforeEach(func() {
connID := models.ConnectorID{Reference: uuid.New(), Provider: "psp"}
accID = models.AccountID{Reference: uuid.New().String(), ConnectorID: connID}
})
Context("list balances", func() {
var (
w *httptest.ResponseRecorder
m *backend.MockBackend
)
BeforeEach(func() {
w = httptest.NewRecorder()
ctrl := gomock.NewController(GinkgoT())
m = backend.NewMockBackend(ctrl)
handlerFn = accountsBalances(m)
})
It("should return a validation request error when account ID is invalid", func(ctx SpecContext) {
req := prepareQueryRequest(http.MethodGet, "accountID", "invalidvalue")
handlerFn(w, req)
assertExpectedResponse(w.Result(), http.StatusBadRequest, ErrValidation)
})
It("should return an internal server error when backend returns error", func(ctx SpecContext) {
req := prepareQueryRequest(http.MethodGet, "accountID", accID.String())
m.EXPECT().BalancesList(gomock.Any(), gomock.Any()).Return(
&paginate.Cursor[models.Balance]{}, fmt.Errorf("balances list error"),
)
handlerFn(w, req)
assertExpectedResponse(w.Result(), http.StatusInternalServerError, "INTERNAL")
})
It("should return a cursor object", func(ctx SpecContext) {
req := prepareQueryRequest(http.MethodGet, "accountID", accID.String())
m.EXPECT().BalancesList(gomock.Any(), gomock.Any()).Return(
&paginate.Cursor[models.Balance]{}, nil,
)
handlerFn(w, req)
assertExpectedResponse(w.Result(), http.StatusOK, "cursor")
})
})
})