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.
174 lines
5.6 KiB
Go
174 lines
5.6 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/gochat/gochat/internal/model"
|
|
)
|
|
|
|
// ========== GetAgentSummary ==========
|
|
|
|
func TestSummaryReportRepo_GetAgentSummary(t *testing.T) {
|
|
db := setupTestDB(t, &model.ReportingEventsRollup{})
|
|
repo := NewSummaryReportRepo(db)
|
|
|
|
accountID := uint(1)
|
|
since := time.Date(2026, 5, 1, 0, 0, 0, 0, time.UTC)
|
|
until := time.Date(2026, 5, 31, 0, 0, 0, 0, time.UTC)
|
|
|
|
// Seed rollup data for agent dimension
|
|
date := time.Date(2026, 5, 15, 0, 0, 0, 0, time.UTC)
|
|
agentRollup := &model.ReportingEventsRollup{
|
|
AccountID: accountID,
|
|
Date: date,
|
|
DimensionType: model.DimensionAgent,
|
|
DimensionID: 10,
|
|
Metric: model.MetricFirstResponse,
|
|
Count: 5,
|
|
SumValue: 250.0,
|
|
SumValueBusinessHours: 125.0,
|
|
}
|
|
require.NoError(t, db.Create(agentRollup).Error)
|
|
|
|
// Also seed an inbox rollup (should NOT appear in agent results)
|
|
inboxRollup := &model.ReportingEventsRollup{
|
|
AccountID: accountID,
|
|
Date: date,
|
|
DimensionType: model.DimensionInbox,
|
|
DimensionID: 20,
|
|
Metric: model.MetricFirstResponse,
|
|
Count: 3,
|
|
SumValue: 150.0,
|
|
SumValueBusinessHours: 75.0,
|
|
}
|
|
require.NoError(t, db.Create(inboxRollup).Error)
|
|
|
|
results, err := repo.GetAgentSummary(context.Background(), accountID, since, until)
|
|
require.NoError(t, err)
|
|
assert.Len(t, results, 1, "only agent-dimension rollups should be returned")
|
|
assert.Equal(t, model.DimensionAgent, results[0].DimensionType)
|
|
assert.Equal(t, uint(10), results[0].DimensionID)
|
|
assert.Equal(t, model.MetricFirstResponse, results[0].Metric)
|
|
}
|
|
|
|
// ========== GetTeamSummary ==========
|
|
|
|
func TestSummaryReportRepo_GetTeamSummary(t *testing.T) {
|
|
db := setupTestDB(t, &model.ReportingEventsRollup{})
|
|
repo := NewSummaryReportRepo(db)
|
|
|
|
accountID := uint(1)
|
|
since := time.Date(2026, 5, 1, 0, 0, 0, 0, time.UTC)
|
|
until := time.Date(2026, 5, 31, 0, 0, 0, 0, time.UTC)
|
|
|
|
date := time.Date(2026, 5, 10, 0, 0, 0, 0, time.UTC)
|
|
teamRollup := &model.ReportingEventsRollup{
|
|
AccountID: accountID,
|
|
Date: date,
|
|
DimensionType: model.DimensionTeam,
|
|
DimensionID: 30,
|
|
Metric: model.MetricResolutionTime,
|
|
Count: 8,
|
|
SumValue: 400.0,
|
|
SumValueBusinessHours: 200.0,
|
|
}
|
|
require.NoError(t, db.Create(teamRollup).Error)
|
|
|
|
results, err := repo.GetTeamSummary(context.Background(), accountID, since, until)
|
|
require.NoError(t, err)
|
|
assert.Len(t, results, 1)
|
|
assert.Equal(t, model.DimensionTeam, results[0].DimensionType)
|
|
assert.Equal(t, uint(30), results[0].DimensionID)
|
|
}
|
|
|
|
// ========== GetInboxSummary ==========
|
|
|
|
func TestSummaryReportRepo_GetInboxSummary(t *testing.T) {
|
|
db := setupTestDB(t, &model.ReportingEventsRollup{})
|
|
repo := NewSummaryReportRepo(db)
|
|
|
|
accountID := uint(1)
|
|
since := time.Date(2026, 5, 1, 0, 0, 0, 0, time.UTC)
|
|
until := time.Date(2026, 5, 31, 0, 0, 0, 0, time.UTC)
|
|
|
|
date := time.Date(2026, 5, 12, 0, 0, 0, 0, time.UTC)
|
|
inboxRollup := &model.ReportingEventsRollup{
|
|
AccountID: accountID,
|
|
Date: date,
|
|
DimensionType: model.DimensionInbox,
|
|
DimensionID: 40,
|
|
Metric: model.MetricReplyTime,
|
|
Count: 12,
|
|
SumValue: 600.0,
|
|
SumValueBusinessHours: 300.0,
|
|
}
|
|
require.NoError(t, db.Create(inboxRollup).Error)
|
|
|
|
results, err := repo.GetInboxSummary(context.Background(), accountID, since, until)
|
|
require.NoError(t, err)
|
|
assert.Len(t, results, 1)
|
|
assert.Equal(t, model.DimensionInbox, results[0].DimensionType)
|
|
assert.Equal(t, uint(40), results[0].DimensionID)
|
|
}
|
|
|
|
// ========== GetLabelSummary ==========
|
|
|
|
func TestSummaryReportRepo_GetLabelSummary(t *testing.T) {
|
|
db := setupTestDB(t, &model.ReportingEventsRollup{})
|
|
repo := NewSummaryReportRepo(db)
|
|
|
|
accountID := uint(1)
|
|
since := time.Date(2026, 5, 1, 0, 0, 0, 0, time.UTC)
|
|
until := time.Date(2026, 5, 31, 0, 0, 0, 0, time.UTC)
|
|
|
|
date := time.Date(2026, 5, 18, 0, 0, 0, 0, time.UTC)
|
|
labelRollup := &model.ReportingEventsRollup{
|
|
AccountID: accountID,
|
|
Date: date,
|
|
DimensionType: model.DimensionLabel,
|
|
DimensionID: 50,
|
|
Metric: model.MetricResolutionsCount,
|
|
Count: 7,
|
|
SumValue: 350.0,
|
|
SumValueBusinessHours: 175.0,
|
|
}
|
|
require.NoError(t, db.Create(labelRollup).Error)
|
|
|
|
results, err := repo.GetLabelSummary(context.Background(), accountID, since, until)
|
|
require.NoError(t, err)
|
|
assert.Len(t, results, 1)
|
|
assert.Equal(t, model.DimensionLabel, results[0].DimensionType)
|
|
assert.Equal(t, uint(50), results[0].DimensionID)
|
|
}
|
|
|
|
// ========== Empty results ==========
|
|
|
|
func TestSummaryReportRepo_EmptyResults(t *testing.T) {
|
|
db := setupTestDB(t, &model.ReportingEventsRollup{})
|
|
repo := NewSummaryReportRepo(db)
|
|
|
|
accountID := uint(999)
|
|
since := time.Date(2026, 5, 1, 0, 0, 0, 0, time.UTC)
|
|
until := time.Date(2026, 5, 31, 0, 0, 0, 0, time.UTC)
|
|
|
|
results, err := repo.GetAgentSummary(context.Background(), accountID, since, until)
|
|
require.NoError(t, err)
|
|
assert.Len(t, results, 0)
|
|
|
|
results, err = repo.GetTeamSummary(context.Background(), accountID, since, until)
|
|
require.NoError(t, err)
|
|
assert.Len(t, results, 0)
|
|
|
|
results, err = repo.GetInboxSummary(context.Background(), accountID, since, until)
|
|
require.NoError(t, err)
|
|
assert.Len(t, results, 0)
|
|
|
|
results, err = repo.GetLabelSummary(context.Background(), accountID, since, until)
|
|
require.NoError(t, err)
|
|
assert.Len(t, results, 0)
|
|
} |