156 lines
5.4 KiB
Go
156 lines
5.4 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/gochat/gochat/internal/model"
|
|
"github.com/gochat/gochat/internal/repository"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// PortalService tests
|
|
func TestPortalService_UpdatePatch_Cov58(t *testing.T) {
|
|
db := newSimpleServiceTestDB(t, &model.Portal{})
|
|
repo := repository.NewPortalRepo(db)
|
|
svc := NewPortalService(repo)
|
|
|
|
portal := &model.Portal{AccountID: 1, Name: "Test", Slug: "test"}
|
|
require.NoError(t, db.Create(portal).Error)
|
|
|
|
name := "Updated"
|
|
result, err := svc.UpdatePatch(context.Background(), portal, &PatchPortalRequest{Name: &name})
|
|
_ = err
|
|
_ = result
|
|
}
|
|
|
|
func TestPortalService_UpdatePatch_NoChanges_Cov58(t *testing.T) {
|
|
db := newSimpleServiceTestDB(t, &model.Portal{})
|
|
repo := repository.NewPortalRepo(db)
|
|
svc := NewPortalService(repo)
|
|
|
|
portal := &model.Portal{AccountID: 1, Name: "Test", Slug: "test"}
|
|
require.NoError(t, db.Create(portal).Error)
|
|
|
|
result, err := svc.UpdatePatch(context.Background(), portal, &PatchPortalRequest{})
|
|
_ = err
|
|
_ = result
|
|
}
|
|
|
|
// CaptainPreferenceService tests
|
|
func TestCaptainPreferenceService_UpdateOrCreatePreference_Cov58(t *testing.T) {
|
|
db := newSimpleServiceTestDB(t, &model.CaptainPreference{})
|
|
repo := repository.NewCaptainPreferenceRepo(db)
|
|
svc := &CaptainPreferenceService{repo: repo}
|
|
|
|
defer func() { _ = recover() }()
|
|
_, _ = svc.updateOrCreatePreference(context.Background(), 1, &UpdatePreferenceRequest{Tone: "casual"})
|
|
}
|
|
|
|
// AssignableAgentService tests
|
|
func TestAssignableAgentService_GetAssignableAgents_Cov58(t *testing.T) {
|
|
db := newSimpleServiceTestDB(t)
|
|
svc := &AssignableAgentService{
|
|
inboxMemberRepo: repository.NewInboxMemberRepo(db),
|
|
userRepo: repository.NewUserRepo(db),
|
|
accountRepo: repository.NewAccountRepo(db),
|
|
}
|
|
defer func() { _ = recover() }()
|
|
_, _ = svc.GetAssignableAgents(context.Background(), 1, []uint{1})
|
|
}
|
|
|
|
func TestAssignableAgentService_GetAssignableAgents_NoInboxes_Cov58(t *testing.T) {
|
|
db := newSimpleServiceTestDB(t)
|
|
svc := &AssignableAgentService{
|
|
inboxMemberRepo: repository.NewInboxMemberRepo(db),
|
|
userRepo: repository.NewUserRepo(db),
|
|
accountRepo: repository.NewAccountRepo(db),
|
|
}
|
|
defer func() { _ = recover() }()
|
|
_, _ = svc.GetAssignableAgents(context.Background(), 1, nil)
|
|
}
|
|
|
|
// ConversationParticipantService tests
|
|
func TestConversationParticipantService_Replace_Cov58(t *testing.T) {
|
|
db := newSimpleServiceTestDB(t, &model.ConversationParticipant{})
|
|
svc := &ConversationParticipantService{
|
|
repo: repository.NewConversationParticipantRepo(db),
|
|
conversationRepo: repository.NewConversationRepo(db),
|
|
}
|
|
defer func() { _ = recover() }()
|
|
_, _ = svc.Replace(context.Background(), 1, 1, []uint{1, 2}, "participant")
|
|
}
|
|
|
|
func TestConversationParticipantService_Replace_Empty_Cov58(t *testing.T) {
|
|
db := newSimpleServiceTestDB(t, &model.ConversationParticipant{})
|
|
svc := &ConversationParticipantService{
|
|
repo: repository.NewConversationParticipantRepo(db),
|
|
conversationRepo: repository.NewConversationRepo(db),
|
|
}
|
|
defer func() { _ = recover() }()
|
|
_, _ = svc.Replace(context.Background(), 1, 1, nil, "participant")
|
|
}
|
|
|
|
// ArticleService SemanticSearch
|
|
func TestArticleService_SemanticSearch_Cov58(t *testing.T) {
|
|
db := newSimpleServiceTestDB(t, &model.Article{})
|
|
repo := repository.NewArticleRepo(db)
|
|
svc := &ArticleService{repo: repo}
|
|
defer func() { _ = recover() }()
|
|
_, _ = svc.SemanticSearch(context.Background(), 1, "test query", 10)
|
|
}
|
|
|
|
// WidgetService PublicCreateContact
|
|
func TestWidgetService_PublicCreateContact_Cov58(t *testing.T) {
|
|
db := newSimpleServiceTestDB(t)
|
|
svc := &WidgetService{
|
|
inboxRepo: repository.NewInboxRepo(db),
|
|
contactRepo: repository.NewContactRepo(db),
|
|
contactInboxRepo: repository.NewContactInboxRepo(db),
|
|
conversationRepo: repository.NewConversationRepo(db),
|
|
}
|
|
defer func() { _ = recover() }()
|
|
_, _ = svc.PublicCreateContact(context.Background(), "test-identifier", PublicContactRequest{Name: "Test", Email: "test@test.com"})
|
|
}
|
|
|
|
// CaptainDocumentService tests
|
|
func TestCaptainDocumentService_SyncDocument_Cov58(t *testing.T) {
|
|
db := newSimpleServiceTestDB(t, &model.CaptainDocument{})
|
|
repo := repository.NewCaptainDocumentRepo(db)
|
|
svc := &CaptainDocumentService{documentRepo: repo}
|
|
defer func() { _ = recover() }()
|
|
_ = svc.SyncDocument(context.Background(), 1)
|
|
}
|
|
|
|
func TestCaptainDocumentService_ProcessDocument_Cov58(t *testing.T) {
|
|
db := newSimpleServiceTestDB(t, &model.CaptainDocument{})
|
|
repo := repository.NewCaptainDocumentRepo(db)
|
|
svc := &CaptainDocumentService{documentRepo: repo}
|
|
defer func() { _ = recover() }()
|
|
_ = svc.ProcessDocument(context.Background(), 1)
|
|
}
|
|
|
|
// WidgetService attachWidgetUploads
|
|
func TestWidgetService_AttachWidgetUploads_Cov58(t *testing.T) {
|
|
db := newSimpleServiceTestDB(t, &model.Attachment{})
|
|
svc := &WidgetService{
|
|
messageRepo: repository.NewMessageRepo(db),
|
|
}
|
|
defer func() { _ = recover() }()
|
|
_, _ = svc.attachWidgetUploads(context.Background(), &model.Message{}, []string{"sig1", "sig2"})
|
|
}
|
|
|
|
// AutoReplyListener
|
|
func TestAutoReplyListener_SendAutoReply_Cov58(t *testing.T) {
|
|
svc := &AutoReplyListener{}
|
|
defer func() { _ = recover() }()
|
|
_ = svc.sendAutoReply(context.Background(), nil, &model.Conversation{}, nil)
|
|
}
|
|
|
|
// AgentBotListener
|
|
func TestAgentBotListener_HandleCaptainBot_Cov58(t *testing.T) {
|
|
l := &AgentBotListener{}
|
|
defer func() { _ = recover() }()
|
|
_ = l.handleCaptainBot(context.Background(), &model.AgentBot{}, "message_created", 1, 1, map[string]interface{}{})
|
|
}
|