Files
payments/internal/api/v2/handler_pools_list_test.go

69 lines
1.6 KiB
Go

package v2
import (
"fmt"
"net/http"
"net/http/httptest"
"time"
"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 v2 Pools List", func() {
var (
handlerFn http.HandlerFunc
)
Context("list pools", func() {
var (
w *httptest.ResponseRecorder
m *backend.MockBackend
)
BeforeEach(func() {
w = httptest.NewRecorder()
ctrl := gomock.NewController(GinkgoT())
m = backend.NewMockBackend(ctrl)
handlerFn = poolsList(m)
})
It("should return an internal server error when backend returns error", func(ctx SpecContext) {
req := httptest.NewRequest(http.MethodGet, "/", nil)
m.EXPECT().PoolsList(gomock.Any(), gomock.Any()).Return(
&paginate.Cursor[models.Pool]{}, fmt.Errorf("pools list error"),
)
handlerFn(w, req)
assertExpectedResponse(w.Result(), http.StatusInternalServerError, "INTERNAL")
})
It("should return a cursor object", func(ctx SpecContext) {
req := httptest.NewRequest(http.MethodGet, "/", nil)
m.EXPECT().PoolsList(gomock.Any(), gomock.Any()).Return(
&paginate.Cursor[models.Pool]{
Data: []models.Pool{
{
ID: uuid.New(),
Name: "test",
CreatedAt: time.Now().UTC(),
PoolAccounts: []models.AccountID{
{
Reference: "test",
ConnectorID: models.ConnectorID{},
},
},
},
},
}, nil,
)
handlerFn(w, req)
assertExpectedResponse(w.Result(), http.StatusOK, "cursor")
})
})
})