Files
gochat/internal/handler/api/v1/live_report_handler_test.go
T
2026-06-04 15:44:48 +08:00

58 lines
1.7 KiB
Go

package v1
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/suite"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"github.com/gochat/gochat/internal/model"
"github.com/gochat/gochat/internal/repository"
"github.com/gochat/gochat/internal/service"
)
type LiveReportHandlerTestSuite struct {
suite.Suite
db *gorm.DB
handler *LiveReportHandler
router *gin.Engine
}
func (s *LiveReportHandlerTestSuite) SetupSuite() {
s.db, _ = gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
s.db.AutoMigrate(&model.Account{}, &model.Conversation{}, &model.ReportingEventsRollup{})
anSvc := service.NewAnalyticsService(
repository.NewReportingEventRepo(s.db),
repository.NewReportingEventsRollupRepo(s.db),
)
s.handler = NewLiveReportHandler(anSvc)
gin.SetMode(gin.TestMode)
r := gin.New()
r.GET("/api/v1/accounts/:account_id/live_reports/conversation_metrics", s.handler.ConversationMetrics)
s.router = r
}
func TestLiveReportHandlerTestSuite(t *testing.T) {
suite.Run(t, new(LiveReportHandlerTestSuite))
}
func (s *LiveReportHandlerTestSuite) TestConversationMetrics_InvalidAccountID() {
w := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, "/api/v1/accounts/abc/live_reports/conversation_metrics", nil)
s.router.ServeHTTP(w, req)
s.Equal(http.StatusBadRequest, w.Code)
}
func (s *LiveReportHandlerTestSuite) TestConversationMetrics_Success() {
// Placeholder implementation returns 200 with zero counts
w := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, "/api/v1/accounts/1/live_reports/conversation_metrics", nil)
s.router.ServeHTTP(w, req)
s.Equal(http.StatusOK, w.Code)
}