second commit
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/gochat/gochat/internal/service"
|
||||
)
|
||||
|
||||
type RAGHandlerTestSuite struct {
|
||||
suite.Suite
|
||||
handler *RAGHandler
|
||||
router *gin.Engine
|
||||
}
|
||||
|
||||
func (s *RAGHandlerTestSuite) SetupSuite() {
|
||||
// Nil/zero service for param-validation only
|
||||
svc := &service.RAGService{}
|
||||
s.handler = NewRAGHandler(svc)
|
||||
|
||||
gin.SetMode(gin.TestMode)
|
||||
r := gin.New()
|
||||
group := r.Group("/api/v1/accounts/:id")
|
||||
group.POST("/captain/rag/query", s.handler.Query)
|
||||
group.POST("/captain/rag/index/:response_id", s.handler.IndexResponse)
|
||||
s.router = r
|
||||
}
|
||||
|
||||
func TestRAGHandlerTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(RAGHandlerTestSuite))
|
||||
}
|
||||
|
||||
func (s *RAGHandlerTestSuite) TestQuery_InvalidAccountID() {
|
||||
w := httptest.NewRecorder()
|
||||
req := httptest.NewRequest(http.MethodPost, "/api/v1/accounts/abc/captain/rag/query", bytes.NewBufferString(`{"query":"test"}`))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
s.router.ServeHTTP(w, req)
|
||||
s.Equal(http.StatusBadRequest, w.Code)
|
||||
}
|
||||
|
||||
func (s *RAGHandlerTestSuite) TestQuery_InvalidJSON() {
|
||||
w := httptest.NewRecorder()
|
||||
req := httptest.NewRequest(http.MethodPost, "/api/v1/accounts/1/captain/rag/query", bytes.NewBufferString(`{invalid`))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
s.router.ServeHTTP(w, req)
|
||||
s.Equal(http.StatusBadRequest, w.Code)
|
||||
}
|
||||
|
||||
func (s *RAGHandlerTestSuite) TestIndexResponse_InvalidResponseID() {
|
||||
w := httptest.NewRecorder()
|
||||
req := httptest.NewRequest(http.MethodPost, "/api/v1/accounts/1/captain/rag/index/abc", nil)
|
||||
s.router.ServeHTTP(w, req)
|
||||
s.Equal(http.StatusBadRequest, w.Code)
|
||||
}
|
||||
Reference in New Issue
Block a user