feat(reports): filter grouped live metrics by team
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -25,7 +26,7 @@ type LiveReportHandlerTestSuite struct {
|
||||
|
||||
func (s *LiveReportHandlerTestSuite) SetupSuite() {
|
||||
s.db, _ = gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
|
||||
s.db.AutoMigrate(&model.Account{}, &model.Conversation{}, &model.ReportingEventsRollup{})
|
||||
s.db.AutoMigrate(&model.Account{}, &model.Team{}, &model.Conversation{}, &model.ReportingEventsRollup{})
|
||||
|
||||
anSvc := service.NewAnalyticsService(
|
||||
repository.NewReportingEventRepo(s.db),
|
||||
@@ -42,6 +43,7 @@ func (s *LiveReportHandlerTestSuite) SetupSuite() {
|
||||
|
||||
func (s *LiveReportHandlerTestSuite) SetupTest() {
|
||||
s.db.Exec("DELETE FROM conversations")
|
||||
s.db.Exec("DELETE FROM teams")
|
||||
}
|
||||
|
||||
func TestLiveReportHandlerTestSuite(t *testing.T) {
|
||||
@@ -106,3 +108,27 @@ func (s *LiveReportHandlerTestSuite) TestGroupedConversationMetrics_ByAssignee()
|
||||
s.Equal(float64(1), body[1]["unattended"])
|
||||
s.Equal(float64(0), body[1]["unassigned"])
|
||||
}
|
||||
|
||||
func (s *LiveReportHandlerTestSuite) TestGroupedConversationMetrics_FiltersByTeamID() {
|
||||
team := model.Team{AccountID: 1, Name: "Support"}
|
||||
otherTeam := model.Team{AccountID: 1, Name: "Other"}
|
||||
s.Require().NoError(s.db.Create(&team).Error)
|
||||
s.Require().NoError(s.db.Create(&otherTeam).Error)
|
||||
agentID := uint(7)
|
||||
teamConversation := model.Conversation{AccountID: 1, TeamID: &team.ID, AssigneeID: &agentID, Status: string(model.ConversationStatusOpen), ChannelType: "web_widget", Channel: "web_widget"}
|
||||
otherConversation := model.Conversation{AccountID: 1, TeamID: &otherTeam.ID, Status: string(model.ConversationStatusOpen), ChannelType: "web_widget", Channel: "web_widget"}
|
||||
s.Require().NoError(s.db.Create(&teamConversation).Error)
|
||||
s.Require().NoError(s.db.Create(&otherConversation).Error)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
req := httptest.NewRequest(http.MethodGet, "/api/v1/accounts/1/live_reports/grouped_conversation_metrics?group_by=assignee_id&team_id="+strconv.FormatUint(uint64(team.ID), 10), nil)
|
||||
s.router.ServeHTTP(w, req)
|
||||
s.Equal(http.StatusOK, w.Code)
|
||||
var body []map[string]interface{}
|
||||
s.NoError(json.Unmarshal(w.Body.Bytes(), &body))
|
||||
s.Len(body, 1)
|
||||
s.Equal(float64(agentID), body[0]["assignee_id"])
|
||||
s.Equal(float64(1), body[0]["open"])
|
||||
s.Equal(float64(1), body[0]["unattended"])
|
||||
s.Equal(float64(0), body[0]["unassigned"])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user