Restructure the monorepo into clear top-level directories: - backend/: Go module root (cmd, internal, pkg, configs, migrations, docs/swagger, scripts, tests, go.mod, Makefile, .air.toml) - deploy/: Docker (Dockerfile, docker-compose*), quickstart, fluentd - docs/: project documentation + reports/ (moved from repo root) - AGENTS.md: new AI coding-agent guide at repo root Update all references to the new layout: - Dockerfile: COPY backend/go.mod, COPY backend/ (context = repo root) - docker-compose files: context ../.., dockerfile deploy/docker/Dockerfile, env_file ../../.env, volume mounts ../../backend:/app - deploy/quickstart/compose.yaml: dockerfile deploy/docker/Dockerfile - CI: working-directory: backend for go commands, file deploy/docker/Dockerfile, coverage path backend/coverage.out, health_check backend/scripts/ - backend/Makefile: docker target uses -f ../deploy/docker/Dockerfile ../ - README: architecture tree, quickstart, config paths updated Move root stray scripts (rename_models.*, run_m11_tests.sh, verify_build.sh, gorm_bool_main.go) to backend/scripts/legacy/. All moves via git mv to preserve history. Build, vet, SQLite tests, and docker compose config verified.
87 lines
3.2 KiB
Go
87 lines
3.2 KiB
Go
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 ConversationInsightHandlerTestSuite struct {
|
|
suite.Suite
|
|
handler *ConversationInsightHandler
|
|
router *gin.Engine
|
|
}
|
|
|
|
func (s *ConversationInsightHandlerTestSuite) SetupSuite() {
|
|
// Use nil/zero service for routing/param-validation tests
|
|
svc := &service.ConversationInsightService{}
|
|
s.handler = NewConversationInsightHandler(svc)
|
|
|
|
gin.SetMode(gin.TestMode)
|
|
r := gin.New()
|
|
group := r.Group("/api/v1/accounts/:id")
|
|
group.POST("/captain/insights/participants", s.handler.AnalyzeParticipants)
|
|
group.POST("/captain/insights/action_items", s.handler.ExtractActionItems)
|
|
group.POST("/captain/insights/label_suggestions", s.handler.SuggestLabels)
|
|
s.router = r
|
|
}
|
|
|
|
func TestConversationInsightHandlerTestSuite(t *testing.T) {
|
|
suite.Run(t, new(ConversationInsightHandlerTestSuite))
|
|
}
|
|
|
|
func (s *ConversationInsightHandlerTestSuite) TestAnalyzeParticipants_InvalidAccountID() {
|
|
w := httptest.NewRecorder()
|
|
req := httptest.NewRequest(http.MethodPost, "/api/v1/accounts/abc/captain/insights/participants", bytes.NewBufferString(`{"conversation_id":1}`))
|
|
req.Header.Set("Content-Type", "application/json")
|
|
s.router.ServeHTTP(w, req)
|
|
s.Equal(http.StatusBadRequest, w.Code)
|
|
}
|
|
|
|
func (s *ConversationInsightHandlerTestSuite) TestAnalyzeParticipants_InvalidJSON() {
|
|
w := httptest.NewRecorder()
|
|
req := httptest.NewRequest(http.MethodPost, "/api/v1/accounts/1/captain/insights/participants", bytes.NewBufferString(`{invalid`))
|
|
req.Header.Set("Content-Type", "application/json")
|
|
s.router.ServeHTTP(w, req)
|
|
s.Equal(http.StatusBadRequest, w.Code)
|
|
}
|
|
|
|
|
|
|
|
func (s *ConversationInsightHandlerTestSuite) TestExtractActionItems_InvalidAccountID() {
|
|
w := httptest.NewRecorder()
|
|
req := httptest.NewRequest(http.MethodPost, "/api/v1/accounts/abc/captain/insights/action_items", bytes.NewBufferString(`{"conversation_id":1}`))
|
|
req.Header.Set("Content-Type", "application/json")
|
|
s.router.ServeHTTP(w, req)
|
|
s.Equal(http.StatusBadRequest, w.Code)
|
|
}
|
|
|
|
func (s *ConversationInsightHandlerTestSuite) TestExtractActionItems_InvalidJSON() {
|
|
w := httptest.NewRecorder()
|
|
req := httptest.NewRequest(http.MethodPost, "/api/v1/accounts/1/captain/insights/action_items", bytes.NewBufferString(`{invalid`))
|
|
req.Header.Set("Content-Type", "application/json")
|
|
s.router.ServeHTTP(w, req)
|
|
s.Equal(http.StatusBadRequest, w.Code)
|
|
}
|
|
|
|
func (s *ConversationInsightHandlerTestSuite) TestSuggestLabels_InvalidAccountID() {
|
|
w := httptest.NewRecorder()
|
|
req := httptest.NewRequest(http.MethodPost, "/api/v1/accounts/abc/captain/insights/label_suggestions", bytes.NewBufferString(`{"conversation_id":1}`))
|
|
req.Header.Set("Content-Type", "application/json")
|
|
s.router.ServeHTTP(w, req)
|
|
s.Equal(http.StatusBadRequest, w.Code)
|
|
}
|
|
|
|
func (s *ConversationInsightHandlerTestSuite) TestSuggestLabels_InvalidJSON() {
|
|
w := httptest.NewRecorder()
|
|
req := httptest.NewRequest(http.MethodPost, "/api/v1/accounts/1/captain/insights/label_suggestions", bytes.NewBufferString(`{invalid`))
|
|
req.Header.Set("Content-Type", "application/json")
|
|
s.router.ServeHTTP(w, req)
|
|
s.Equal(http.StatusBadRequest, w.Code)
|
|
} |