mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
53 lines
1.4 KiB
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 Payments List", func() {
|
|
var (
|
|
handlerFn http.HandlerFunc
|
|
)
|
|
|
|
Context("list payments", func() {
|
|
var (
|
|
w *httptest.ResponseRecorder
|
|
m *backend.MockBackend
|
|
)
|
|
BeforeEach(func() {
|
|
w = httptest.NewRecorder()
|
|
ctrl := gomock.NewController(GinkgoT())
|
|
m = backend.NewMockBackend(ctrl)
|
|
handlerFn = paymentsList(m)
|
|
})
|
|
|
|
It("should return an internal server error when backend returns error", func(ctx SpecContext) {
|
|
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
|
m.EXPECT().PaymentsList(gomock.Any(), gomock.Any()).Return(
|
|
&paginate.Cursor[models.Payment]{}, fmt.Errorf("payments 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().PaymentsList(gomock.Any(), gomock.Any()).Return(
|
|
&paginate.Cursor[models.Payment]{}, nil,
|
|
)
|
|
handlerFn(w, req)
|
|
|
|
assertExpectedResponse(w.Result(), http.StatusOK, "cursor")
|
|
})
|
|
})
|
|
})
|