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

53 lines
1.4 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/onsi/ginkgo/v2"
"go.uber.org/mock/gomock"
)
var _ = Describe("API v3 Conversions List", func() {
var (
handlerFn http.HandlerFunc
)
Context("list conversions", func() {
var (
w *httptest.ResponseRecorder
m *backend.MockBackend
)
BeforeEach(func() {
w = httptest.NewRecorder()
ctrl := gomock.NewController(GinkgoT())
m = backend.NewMockBackend(ctrl)
handlerFn = conversionsList(m)
})
It("should return an internal server error when backend returns error", func(ctx SpecContext) {
req := httptest.NewRequest(http.MethodGet, "/", nil)
m.EXPECT().ConversionsList(gomock.Any(), gomock.Any()).Return(
&paginate.Cursor[models.Conversion]{}, fmt.Errorf("conversions 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().ConversionsList(gomock.Any(), gomock.Any()).Return(
&paginate.Cursor[models.Conversion]{}, nil,
)
handlerFn(w, req)
assertExpectedResponse(w.Result(), http.StatusOK, "cursor")
})
})
})