mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
62 lines
1.5 KiB
Go
62 lines
1.5 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/onsi/ginkgo/v2"
|
|
"go.uber.org/mock/gomock"
|
|
)
|
|
|
|
var _ = Describe("API v2 tasks List", func() {
|
|
var (
|
|
handlerFn http.HandlerFunc
|
|
)
|
|
|
|
Context("list tasks", func() {
|
|
var (
|
|
w *httptest.ResponseRecorder
|
|
m *backend.MockBackend
|
|
)
|
|
BeforeEach(func() {
|
|
w = httptest.NewRecorder()
|
|
ctrl := gomock.NewController(GinkgoT())
|
|
m = backend.NewMockBackend(ctrl)
|
|
handlerFn = tasksList(m)
|
|
})
|
|
|
|
It("should return an internal server error when backend returns error", func(ctx SpecContext) {
|
|
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
|
m.EXPECT().SchedulesList(gomock.Any(), gomock.Any()).Return(
|
|
&paginate.Cursor[models.Schedule]{}, fmt.Errorf("tasks 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().SchedulesList(gomock.Any(), gomock.Any()).Return(
|
|
&paginate.Cursor[models.Schedule]{
|
|
Data: []models.Schedule{
|
|
{
|
|
ID: "test",
|
|
ConnectorID: models.ConnectorID{},
|
|
CreatedAt: time.Now().UTC(),
|
|
},
|
|
},
|
|
}, nil,
|
|
)
|
|
handlerFn(w, req)
|
|
|
|
assertExpectedResponse(w.Result(), http.StatusOK, "cursor")
|
|
})
|
|
})
|
|
})
|