-
Notifications
You must be signed in to change notification settings - Fork 0
/
handlers_test.go
45 lines (36 loc) · 1.3 KB
/
handlers_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package graphql
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"github.com/gin-gonic/gin"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
"github.com/surahman/FTeX/pkg/mocks"
"github.com/surahman/FTeX/pkg/quotes"
)
func TestQueryHandler(t *testing.T) {
// Mock configurations.
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockAuth := mocks.NewMockAuth(mockCtrl)
mockPostgres := mocks.NewMockPostgres(mockCtrl)
mockRedis := mocks.NewMockRedis(mockCtrl)
mockQuotes := quotes.NewMockQuotes(mockCtrl)
handler := QueryHandler("Authorization", mockAuth, mockRedis, mockPostgres, mockQuotes, zapLogger)
require.NotNil(t, handler, "failed to create graphql endpoint handler")
}
func TestPlaygroundHandler(t *testing.T) {
handler := PlaygroundHandler("/base-url", "/query-endpoint-url")
require.NotNil(t, handler, "failed to create playground endpoint handler")
}
func TestGinContextToContextMiddleware(t *testing.T) {
router := gin.Default()
router.POST("/middleware-test", GinContextToContextMiddleware())
req, _ := http.NewRequestWithContext(context.TODO(), http.MethodPost, "/middleware-test", nil)
w := httptest.NewRecorder()
router.ServeHTTP(w, req)
// Verify responses
require.Equal(t, http.StatusOK, w.Code, "expected status codes do not match")
}