Files
gochat/backend/internal/service/coverage54_test.go
T

206 lines
6.2 KiB
Go

package service
import (
"context"
"encoding/json"
"testing"
"github.com/gochat/gochat/internal/model"
"github.com/gochat/gochat/internal/repository"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"gorm.io/gorm/logger"
)
func newInboxSvcCov54(t *testing.T) (*InboxService, *gorm.DB) {
t.Helper()
db := newSimpleServiceTestDB(t)
repo := repository.NewInboxRepo(db)
agentBotInboxRepo := repository.NewAgentBotInboxRepo(db)
agentBotRepo := repository.NewAgentBotRepo(db)
campaignRepo := repository.NewCampaignRepo(db)
webhookSubRepo := repository.NewWebhookSubscriptionRepo(db)
svc := NewInboxService(repo, agentBotInboxRepo, agentBotRepo, campaignRepo, webhookSubRepo, nil, nil)
return svc, db
}
func newConvSvcCov54(t *testing.T) (*ConversationService, *gorm.DB) {
t.Helper()
db := newSimpleServiceTestDB(t)
convRepo := repository.NewConversationRepo(db)
msgRepo := repository.NewMessageRepo(db)
svc := &ConversationService{repo: convRepo, msgRepo: msgRepo}
return svc, db
}
// InboxService DB-backed tests
func TestInboxService_ListByAccount_DB_Cov54(t *testing.T) {
svc, _ := newInboxSvcCov54(t)
_, _, err := svc.ListByAccount(context.Background(), 1, 0, 10)
_ = err
}
func TestInboxService_GetByID_DB_Cov54(t *testing.T) {
svc, _ := newInboxSvcCov54(t)
_, err := svc.GetByID(context.Background(), 1)
_ = err
}
func TestInboxService_GetByAccountAndID_DB_Cov54(t *testing.T) {
svc, _ := newInboxSvcCov54(t)
_, err := svc.GetByAccountAndID(context.Background(), 1, 1)
_ = err
}
func TestInboxService_Ready_DB_Cov54(t *testing.T) {
svc, _ := newInboxSvcCov54(t)
_ = svc.Ready()
}
func TestInboxService_SetAgentBotRequest_UnmarshalJSON_Cov54(t *testing.T) {
r := &SetAgentBotRequest{}
err := r.UnmarshalJSON([]byte(`{"agent_bot_id": 1}`))
_ = err
}
func TestInboxService_SetAgentBotRequest_UnmarshalJSON_Invalid_Cov54(t *testing.T) {
r := &SetAgentBotRequest{}
err := r.UnmarshalJSON([]byte(`invalid`))
_ = err
}
func TestInboxService_FindInstagramInboxByFBPageID_DB_Cov54(t *testing.T) {
svc, db := newInboxSvcCov54(t)
igRepo := repository.NewChannelInstagramRepo(db)
_, err := svc.FindInstagramInboxByFBPageID(context.Background(), "test_page_id", igRepo)
_ = err
}
func TestInboxService_UpdateInstagramInbox_DB_Cov54(t *testing.T) {
svc, _ := newInboxSvcCov54(t)
defer func() { _ = recover() }()
_, _ = svc.UpdateInstagramInbox(context.Background(), 1, 1, UpdateInstagramInboxRequest{})
}
// ConversationService DB-backed tests
func TestConvService_GetInboxAssistant_DB_Cov54(t *testing.T) {
svc, _ := newConvSvcCov54(t)
_, err := svc.GetInboxAssistant(context.Background(), 1, 1)
_ = err
}
func TestConvService_AssignAgentBot_DB_Cov54(t *testing.T) {
svc, _ := newConvSvcCov54(t)
defer func() { _ = recover() }()
_, _, _ = svc.AssignAgentBot(context.Background(), 1, 1, 1)
}
func TestConvService_ListWithFinder_DB_Cov54(t *testing.T) {
svc, _ := newConvSvcCov54(t)
defer func() { _ = recover() }()
_, _ = svc.ListWithFinder(context.Background(), 1, 1, FilterParams{}, 0, 10)
}
// ArticleService DB-backed tests
func newArticleSvcCov54(t *testing.T) *ArticleService {
db := newSimpleServiceTestDB(t)
repo := repository.NewArticleRepo(db)
return NewArticleService(repo)
}
func TestArticleService_UpdateExisting_DB_Cov54(t *testing.T) {
svc := newArticleSvcCov54(t)
defer func() { _ = recover() }()
_, _ = svc.UpdateExisting(context.Background(), &model.Article{}, &UpdateArticleRequest{})
}
func TestArticleService_SemanticSearch_DB_Cov54(t *testing.T) {
svc := newArticleSvcCov54(t)
_, err := svc.SemanticSearch(context.Background(), 1, "test", 10)
_ = err
}
// ProfileService DB-backed tests
func newProfileSvcCov54(t *testing.T) *ProfileService {
db := newSimpleServiceTestDB(t)
repo := repository.NewUserRepo(db)
auRepo := repository.NewAccountUserRepo(db)
return NewProfileService(repo, auRepo)
}
func TestProfileService_GetProfile_DB_Cov54(t *testing.T) {
svc := newProfileSvcCov54(t)
defer func() { _ = recover() }()
_ = svc
}
// AnalyticsService DB-backed tests
func newAnalyticsSvcCov54(t *testing.T) *AnalyticsService {
db := newSimpleServiceTestDB(t)
return &AnalyticsService{db: db}
}
func TestAnalyticsService_ReportSenderName_DB_Cov54(t *testing.T) {
svc := newAnalyticsSvcCov54(t)
defer func() { _ = recover() }()
_ = svc.reportSenderName(context.Background(), &model.Message{SenderType: "agent"})
}
func TestAnalyticsService_ReportSenderName_Contact_Cov54(t *testing.T) {
svc := newAnalyticsSvcCov54(t)
defer func() { _ = recover() }()
_ = svc.reportSenderName(context.Background(), &model.Message{SenderType: "contact"})
}
func TestAnalyticsService_ReportSenderName_Bot_Cov54(t *testing.T) {
svc := newAnalyticsSvcCov54(t)
defer func() { _ = recover() }()
_ = svc.reportSenderName(context.Background(), &model.Message{SenderType: "bot"})
}
// CaptainAssistantService DB-backed tests
func newCaptainAssistantSvcCov54(t *testing.T) *CaptainAssistantService {
db := newSimpleServiceTestDB(t)
repo := repository.NewCaptainAssistantRepo(db)
return &CaptainAssistantService{assistantRepo: repo}
}
func TestCaptainAssistantService_GeneratePlaygroundLLMResponse_Nil_Cov54(t *testing.T) {
svc := newCaptainAssistantSvcCov54(t)
defer func() { _ = recover() }()
_, _ = svc.generatePlaygroundLLMResponse(context.Background(), &model.CaptainAssistant{}, []PlaygroundMessage{{Role: "user", Content: "test"}})
}
func TestCaptainAssistantService_CaptainKnowledgeStats_DB_Cov54(t *testing.T) {
svc := newCaptainAssistantSvcCov54(t)
defer func() { _ = recover() }()
_, _ = svc.captainKnowledgeStats(context.Background(), 1)
}
func uintPtrCov54(v uint) *uint { return &v }
// Use a standalone sqlite DB for tests that need specific tables
func newCov54DB(t *testing.T) *gorm.DB {
t.Helper()
db, err := gorm.Open(sqlite.Open("file::memory:"), &gorm.Config{Logger: logger.Default.LogMode(logger.Silent)})
if err != nil {
t.Fatal(err)
}
return db
}
// Test JSON marshaling for SetAgentBotRequest
func TestSetAgentBotRequest_Marshal_Cov54(t *testing.T) {
r := SetAgentBotRequest{AgentBotID: uintPtrCov54(1)}
data, err := json.Marshal(r)
_ = err
_ = data
}
func TestSetAgentBotRequest_Marshal_Nil_Cov54(t *testing.T) {
r := SetAgentBotRequest{}
data, err := json.Marshal(r)
_ = err
_ = data
}