package service import ( "context" "testing" "time" "github.com/gochat/gochat/internal/campaign" "github.com/gochat/gochat/internal/model" channelmodel "github.com/gochat/gochat/internal/model/channel" "github.com/gochat/gochat/internal/repository" "github.com/gochat/gochat/internal/search" "github.com/stretchr/testify/require" "gorm.io/datatypes" "gorm.io/gorm" ) // safeCall62 wraps a function call and recovers from panics. func safeCall62(fn func()) { defer func() { _ = recover() }() fn() } // seedCov62 creates the standard set of test entities and returns them. func seedCov62(t *testing.T, db *gorm.DB) (*model.Account, *model.User, *model.Inbox, *model.Contact, *model.Conversation) { t.Helper() acc := &model.Account{Name: "test"} require.NoError(t, db.Create(acc).Error) user := &model.User{AccountID: acc.ID, Name: "u", Email: "u@t.com", Password: "p"} require.NoError(t, db.Create(user).Error) require.NoError(t, db.Create(&model.AccountUser{AccountID: acc.ID, UserID: user.ID, Role: "administrator"}).Error) inbox := &model.Inbox{AccountID: acc.ID, Name: "i", ChannelType: "web_widget"} require.NoError(t, db.Create(inbox).Error) contact := &model.Contact{AccountID: acc.ID, Name: "c", Email: "c@t.com"} require.NoError(t, db.Create(contact).Error) require.NoError(t, db.Create(&model.ContactInbox{ContactID: contact.ID, InboxID: inbox.ID, SourceID: "s"}).Error) conv := &model.Conversation{AccountID: acc.ID, InboxID: inbox.ID, ContactID: contact.ID, Status: "open"} require.NoError(t, db.Create(conv).Error) return acc, user, inbox, contact, conv } // cov62DB creates a test DB with extra models. func cov62DB(t *testing.T, extras ...interface{}) *gorm.DB { t.Helper() all := append([]interface{}{}, extras...) return newSimpleServiceTestDB(t, all...) } // ==================================================================== // WidgetService tests // ==================================================================== func TestWidgetService_GetConversations_Cov62(t *testing.T) { db := cov62DB(t) _, _, inbox, contact, _ := seedCov62(t, db) ci := &model.ContactInbox{ContactID: contact.ID, InboxID: inbox.ID, SourceID: "s2", PubsubToken: "tok62"} require.NoError(t, db.Create(ci).Error) svc := &WidgetService{ inboxRepo: repository.NewInboxRepo(db), contactRepo: repository.NewContactRepo(db), contactInboxRepo: repository.NewContactInboxRepo(db), conversationRepo: repository.NewConversationRepo(db), messageRepo: repository.NewMessageRepo(db), } defer func() { _ = recover() }() _, _ = svc.GetConversations(context.Background(), "tok62") } func TestWidgetService_GetLatestConversation_Cov62(t *testing.T) { db := cov62DB(t) _, _, inbox, contact, _ := seedCov62(t, db) ci := &model.ContactInbox{ContactID: contact.ID, InboxID: inbox.ID, SourceID: "s3", PubsubToken: "tok63"} require.NoError(t, db.Create(ci).Error) conv := &model.Conversation{AccountID: inbox.AccountID, InboxID: inbox.ID, ContactID: contact.ID, Status: "open"} require.NoError(t, db.Create(conv).Error) svc := &WidgetService{ contactInboxRepo: repository.NewContactInboxRepo(db), conversationRepo: repository.NewConversationRepo(db), } defer func() { _ = recover() }() _, _ = svc.GetLatestConversation(context.Background(), "tok63") } func TestWidgetService_GetConversation_Cov62(t *testing.T) { db := cov62DB(t) _, _, inbox, contact, conv := seedCov62(t, db) ci := &model.ContactInbox{ContactID: contact.ID, InboxID: inbox.ID, SourceID: "s4", PubsubToken: "tok64"} require.NoError(t, db.Create(ci).Error) svc := &WidgetService{ contactInboxRepo: repository.NewContactInboxRepo(db), conversationRepo: repository.NewConversationRepo(db), } defer func() { _ = recover() }() _, _ = svc.GetConversation(context.Background(), "tok64", conv.ID) } func TestWidgetService_GetMessages_Cov62(t *testing.T) { db := cov62DB(t) _, _, inbox, contact, conv := seedCov62(t, db) ci := &model.ContactInbox{ContactID: contact.ID, InboxID: inbox.ID, SourceID: "s5", PubsubToken: "tok65"} require.NoError(t, db.Create(ci).Error) svc := &WidgetService{ contactInboxRepo: repository.NewContactInboxRepo(db), conversationRepo: repository.NewConversationRepo(db), messageRepo: repository.NewMessageRepo(db), } defer func() { _ = recover() }() _, _, _ = svc.GetMessages(context.Background(), "tok65", conv.ID, 0, 20) } func TestWidgetService_GetMessageAttachments_Cov62(t *testing.T) { db := cov62DB(t) _, _, _, _, _ = seedCov62(t, db) svc := &WidgetService{ messageRepo: repository.NewMessageRepo(db), } defer func() { _ = recover() }() _, _ = svc.GetMessageAttachments(context.Background(), 1) } func TestWidgetService_GetCableToken_Cov62(t *testing.T) { db := cov62DB(t) _, _, inbox, contact, _ := seedCov62(t, db) ci := &model.ContactInbox{ContactID: contact.ID, InboxID: inbox.ID, SourceID: "s6", PubsubToken: "tok66"} require.NoError(t, db.Create(ci).Error) svc := &WidgetService{ inboxRepo: repository.NewInboxRepo(db), contactInboxRepo: repository.NewContactInboxRepo(db), } defer func() { _ = recover() }() _, _ = svc.GetCableToken(context.Background(), "tok66") } func TestWidgetService_GetContact_Cov62(t *testing.T) { db := cov62DB(t) _, _, inbox, contact, _ := seedCov62(t, db) ci := &model.ContactInbox{ContactID: contact.ID, InboxID: inbox.ID, SourceID: "s7", PubsubToken: "tok67"} require.NoError(t, db.Create(ci).Error) svc := &WidgetService{ contactRepo: repository.NewContactRepo(db), contactInboxRepo: repository.NewContactInboxRepo(db), } defer func() { _ = recover() }() _, _ = svc.GetContact(context.Background(), "tok67") } func TestWidgetService_UpdateContact_Cov62(t *testing.T) { db := cov62DB(t) _, _, inbox, contact, _ := seedCov62(t, db) ci := &model.ContactInbox{ContactID: contact.ID, InboxID: inbox.ID, SourceID: "s8", PubsubToken: "tok68"} require.NoError(t, db.Create(ci).Error) svc := &WidgetService{ contactRepo: repository.NewContactRepo(db), contactInboxRepo: repository.NewContactInboxRepo(db), } defer func() { _ = recover() }() _, _ = svc.UpdateContact(context.Background(), "tok68", "NewName", "new@t.com") } func TestWidgetService_UpdateContactProfile_Cov62(t *testing.T) { db := cov62DB(t) _, _, inbox, contact, _ := seedCov62(t, db) ci := &model.ContactInbox{ContactID: contact.ID, InboxID: inbox.ID, SourceID: "s9", PubsubToken: "tok69"} require.NoError(t, db.Create(ci).Error) svc := &WidgetService{ contactRepo: repository.NewContactRepo(db), contactInboxRepo: repository.NewContactInboxRepo(db), } defer func() { _ = recover() }() _, _ = svc.UpdateContactProfile(context.Background(), "tok69", WidgetContactUpdate{Name: "Updated", Email: "upd@t.com"}) } func TestWidgetService_GetLatestConversationMessages_Cov62(t *testing.T) { db := cov62DB(t) _, _, inbox, contact, _ := seedCov62(t, db) ci := &model.ContactInbox{ContactID: contact.ID, InboxID: inbox.ID, SourceID: "s10", PubsubToken: "tok610"} require.NoError(t, db.Create(ci).Error) conv := &model.Conversation{AccountID: inbox.AccountID, InboxID: inbox.ID, ContactID: contact.ID, Status: "open"} require.NoError(t, db.Create(conv).Error) svc := &WidgetService{ contactInboxRepo: repository.NewContactInboxRepo(db), conversationRepo: repository.NewConversationRepo(db), messageRepo: repository.NewMessageRepo(db), } defer func() { _ = recover() }() _, _, _, _ = svc.GetLatestConversationMessages(context.Background(), "tok610", 0, 0) } func TestWidgetService_AddLabelToLatestConversation_Cov62(t *testing.T) { db := cov62DB(t) _, _, inbox, contact, _ := seedCov62(t, db) ci := &model.ContactInbox{ContactID: contact.ID, InboxID: inbox.ID, SourceID: "s11", PubsubToken: "tok611"} require.NoError(t, db.Create(ci).Error) conv := &model.Conversation{AccountID: inbox.AccountID, InboxID: inbox.ID, ContactID: contact.ID, Status: "open"} require.NoError(t, db.Create(conv).Error) svc := &WidgetService{ contactInboxRepo: repository.NewContactInboxRepo(db), conversationRepo: repository.NewConversationRepo(db), tagRepo: repository.NewTagRepo(db), } defer func() { _ = recover() }() _ = svc.AddLabelToLatestConversation(context.Background(), "tok611", "test-label") } func TestWidgetService_RemoveLabelFromLatestConversation_Cov62(t *testing.T) { db := cov62DB(t) _, _, inbox, contact, _ := seedCov62(t, db) ci := &model.ContactInbox{ContactID: contact.ID, InboxID: inbox.ID, SourceID: "s12", PubsubToken: "tok612"} require.NoError(t, db.Create(ci).Error) conv := &model.Conversation{AccountID: inbox.AccountID, InboxID: inbox.ID, ContactID: contact.ID, Status: "open", Labels: "label1"} require.NoError(t, db.Create(conv).Error) svc := &WidgetService{ contactInboxRepo: repository.NewContactInboxRepo(db), conversationRepo: repository.NewConversationRepo(db), } defer func() { _ = recover() }() _ = svc.RemoveLabelFromLatestConversation(context.Background(), "tok612", "label1") } func TestWidgetService_DeleteContactCustomAttributes_Cov62(t *testing.T) { db := cov62DB(t) _, _, inbox, contact, _ := seedCov62(t, db) ci := &model.ContactInbox{ContactID: contact.ID, InboxID: inbox.ID, SourceID: "s13", PubsubToken: "tok613"} require.NoError(t, db.Create(ci).Error) svc := &WidgetService{ contactRepo: repository.NewContactRepo(db), contactInboxRepo: repository.NewContactInboxRepo(db), } defer func() { _ = recover() }() _, _ = svc.DeleteContactCustomAttributes(context.Background(), "tok613", []string{"key1"}) } func TestWidgetService_UpdateLastSeen_Cov62(t *testing.T) { db := cov62DB(t) _, _, inbox, contact, _ := seedCov62(t, db) ci := &model.ContactInbox{ContactID: contact.ID, InboxID: inbox.ID, SourceID: "s14", PubsubToken: "tok614"} require.NoError(t, db.Create(ci).Error) conv := &model.Conversation{AccountID: inbox.AccountID, InboxID: inbox.ID, ContactID: contact.ID, Status: "open"} require.NoError(t, db.Create(conv).Error) svc := &WidgetService{ contactInboxRepo: repository.NewContactInboxRepo(db), conversationRepo: repository.NewConversationRepo(db), } defer func() { _ = recover() }() _, _ = svc.UpdateLastSeen(context.Background(), "tok614") } func TestWidgetService_SetLatestConversationCustomAttributes_Cov62(t *testing.T) { db := cov62DB(t) _, _, inbox, contact, _ := seedCov62(t, db) ci := &model.ContactInbox{ContactID: contact.ID, InboxID: inbox.ID, SourceID: "s15", PubsubToken: "tok615"} require.NoError(t, db.Create(ci).Error) conv := &model.Conversation{AccountID: inbox.AccountID, InboxID: inbox.ID, ContactID: contact.ID, Status: "open"} require.NoError(t, db.Create(conv).Error) svc := &WidgetService{ contactInboxRepo: repository.NewContactInboxRepo(db), conversationRepo: repository.NewConversationRepo(db), } defer func() { _ = recover() }() _, _ = svc.SetLatestConversationCustomAttributes(context.Background(), "tok615", map[string]any{"key": "val"}) } func TestWidgetService_DeleteLatestConversationCustomAttributes_Cov62(t *testing.T) { db := cov62DB(t) _, _, inbox, contact, _ := seedCov62(t, db) ci := &model.ContactInbox{ContactID: contact.ID, InboxID: inbox.ID, SourceID: "s16", PubsubToken: "tok616"} require.NoError(t, db.Create(ci).Error) conv := &model.Conversation{AccountID: inbox.AccountID, InboxID: inbox.ID, ContactID: contact.ID, Status: "open"} require.NoError(t, db.Create(conv).Error) svc := &WidgetService{ contactInboxRepo: repository.NewContactInboxRepo(db), conversationRepo: repository.NewConversationRepo(db), } defer func() { _ = recover() }() _, _ = svc.DeleteLatestConversationCustomAttributes(context.Background(), "tok616", []string{"key1"}) } func TestWidgetService_ToggleTyping_Cov62(t *testing.T) { db := cov62DB(t) _, _, inbox, contact, conv := seedCov62(t, db) ci := &model.ContactInbox{ContactID: contact.ID, InboxID: inbox.ID, SourceID: "s17", PubsubToken: "tok617"} require.NoError(t, db.Create(ci).Error) svc := &WidgetService{ contactInboxRepo: repository.NewContactInboxRepo(db), conversationRepo: repository.NewConversationRepo(db), } defer func() { _ = recover() }() _ = svc.ToggleTyping(context.Background(), "tok617", conv.ID, true) } func TestWidgetService_SendTranscript_Cov62(t *testing.T) { db := cov62DB(t) _, _, inbox, contact, _ := seedCov62(t, db) ci := &model.ContactInbox{ContactID: contact.ID, InboxID: inbox.ID, SourceID: "s18", PubsubToken: "tok618"} require.NoError(t, db.Create(ci).Error) conv := &model.Conversation{AccountID: inbox.AccountID, InboxID: inbox.ID, ContactID: contact.ID, Status: "open"} require.NoError(t, db.Create(conv).Error) svc := &WidgetService{ contactRepo: repository.NewContactRepo(db), contactInboxRepo: repository.NewContactInboxRepo(db), conversationRepo: repository.NewConversationRepo(db), messageRepo: repository.NewMessageRepo(db), } defer func() { _ = recover() }() _ = svc.SendTranscript(context.Background(), "tok618") } func TestWidgetService_ResolveLatestConversation_Cov62(t *testing.T) { db := cov62DB(t) _, _, inbox, contact, _ := seedCov62(t, db) ci := &model.ContactInbox{ContactID: contact.ID, InboxID: inbox.ID, SourceID: "s19", PubsubToken: "tok619"} require.NoError(t, db.Create(ci).Error) conv := &model.Conversation{AccountID: inbox.AccountID, InboxID: inbox.ID, ContactID: contact.ID, Status: "open"} require.NoError(t, db.Create(conv).Error) svc := &WidgetService{ inboxRepo: repository.NewInboxRepo(db), contactRepo: repository.NewContactRepo(db), contactInboxRepo: repository.NewContactInboxRepo(db), conversationRepo: repository.NewConversationRepo(db), messageRepo: repository.NewMessageRepo(db), } defer func() { _ = recover() }() _, _ = svc.ResolveLatestConversation(context.Background(), "tok619") } func TestWidgetService_VerifyHMAC_Cov62(t *testing.T) { defer func() { _ = recover() }() _ = VerifyHMAC("token", "identifier", "sig") } func TestWidgetService_ParseWebWidgetConfig_Cov62(t *testing.T) { defer func() { _ = recover() }() _, _ = ParseWebWidgetConfig(`{"website_token":"wt"}`) } func TestWidgetService_widgetAccountFeatureEnabled_Cov62(t *testing.T) { defer func() { _ = recover() }() _ = widgetAccountFeatureEnabled(`{"campaigns":true}`, "campaigns") } func TestWidgetService_splitWidgetLabels_Cov62(t *testing.T) { defer func() { _ = recover() }() _ = splitWidgetLabels("a,b,c") } func TestWidgetService_shouldVerifyWidgetSetUserHMAC_Cov62(t *testing.T) { defer func() { _ = recover() }() _ = shouldVerifyWidgetSetUserHMAC(&WebWidgetConfig{HMACMandatory: true}, WidgetSetUserRequest{IdentifierHash: "hash"}) } // ==================================================================== // InboxService tests // ==================================================================== func TestInboxService_Ready_Cov62(t *testing.T) { db := cov62DB(t) svc := &InboxService{repo: repository.NewInboxRepo(db)} defer func() { _ = recover() }() _ = svc.Ready() } func TestInboxService_DB_Cov62(t *testing.T) { db := cov62DB(t) svc := &InboxService{repo: repository.NewInboxRepo(db)} defer func() { _ = recover() }() _ = svc.DB() } func TestInboxService_GetByID_Cov62(t *testing.T) { db := cov62DB(t) _, _, inbox, _, _ := seedCov62(t, db) svc := &InboxService{repo: repository.NewInboxRepo(db)} defer func() { _ = recover() }() _, _ = svc.GetByID(context.Background(), inbox.ID) } func TestInboxService_GetByAccountAndID_Cov62(t *testing.T) { db := cov62DB(t) acc, _, inbox, _, _ := seedCov62(t, db) svc := &InboxService{repo: repository.NewInboxRepo(db)} defer func() { _ = recover() }() _, _ = svc.GetByAccountAndID(context.Background(), acc.ID, inbox.ID) } func TestInboxService_ListByAccount_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, _ := seedCov62(t, db) svc := &InboxService{repo: repository.NewInboxRepo(db)} defer func() { _ = recover() }() _, _, _ = svc.ListByAccount(context.Background(), acc.ID, 0, 10) } func TestInboxService_EnsureCanCreateInbox_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, _ := seedCov62(t, db) svc := &InboxService{repo: repository.NewInboxRepo(db)} defer func() { _ = recover() }() _ = svc.EnsureCanCreateInbox(context.Background(), acc.ID) } func TestInboxService_Create_Cov62(t *testing.T) { db := cov62DB(t, &channelmodel.ChannelAPI{}) acc, _, _, _, _ := seedCov62(t, db) svc := &InboxService{repo: repository.NewInboxRepo(db)} defer func() { _ = recover() }() _, _ = svc.Create(context.Background(), acc.ID, CreateInboxRequest{ Name: "TestInbox2", ChannelType: "web_widget", }) } func TestInboxService_Create_API_Cov62(t *testing.T) { db := cov62DB(t, &channelmodel.ChannelAPI{}) acc, _, _, _, _ := seedCov62(t, db) svc := &InboxService{repo: repository.NewInboxRepo(db)} defer func() { _ = recover() }() _, _ = svc.Create(context.Background(), acc.ID, CreateInboxRequest{ Name: "APIInbox", ChannelType: "api", Channel: map[string]any{"webhook_url": "https://example.com/wh"}, }) } func TestInboxService_Update_Cov62(t *testing.T) { db := cov62DB(t, &channelmodel.ChannelAPI{}) acc, _, inbox, _, _ := seedCov62(t, db) svc := &InboxService{repo: repository.NewInboxRepo(db)} defer func() { _ = recover() }() enabled := true _, _ = svc.Update(context.Background(), acc.ID, inbox.ID, UpdateInboxRequest{ Name: "UpdatedInbox", Enabled: &enabled, }) } func TestInboxService_BindChannel_Cov62(t *testing.T) { db := cov62DB(t) acc, _, inbox, _, _ := seedCov62(t, db) svc := &InboxService{repo: repository.NewInboxRepo(db)} defer func() { _ = recover() }() _, _ = svc.BindChannel(context.Background(), acc.ID, inbox.ID, 1, map[string]any{"key": "val"}) } func TestInboxService_IsInboxLimitExceeded_Cov62(t *testing.T) { defer func() { _ = recover() }() _ = IsInboxLimitExceeded(ErrInboxLimitExceeded) } // ==================================================================== // ConversationService tests // ==================================================================== func TestConversationService_DB_Cov62(t *testing.T) { db := cov62DB(t) svc := &ConversationService{repo: repository.NewConversationRepo(db), msgRepo: repository.NewMessageRepo(db)} defer func() { _ = recover() }() _ = svc.DB() } func TestConversationService_ListByAccount_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, _ := seedCov62(t, db) svc := &ConversationService{repo: repository.NewConversationRepo(db), msgRepo: repository.NewMessageRepo(db)} defer func() { _ = recover() }() _, _, _ = svc.ListByAccount(context.Background(), acc.ID, 0, 10) } func TestConversationService_ListByInbox_Cov62(t *testing.T) { db := cov62DB(t) acc, _, inbox, _, _ := seedCov62(t, db) svc := &ConversationService{repo: repository.NewConversationRepo(db), msgRepo: repository.NewMessageRepo(db)} defer func() { _ = recover() }() _, _, _ = svc.ListByInbox(context.Background(), acc.ID, inbox.ID, 0, 10) } func TestConversationService_ListByStatus_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, _ := seedCov62(t, db) svc := &ConversationService{repo: repository.NewConversationRepo(db), msgRepo: repository.NewMessageRepo(db)} defer func() { _ = recover() }() _, _, _ = svc.ListByStatus(context.Background(), acc.ID, "open", 0, 10) } func TestConversationService_ListByAssignee_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, _ := seedCov62(t, db) svc := &ConversationService{repo: repository.NewConversationRepo(db), msgRepo: repository.NewMessageRepo(db)} defer func() { _ = recover() }() _, _, _ = svc.ListByAssignee(context.Background(), acc.ID, 1, 0, 10) } func TestConversationService_ListRecentByContact_Cov62(t *testing.T) { db := cov62DB(t) acc, _, inbox, contact, _ := seedCov62(t, db) svc := &ConversationService{repo: repository.NewConversationRepo(db), msgRepo: repository.NewMessageRepo(db)} defer func() { _ = recover() }() _, _ = svc.ListRecentByContact(context.Background(), acc.ID, contact.ID, &inbox.ID, 10) } func TestConversationService_ListUnassigned_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, _ := seedCov62(t, db) svc := &ConversationService{repo: repository.NewConversationRepo(db), msgRepo: repository.NewMessageRepo(db)} defer func() { _ = recover() }() _, _, _ = svc.ListUnassigned(context.Background(), acc.ID, 0, 10) } func TestConversationService_GetByID_Cov62(t *testing.T) { db := cov62DB(t) _, _, _, _, conv := seedCov62(t, db) svc := &ConversationService{repo: repository.NewConversationRepo(db), msgRepo: repository.NewMessageRepo(db)} defer func() { _ = recover() }() _, _ = svc.GetByID(context.Background(), conv.ID) } func TestConversationService_GetByAccountAndID_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, conv := seedCov62(t, db) svc := &ConversationService{repo: repository.NewConversationRepo(db), msgRepo: repository.NewMessageRepo(db)} defer func() { _ = recover() }() _, _ = svc.GetByAccountAndID(context.Background(), acc.ID, conv.ID) } func TestConversationService_GetByAccountAndDisplayIDOrID_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, conv := seedCov62(t, db) svc := &ConversationService{repo: repository.NewConversationRepo(db), msgRepo: repository.NewMessageRepo(db)} defer func() { _ = recover() }() _, _ = svc.GetByAccountAndDisplayIDOrID(context.Background(), acc.ID, conv.ID) } func TestConversationService_Create_Cov62(t *testing.T) { db := cov62DB(t) acc, _, inbox, contact, _ := seedCov62(t, db) svc := &ConversationService{repo: repository.NewConversationRepo(db), msgRepo: repository.NewMessageRepo(db)} defer func() { _ = recover() }() _, _ = svc.Create(context.Background(), acc.ID, CreateConversationRequest{ InboxID: inbox.ID, ContactID: contact.ID, Status: "open", }) } func TestConversationService_Create_WithMessage_Cov62(t *testing.T) { db := cov62DB(t) acc, _, inbox, contact, _ := seedCov62(t, db) svc := &ConversationService{repo: repository.NewConversationRepo(db), msgRepo: repository.NewMessageRepo(db)} defer func() { _ = recover() }() _, _ = svc.Create(context.Background(), acc.ID, CreateConversationRequest{ InboxID: inbox.ID, ContactID: contact.ID, Status: "open", MessageContent: "Hello", MessageType: "outgoing", }) } func TestConversationService_Update_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, conv := seedCov62(t, db) svc := &ConversationService{repo: repository.NewConversationRepo(db), msgRepo: repository.NewMessageRepo(db)} defer func() { _ = recover() }() _, _ = svc.Update(context.Background(), acc.ID, conv.ID, UpdateConversationRequest{ Status: "resolved", Priority: "high", }) } func TestConversationService_AssignAgent_Unassign_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, conv := seedCov62(t, db) svc := &ConversationService{repo: repository.NewConversationRepo(db), msgRepo: repository.NewMessageRepo(db)} defer func() { _ = recover() }() _, _ = svc.AssignAgent(context.Background(), acc.ID, conv.ID, 0) } func TestConversationService_UnassignAgent_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, conv := seedCov62(t, db) svc := &ConversationService{repo: repository.NewConversationRepo(db), msgRepo: repository.NewMessageRepo(db)} defer func() { _ = recover() }() _, _ = svc.UnassignAgent(context.Background(), acc.ID, conv.ID) } func TestConversationService_ToggleStatus_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, conv := seedCov62(t, db) svc := &ConversationService{repo: repository.NewConversationRepo(db), msgRepo: repository.NewMessageRepo(db)} defer func() { _ = recover() }() _, _ = svc.ToggleStatus(context.Background(), acc.ID, conv.ID, ToggleStatusRequest{Status: "resolved"}) } func TestConversationService_ToggleStatus_Reopen_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, conv := seedCov62(t, db) conv.Status = "resolved" require.NoError(t, db.Save(conv).Error) svc := &ConversationService{repo: repository.NewConversationRepo(db), msgRepo: repository.NewMessageRepo(db)} defer func() { _ = recover() }() _, _ = svc.ToggleStatus(context.Background(), acc.ID, conv.ID, ToggleStatusRequest{Status: "open"}) } func TestConversationService_UpdateLabels_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, conv := seedCov62(t, db) svc := &ConversationService{repo: repository.NewConversationRepo(db), msgRepo: repository.NewMessageRepo(db)} defer func() { _ = recover() }() _, _ = svc.UpdateLabels(context.Background(), acc.ID, conv.ID, []string{"label1", "label2"}) } func TestConversationService_Delete_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, conv := seedCov62(t, db) svc := &ConversationService{repo: repository.NewConversationRepo(db), msgRepo: repository.NewMessageRepo(db)} defer func() { _ = recover() }() _ = svc.Delete(context.Background(), acc.ID, conv.ID) } func TestConversationService_ListMessages_Cov62(t *testing.T) { db := cov62DB(t) _, _, _, _, conv := seedCov62(t, db) require.NoError(t, db.Create(&model.Message{AccountID: conv.AccountID, ConversationID: conv.ID, Content: "test", ContentType: "text", MessageType: "incoming"}).Error) svc := &ConversationService{repo: repository.NewConversationRepo(db), msgRepo: repository.NewMessageRepo(db)} defer func() { _ = recover() }() _, _, _ = svc.ListMessages(context.Background(), conv.ID, 0, 20) } func TestConversationService_Mute_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, conv := seedCov62(t, db) svc := &ConversationService{repo: repository.NewConversationRepo(db), msgRepo: repository.NewMessageRepo(db)} defer func() { _ = recover() }() _, _ = svc.Mute(context.Background(), acc.ID, conv.ID) } func TestConversationService_Unmute_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, conv := seedCov62(t, db) conv.Muted = true require.NoError(t, db.Save(conv).Error) svc := &ConversationService{repo: repository.NewConversationRepo(db), msgRepo: repository.NewMessageRepo(db)} defer func() { _ = recover() }() _, _ = svc.Unmute(context.Background(), acc.ID, conv.ID) } func TestConversationService_ListReportingEvents_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, conv := seedCov62(t, db) svc := &ConversationService{repo: repository.NewConversationRepo(db), msgRepo: repository.NewMessageRepo(db)} defer func() { _ = recover() }() _, _ = svc.ListReportingEvents(context.Background(), acc.ID, conv.ID) } func TestConversationService_changedAttributes_Cov62(t *testing.T) { defer func() { _ = recover() }() _ = changedAttributes(map[string][2]interface{}{"status": {"open", "resolved"}}) } func TestConversationService_eventDataWithChanges_Cov62(t *testing.T) { defer func() { _ = recover() }() _ = eventDataWithChanges(map[string]interface{}{"key": "val"}) } // ==================================================================== // ContactService tests // ==================================================================== func TestContactService_Ready_Cov62(t *testing.T) { db := cov62DB(t) svc := &ContactService{repo: repository.NewContactRepo(db), noteRepo: repository.NewNoteRepo(db)} defer func() { _ = recover() }() _ = svc.Ready() } func TestContactService_DB_Cov62(t *testing.T) { db := cov62DB(t) svc := &ContactService{repo: repository.NewContactRepo(db), noteRepo: repository.NewNoteRepo(db)} defer func() { _ = recover() }() _ = svc.DB() } func TestContactService_GetByID_Cov62(t *testing.T) { db := cov62DB(t) _, _, _, contact, _ := seedCov62(t, db) svc := &ContactService{repo: repository.NewContactRepo(db), noteRepo: repository.NewNoteRepo(db)} defer func() { _ = recover() }() _, _ = svc.GetByID(context.Background(), contact.ID) } func TestContactService_GetByAccountAndID_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, contact, _ := seedCov62(t, db) svc := &ContactService{repo: repository.NewContactRepo(db), noteRepo: repository.NewNoteRepo(db)} defer func() { _ = recover() }() _, _ = svc.GetByAccountAndID(context.Background(), acc.ID, contact.ID) } func TestContactService_ListByAccount_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, _ := seedCov62(t, db) svc := &ContactService{repo: repository.NewContactRepo(db), noteRepo: repository.NewNoteRepo(db)} defer func() { _ = recover() }() _, _, _ = svc.ListByAccount(context.Background(), acc.ID, 0, 10, "") } func TestContactService_Search_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, _ := seedCov62(t, db) svc := &ContactService{repo: repository.NewContactRepo(db), noteRepo: repository.NewNoteRepo(db)} defer func() { _ = recover() }() _, _, _ = svc.Search(context.Background(), acc.ID, "test", 0, 10, "", search.SearchModeILike) } func TestContactService_Search_EmptyQuery_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, _ := seedCov62(t, db) svc := &ContactService{repo: repository.NewContactRepo(db), noteRepo: repository.NewNoteRepo(db)} defer func() { _ = recover() }() _, _, _ = svc.Search(context.Background(), acc.ID, "", 0, 10, "", search.SearchModeILike) } func TestContactService_Create_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, _ := seedCov62(t, db) svc := &ContactService{repo: repository.NewContactRepo(db), noteRepo: repository.NewNoteRepo(db)} defer func() { _ = recover() }() _, _ = svc.Create(context.Background(), acc.ID, CreateContactRequest{ Name: "NewContact", Email: "new@t.com", }) } func TestContactService_Create_WithInbox_Cov62(t *testing.T) { db := cov62DB(t) acc, _, inbox, _, _ := seedCov62(t, db) svc := &ContactService{repo: repository.NewContactRepo(db), noteRepo: repository.NewNoteRepo(db)} defer func() { _ = recover() }() inboxID := inbox.ID _, _ = svc.Create(context.Background(), acc.ID, CreateContactRequest{ Name: "NewContact2", Email: "new2@t.com", InboxID: &inboxID, }) } func TestContactService_Update_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, contact, _ := seedCov62(t, db) svc := &ContactService{repo: repository.NewContactRepo(db), noteRepo: repository.NewNoteRepo(db)} defer func() { _ = recover() }() _, _ = svc.Update(context.Background(), acc.ID, contact.ID, UpdateContactRequest{ Name: "UpdatedContact", }) } func TestContactService_Delete_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, contact, _ := seedCov62(t, db) svc := &ContactService{repo: repository.NewContactRepo(db), noteRepo: repository.NewNoteRepo(db)} defer func() { _ = recover() }() _ = svc.Delete(context.Background(), acc.ID, contact.ID) } func TestContactService_ListNotes_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, contact, _ := seedCov62(t, db) svc := &ContactService{repo: repository.NewContactRepo(db), noteRepo: repository.NewNoteRepo(db)} defer func() { _ = recover() }() _, _ = svc.ListNotes(context.Background(), acc.ID, contact.ID) } func TestContactService_CreateNote_Cov62(t *testing.T) { db := cov62DB(t) acc, user, _, contact, _ := seedCov62(t, db) svc := &ContactService{repo: repository.NewContactRepo(db), noteRepo: repository.NewNoteRepo(db)} defer func() { _ = recover() }() _, _ = svc.CreateNote(context.Background(), acc.ID, contact.ID, user.ID, CreateNoteRequest{Content: "test note"}) } func TestContactService_ListActive_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, _ := seedCov62(t, db) svc := &ContactService{repo: repository.NewContactRepo(db), noteRepo: repository.NewNoteRepo(db)} defer func() { _ = recover() }() _, _, _ = svc.ListActive(context.Background(), acc.ID, 0, 10, "") } func TestContactService_contactCallVoiceEnabled_Cov62(t *testing.T) { defer func() { _ = recover() }() _ = contactCallVoiceEnabled(`{"voice_enabled":true}`) } // ==================================================================== // ArticleService tests // ==================================================================== func TestArticleService_Create_Cov62(t *testing.T) { db := cov62DB(t, &model.Portal{}) acc, _, _, _, _ := seedCov62(t, db) portal := &model.Portal{AccountID: acc.ID, Name: "TestPortal"} require.NoError(t, db.Create(portal).Error) svc := &ArticleService{repo: repository.NewArticleRepo(db)} defer func() { _ = recover() }() _, _ = svc.Create(context.Background(), portal.ID, 1, &CreateArticleRequest{ Title: "Test Article", Content: "Content", }) } func TestArticleService_CreateWithAccount_Cov62(t *testing.T) { db := cov62DB(t, &model.Portal{}) acc, _, _, _, _ := seedCov62(t, db) portal := &model.Portal{AccountID: acc.ID, Name: "TestPortal2"} require.NoError(t, db.Create(portal).Error) svc := &ArticleService{repo: repository.NewArticleRepo(db)} defer func() { _ = recover() }() _, _ = svc.CreateWithAccount(context.Background(), acc.ID, portal.ID, 1, &CreateArticleRequest{ Title: "Test Article 2", Content: "Content 2", }) } func TestArticleService_GetByID_Cov62(t *testing.T) { db := cov62DB(t, &model.Portal{}) acc, _, _, _, _ := seedCov62(t, db) portal := &model.Portal{AccountID: acc.ID, Name: "TestPortal3"} require.NoError(t, db.Create(portal).Error) article := &model.Article{AccountID: acc.ID, PortalID: portal.ID, Title: "A", Slug: "a", Status: "draft"} require.NoError(t, db.Create(article).Error) svc := &ArticleService{repo: repository.NewArticleRepo(db)} defer func() { _ = recover() }() _, _ = svc.GetByID(context.Background(), article.ID) } func TestArticleService_GetByPortalAndID_Cov62(t *testing.T) { db := cov62DB(t, &model.Portal{}) acc, _, _, _, _ := seedCov62(t, db) portal := &model.Portal{AccountID: acc.ID, Name: "TestPortal4"} require.NoError(t, db.Create(portal).Error) article := &model.Article{AccountID: acc.ID, PortalID: portal.ID, Title: "B", Slug: "b", Status: "draft"} require.NoError(t, db.Create(article).Error) svc := &ArticleService{repo: repository.NewArticleRepo(db)} defer func() { _ = recover() }() _, _ = svc.GetByPortalAndID(context.Background(), portal.ID, article.ID) } func TestArticleService_Update_Cov62(t *testing.T) { db := cov62DB(t, &model.Portal{}) acc, _, _, _, _ := seedCov62(t, db) portal := &model.Portal{AccountID: acc.ID, Name: "TestPortal5"} require.NoError(t, db.Create(portal).Error) article := &model.Article{AccountID: acc.ID, PortalID: portal.ID, Title: "C", Slug: "c", Status: "draft"} require.NoError(t, db.Create(article).Error) svc := &ArticleService{repo: repository.NewArticleRepo(db)} defer func() { _ = recover() }() newTitle := "Updated Title" _, _ = svc.Update(context.Background(), article.ID, &UpdateArticleRequest{Title: &newTitle}) } func TestArticleService_UpdateScoped_Cov62(t *testing.T) { db := cov62DB(t, &model.Portal{}) acc, _, _, _, _ := seedCov62(t, db) portal := &model.Portal{AccountID: acc.ID, Name: "TestPortal6"} require.NoError(t, db.Create(portal).Error) article := &model.Article{AccountID: acc.ID, PortalID: portal.ID, Title: "D", Slug: "d", Status: "draft"} require.NoError(t, db.Create(article).Error) svc := &ArticleService{repo: repository.NewArticleRepo(db)} defer func() { _ = recover() }() newContent := "New content" _, _ = svc.UpdateScoped(context.Background(), portal.ID, article.ID, &UpdateArticleRequest{Content: &newContent}) } func TestArticleService_Delete_Cov62(t *testing.T) { db := cov62DB(t, &model.Portal{}) acc, _, _, _, _ := seedCov62(t, db) portal := &model.Portal{AccountID: acc.ID, Name: "TestPortal7"} require.NoError(t, db.Create(portal).Error) article := &model.Article{AccountID: acc.ID, PortalID: portal.ID, Title: "E", Slug: "e", Status: "draft"} require.NoError(t, db.Create(article).Error) svc := &ArticleService{repo: repository.NewArticleRepo(db)} defer func() { _ = recover() }() _ = svc.Delete(context.Background(), article.ID) } func TestArticleService_DeleteScoped_Cov62(t *testing.T) { db := cov62DB(t, &model.Portal{}) acc, _, _, _, _ := seedCov62(t, db) portal := &model.Portal{AccountID: acc.ID, Name: "TestPortal8"} require.NoError(t, db.Create(portal).Error) article := &model.Article{AccountID: acc.ID, PortalID: portal.ID, Title: "F", Slug: "f", Status: "draft"} require.NoError(t, db.Create(article).Error) svc := &ArticleService{repo: repository.NewArticleRepo(db)} defer func() { _ = recover() }() _ = svc.DeleteScoped(context.Background(), portal.ID, article.ID) } func TestArticleService_ListByPortalID_Cov62(t *testing.T) { db := cov62DB(t, &model.Portal{}) acc, _, _, _, _ := seedCov62(t, db) portal := &model.Portal{AccountID: acc.ID, Name: "TestPortal9"} require.NoError(t, db.Create(portal).Error) svc := &ArticleService{repo: repository.NewArticleRepo(db)} defer func() { _ = recover() }() _, _, _ = svc.ListByPortalID(context.Background(), portal.ID, 1, 25) } func TestArticleService_ListByCategoryID_Cov62(t *testing.T) { db := cov62DB(t, &model.Portal{}) acc, _, _, _, _ := seedCov62(t, db) portal := &model.Portal{AccountID: acc.ID, Name: "TestPortal10"} require.NoError(t, db.Create(portal).Error) svc := &ArticleService{repo: repository.NewArticleRepo(db)} defer func() { _ = recover() }() _, _, _ = svc.ListByCategoryID(context.Background(), 1, 1, 25) } func TestArticleService_ListByStatus_Cov62(t *testing.T) { db := cov62DB(t, &model.Portal{}) acc, _, _, _, _ := seedCov62(t, db) portal := &model.Portal{AccountID: acc.ID, Name: "TestPortal11"} require.NoError(t, db.Create(portal).Error) svc := &ArticleService{repo: repository.NewArticleRepo(db)} defer func() { _ = recover() }() _, _, _ = svc.ListByStatus(context.Background(), portal.ID, "draft", 1, 25) } func TestArticleService_Search_Cov62(t *testing.T) { db := cov62DB(t, &model.Portal{}) acc, _, _, _, _ := seedCov62(t, db) portal := &model.Portal{AccountID: acc.ID, Name: "TestPortal12"} require.NoError(t, db.Create(portal).Error) svc := &ArticleService{repo: repository.NewArticleRepo(db)} defer func() { _ = recover() }() _, _, _ = svc.Search(context.Background(), repository.ArticleSearchParams{PortalID: portal.ID}) } func TestArticleService_Count_Cov62(t *testing.T) { db := cov62DB(t, &model.Portal{}) acc, _, _, _, _ := seedCov62(t, db) portal := &model.Portal{AccountID: acc.ID, Name: "TestPortal13"} require.NoError(t, db.Create(portal).Error) svc := &ArticleService{repo: repository.NewArticleRepo(db)} defer func() { _ = recover() }() _, _ = svc.Count(context.Background(), repository.ArticleSearchParams{PortalID: portal.ID}) } func TestArticleService_StatusCounts_Cov62(t *testing.T) { db := cov62DB(t, &model.Portal{}) acc, _, _, _, _ := seedCov62(t, db) portal := &model.Portal{AccountID: acc.ID, Name: "TestPortal14"} require.NoError(t, db.Create(portal).Error) svc := &ArticleService{repo: repository.NewArticleRepo(db)} defer func() { _ = recover() }() _, _ = svc.StatusCounts(context.Background(), portal.ID) } func TestArticleService_ListMeta_Cov62(t *testing.T) { db := cov62DB(t, &model.Portal{}) acc, _, _, _, _ := seedCov62(t, db) portal := &model.Portal{AccountID: acc.ID, Name: "TestPortal15"} require.NoError(t, db.Create(portal).Error) svc := &ArticleService{repo: repository.NewArticleRepo(db)} defer func() { _ = recover() }() _, _ = svc.ListMeta(context.Background(), repository.ArticleSearchParams{PortalID: portal.ID}, 1) } func TestArticleService_IncrementViews_Cov62(t *testing.T) { db := cov62DB(t, &model.Portal{}) acc, _, _, _, _ := seedCov62(t, db) portal := &model.Portal{AccountID: acc.ID, Name: "TestPortal16"} require.NoError(t, db.Create(portal).Error) article := &model.Article{AccountID: acc.ID, PortalID: portal.ID, Title: "G", Slug: "g", Status: "draft"} require.NoError(t, db.Create(article).Error) svc := &ArticleService{repo: repository.NewArticleRepo(db)} defer func() { _ = recover() }() _ = svc.IncrementViews(context.Background(), article.ID) } func TestArticleService_BulkActions_Publish_Cov62(t *testing.T) { db := cov62DB(t, &model.Portal{}) acc, _, _, _, _ := seedCov62(t, db) portal := &model.Portal{AccountID: acc.ID, Name: "TestPortal17"} require.NoError(t, db.Create(portal).Error) article := &model.Article{AccountID: acc.ID, PortalID: portal.ID, Title: "H", Slug: "h", Status: "draft"} require.NoError(t, db.Create(article).Error) svc := &ArticleService{repo: repository.NewArticleRepo(db)} defer func() { _ = recover() }() _ = svc.BulkActions(context.Background(), &BulkActionsRequest{Action: "publish", IDs: []uint{article.ID}}) } func TestArticleService_BulkActions_Archive_Cov62(t *testing.T) { db := cov62DB(t, &model.Portal{}) acc, _, _, _, _ := seedCov62(t, db) portal := &model.Portal{AccountID: acc.ID, Name: "TestPortal18"} require.NoError(t, db.Create(portal).Error) article := &model.Article{AccountID: acc.ID, PortalID: portal.ID, Title: "I", Slug: "i", Status: "published"} require.NoError(t, db.Create(article).Error) svc := &ArticleService{repo: repository.NewArticleRepo(db)} defer func() { _ = recover() }() _ = svc.BulkActions(context.Background(), &BulkActionsRequest{Action: "archive", IDs: []uint{article.ID}}) } func TestArticleService_Reorder_Cov62(t *testing.T) { db := cov62DB(t, &model.Portal{}) acc, _, _, _, _ := seedCov62(t, db) portal := &model.Portal{AccountID: acc.ID, Name: "TestPortal19"} require.NoError(t, db.Create(portal).Error) article := &model.Article{AccountID: acc.ID, PortalID: portal.ID, Title: "J", Slug: "j", Status: "draft"} require.NoError(t, db.Create(article).Error) svc := &ArticleService{repo: repository.NewArticleRepo(db)} defer func() { _ = recover() }() _ = svc.Reorder(context.Background(), map[uint]int{article.ID: 1}) } // ==================================================================== // AnalyticsService tests // ==================================================================== func TestAnalyticsService_GetSummary_Cov62(t *testing.T) { db := cov62DB(t, &model.ReportingEventsRollup{}) acc, _, _, _, _ := seedCov62(t, db) svc := &AnalyticsService{ eventRepo: repository.NewReportingEventRepo(db), rollupRepo: repository.NewReportingEventsRollupRepo(db), db: db, rollups: NewReportingRollupService(repository.NewReportingEventRepo(db), repository.NewReportingEventsRollupRepo(db)), } defer func() { _ = recover() }() now := time.Now() _, _ = svc.GetSummary(context.Background(), acc.ID, now.AddDate(0, -1, 0), now) } func TestAnalyticsService_GetAgentMetrics_Cov62(t *testing.T) { db := cov62DB(t, &model.ReportingEventsRollup{}) acc, _, _, _, _ := seedCov62(t, db) svc := &AnalyticsService{ eventRepo: repository.NewReportingEventRepo(db), rollupRepo: repository.NewReportingEventsRollupRepo(db), db: db, } defer func() { _ = recover() }() now := time.Now() _, _ = svc.GetAgentMetrics(context.Background(), acc.ID, now.AddDate(0, -1, 0), now) } func TestAnalyticsService_GetInboxMetrics_Cov62(t *testing.T) { db := cov62DB(t, &model.ReportingEventsRollup{}) acc, _, _, _, _ := seedCov62(t, db) svc := &AnalyticsService{ eventRepo: repository.NewReportingEventRepo(db), rollupRepo: repository.NewReportingEventsRollupRepo(db), db: db, } defer func() { _ = recover() }() now := time.Now() _, _ = svc.GetInboxMetrics(context.Background(), acc.ID, now.AddDate(0, -1, 0), now) } func TestAnalyticsService_GetLabelMetrics_Cov62(t *testing.T) { db := cov62DB(t, &model.ReportingEventsRollup{}) acc, _, _, _, _ := seedCov62(t, db) svc := &AnalyticsService{ eventRepo: repository.NewReportingEventRepo(db), rollupRepo: repository.NewReportingEventsRollupRepo(db), db: db, } defer func() { _ = recover() }() now := time.Now() _, _ = svc.GetLabelMetrics(context.Background(), acc.ID, now.AddDate(0, -1, 0), now) } func TestAnalyticsService_GetTeamMetrics_Cov62(t *testing.T) { db := cov62DB(t, &model.ReportingEventsRollup{}) acc, _, _, _, _ := seedCov62(t, db) svc := &AnalyticsService{ eventRepo: repository.NewReportingEventRepo(db), rollupRepo: repository.NewReportingEventsRollupRepo(db), db: db, } defer func() { _ = recover() }() now := time.Now() _, _ = svc.GetTeamMetrics(context.Background(), acc.ID, now.AddDate(0, -1, 0), now) } func TestAnalyticsService_GetDrilldown_Cov62(t *testing.T) { db := cov62DB(t, &model.ReportingEventsRollup{}) acc, _, _, _, _ := seedCov62(t, db) svc := &AnalyticsService{ eventRepo: repository.NewReportingEventRepo(db), rollupRepo: repository.NewReportingEventsRollupRepo(db), db: db, } defer func() { _ = recover() }() now := time.Now() _, _ = svc.GetDrilldown(context.Background(), acc.ID, ReportDrilldownParams{ Metric: "conversations_count", DimensionType: "account", Since: now.AddDate(0, -1, 0), Until: now, BucketTimestamp: now.AddDate(0, 0, -1), Page: 1, PerPage: 25, }) } func TestAnalyticsService_reportBucketEnd_Cov62(t *testing.T) { defer func() { _ = recover() }() _ = reportBucketEnd(time.Now(), "day", 0) } func TestAnalyticsService_reportInt64Value_Cov62(t *testing.T) { defer func() { _ = recover() }() v := int64(42) _ = reportInt64Value(&v) } // ==================================================================== // ProfileService tests // ==================================================================== func TestProfileService_Get_Cov62(t *testing.T) { db := cov62DB(t, &model.AccessToken{}) acc, user, _, _, _ := seedCov62(t, db) svc := &ProfileService{ userRepo: repository.NewUserRepo(db), accountUserRepo: repository.NewAccountUserRepo(db), accessTokenRepo: repository.NewAccessTokenRepo(db), installationConfigRepo: repository.NewInstallationConfigRepo(db), } defer func() { _ = recover() }() _, _ = svc.Get(context.Background(), user.ID, acc.ID) } func TestProfileService_Update_Cov62(t *testing.T) { db := cov62DB(t, &model.AccessToken{}) acc, user, _, _, _ := seedCov62(t, db) svc := &ProfileService{ userRepo: repository.NewUserRepo(db), accountUserRepo: repository.NewAccountUserRepo(db), } defer func() { _ = recover() }() _, _ = svc.Update(context.Background(), user.ID, acc.ID, UpdateProfileRequest{Name: "UpdatedName"}) } func TestProfileService_UpdateAvatar_Cov62(t *testing.T) { db := cov62DB(t, &model.AccessToken{}) acc, user, _, _, _ := seedCov62(t, db) svc := &ProfileService{ userRepo: repository.NewUserRepo(db), accountUserRepo: repository.NewAccountUserRepo(db), } defer func() { _ = recover() }() _, _ = svc.UpdateAvatar(context.Background(), user.ID, acc.ID, UpdateAvatarRequest{AvatarURL: "https://example.com/avatar.png"}) } func TestProfileService_SetAvailability_Cov62(t *testing.T) { db := cov62DB(t, &model.AccessToken{}) acc, user, _, _, _ := seedCov62(t, db) svc := &ProfileService{ userRepo: repository.NewUserRepo(db), accountUserRepo: repository.NewAccountUserRepo(db), } defer func() { _ = recover() }() _, _ = svc.SetAvailability(context.Background(), user.ID, AvailabilityRequest{AccountID: acc.ID, Availability: "online"}) } func TestProfileService_SetAutoOffline_Cov62(t *testing.T) { db := cov62DB(t, &model.AccessToken{}) acc, user, _, _, _ := seedCov62(t, db) svc := &ProfileService{ userRepo: repository.NewUserRepo(db), accountUserRepo: repository.NewAccountUserRepo(db), } defer func() { _ = recover() }() _, _ = svc.SetAutoOffline(context.Background(), user.ID, AutoOfflineRequest{AccountID: acc.ID, AutoOffline: true}) } func TestProfileService_SetActiveAccount_Cov62(t *testing.T) { db := cov62DB(t, &model.AccessToken{}) acc, user, _, _, _ := seedCov62(t, db) svc := &ProfileService{ userRepo: repository.NewUserRepo(db), accountUserRepo: repository.NewAccountUserRepo(db), } defer func() { _ = recover() }() _ = svc.SetActiveAccount(context.Background(), user.ID, SetActiveAccountRequest{AccountID: acc.ID}) } func TestProfileService_DeleteAvatar_Cov62(t *testing.T) { db := cov62DB(t, &model.AccessToken{}) acc, user, _, _, _ := seedCov62(t, db) svc := &ProfileService{ userRepo: repository.NewUserRepo(db), accountUserRepo: repository.NewAccountUserRepo(db), } defer func() { _ = recover() }() _, _ = svc.DeleteAvatar(context.Background(), user.ID, acc.ID) } func TestProfileService_ResendConfirmation_Cov62(t *testing.T) { db := cov62DB(t, &model.AccessToken{}) _, user, _, _, _ := seedCov62(t, db) svc := &ProfileService{ userRepo: repository.NewUserRepo(db), accountUserRepo: repository.NewAccountUserRepo(db), } defer func() { _ = recover() }() _ = svc.ResendConfirmation(context.Background(), user.ID) } func TestProfileService_ListUserSessions_Cov62(t *testing.T) { db := cov62DB(t, &model.AccessToken{}, &model.UserSession{}) _, user, _, _, _ := seedCov62(t, db) svc := &ProfileService{ userRepo: repository.NewUserRepo(db), accountUserRepo: repository.NewAccountUserRepo(db), } defer func() { _ = recover() }() _, _ = svc.ListUserSessions(context.Background(), user.ID) } // ==================================================================== // CompanyService tests // ==================================================================== func TestCompanyService_DB_Cov62(t *testing.T) { db := cov62DB(t, &model.Company{}) svc := &CompanyService{companyRepo: repository.NewCompanyRepo(db), contactRepo: repository.NewContactRepo(db)} defer func() { _ = recover() }() _ = svc.DB() } func TestCompanyService_List_Cov62(t *testing.T) { db := cov62DB(t, &model.Company{}) acc, _, _, _, _ := seedCov62(t, db) svc := &CompanyService{companyRepo: repository.NewCompanyRepo(db), contactRepo: repository.NewContactRepo(db)} defer func() { _ = recover() }() _, _, _ = svc.List(context.Background(), acc.ID, 0, 10, "") } func TestCompanyService_Search_Cov62(t *testing.T) { db := cov62DB(t, &model.Company{}) acc, _, _, _, _ := seedCov62(t, db) svc := &CompanyService{companyRepo: repository.NewCompanyRepo(db), contactRepo: repository.NewContactRepo(db)} defer func() { _ = recover() }() _, _, _ = svc.Search(context.Background(), acc.ID, "test", 0, 10, "", search.SearchModeILike) } func TestCompanyService_Search_EmptyQuery_Cov62(t *testing.T) { db := cov62DB(t, &model.Company{}) acc, _, _, _, _ := seedCov62(t, db) svc := &CompanyService{companyRepo: repository.NewCompanyRepo(db), contactRepo: repository.NewContactRepo(db)} defer func() { _ = recover() }() _, _, _ = svc.Search(context.Background(), acc.ID, "", 0, 10, "", search.SearchModeILike) } func TestCompanyService_Get_Cov62(t *testing.T) { db := cov62DB(t, &model.Company{}) acc, _, _, _, _ := seedCov62(t, db) comp := &model.Company{AccountID: acc.ID, Name: "TestCo"} require.NoError(t, db.Create(comp).Error) svc := &CompanyService{companyRepo: repository.NewCompanyRepo(db), contactRepo: repository.NewContactRepo(db)} defer func() { _ = recover() }() _, _ = svc.Get(context.Background(), comp.ID, acc.ID) } func TestCompanyService_Create_Cov62(t *testing.T) { db := cov62DB(t, &model.Company{}) acc, _, _, _, _ := seedCov62(t, db) svc := &CompanyService{companyRepo: repository.NewCompanyRepo(db), contactRepo: repository.NewContactRepo(db)} defer func() { _ = recover() }() _, _ = svc.Create(context.Background(), acc.ID, &CreateCompanyRequest{Name: "NewCo"}) } func TestCompanyService_Update_Cov62(t *testing.T) { db := cov62DB(t, &model.Company{}) acc, _, _, _, _ := seedCov62(t, db) comp := &model.Company{AccountID: acc.ID, Name: "OldCo"} require.NoError(t, db.Create(comp).Error) svc := &CompanyService{companyRepo: repository.NewCompanyRepo(db), contactRepo: repository.NewContactRepo(db)} defer func() { _ = recover() }() _, _ = svc.Update(context.Background(), comp.ID, acc.ID, &UpdateCompanyRequest{Name: "UpdatedCo"}) } // ==================================================================== // CampaignService tests // ==================================================================== func TestCampaignService_List_Cov62(t *testing.T) { db := cov62DB(t, &campaign.Campaign{}) acc, _, _, _, _ := seedCov62(t, db) svc := &CampaignService{campaignRepo: repository.NewCampaignRepo(db)} defer func() { _ = recover() }() _, _, _ = svc.List(context.Background(), acc.ID, 0, 10) } func TestCampaignService_Get_Cov62(t *testing.T) { db := cov62DB(t, &campaign.Campaign{}) acc, _, _, _, _ := seedCov62(t, db) camp := &campaign.Campaign{AccountID: acc.ID, Title: "TestCamp", Message: "msg", CampaignStatus: campaign.CampaignStatusActive} require.NoError(t, db.Create(camp).Error) svc := &CampaignService{campaignRepo: repository.NewCampaignRepo(db)} defer func() { _ = recover() }() _, _ = svc.Get(context.Background(), camp.ID, acc.ID) } func TestCampaignService_Create_Cov62(t *testing.T) { db := cov62DB(t, &campaign.Campaign{}) acc, _, inbox, _, _ := seedCov62(t, db) svc := &CampaignService{campaignRepo: repository.NewCampaignRepo(db)} defer func() { _ = recover() }() _, _ = svc.Create(context.Background(), acc.ID, CreateCampaignRequest{ InboxID: inbox.ID, Title: "Camp", Message: "msg", }) } // ==================================================================== // CustomFilterService tests // ==================================================================== func TestCustomFilterService_Create_Cov62(t *testing.T) { db := cov62DB(t, &model.CustomFilter{}) acc, user, _, _, _ := seedCov62(t, db) svc := &CustomFilterService{repo: repository.NewCustomFilterRepo(db)} defer func() { _ = recover() }() _, _ = svc.Create(context.Background(), acc.ID, user.ID, &CreateCustomFilterRequest{ Name: "test-filter", FilterType: "conversation", Query: datatypes.JSON([]byte(`{}`)), }) } func TestCustomFilterService_Get_Cov62(t *testing.T) { db := cov62DB(t, &model.CustomFilter{}) acc, _, _, _, _ := seedCov62(t, db) cf := &model.CustomFilter{AccountID: acc.ID, Name: "f", FilterType: "conversation", Query: datatypes.JSON([]byte(`{}`))} require.NoError(t, db.Create(cf).Error) svc := &CustomFilterService{repo: repository.NewCustomFilterRepo(db)} defer func() { _ = recover() }() _, _ = svc.Get(context.Background(), acc.ID, cf.ID) } func TestCustomFilterService_List_Cov62(t *testing.T) { db := cov62DB(t, &model.CustomFilter{}) acc, _, _, _, _ := seedCov62(t, db) svc := &CustomFilterService{repo: repository.NewCustomFilterRepo(db)} defer func() { _ = recover() }() _, _, _ = svc.List(context.Background(), acc.ID, "conversation", 0, 10) } func TestCustomFilterService_List_NoType_Cov62(t *testing.T) { db := cov62DB(t, &model.CustomFilter{}) acc, _, _, _, _ := seedCov62(t, db) svc := &CustomFilterService{repo: repository.NewCustomFilterRepo(db)} defer func() { _ = recover() }() _, _, _ = svc.List(context.Background(), acc.ID, "", 0, 10) } func TestCustomFilterService_Update_Cov62(t *testing.T) { db := cov62DB(t, &model.CustomFilter{}) acc, _, _, _, _ := seedCov62(t, db) cf := &model.CustomFilter{AccountID: acc.ID, Name: "f", FilterType: "conversation", Query: datatypes.JSON([]byte(`{}`))} require.NoError(t, db.Create(cf).Error) svc := &CustomFilterService{repo: repository.NewCustomFilterRepo(db)} defer func() { _ = recover() }() _, _ = svc.Update(context.Background(), acc.ID, cf.ID, &UpdateCustomFilterRequest{Name: "updated"}) } func TestCustomFilterService_ListForUser_Cov62(t *testing.T) { db := cov62DB(t, &model.CustomFilter{}) acc, user, _, _, _ := seedCov62(t, db) svc := &CustomFilterService{repo: repository.NewCustomFilterRepo(db)} defer func() { _ = recover() }() _, _, _ = svc.ListForUser(context.Background(), acc.ID, user.ID, "conversation", 0, 10) } // ==================================================================== // CustomRoleService tests // ==================================================================== func TestCustomRoleService_List_Cov62(t *testing.T) { db := cov62DB(t, &model.CustomRole{}) acc, _, _, _, _ := seedCov62(t, db) svc := &CustomRoleService{repo: repository.NewCustomRoleRepo(db)} defer func() { _ = recover() }() _, _, _ = svc.List(context.Background(), acc.ID, 1, 25) } func TestCustomRoleService_Create_Cov62(t *testing.T) { db := cov62DB(t, &model.CustomRole{}) acc, _, _, _, _ := seedCov62(t, db) svc := &CustomRoleService{repo: repository.NewCustomRoleRepo(db)} defer func() { _ = recover() }() _, _ = svc.Create(context.Background(), acc.ID, CreateCustomRoleRequest{Name: "test-role"}) } func TestCustomRoleService_GetByID_Cov62(t *testing.T) { db := cov62DB(t, &model.CustomRole{}) acc, _, _, _, _ := seedCov62(t, db) role := &model.CustomRole{AccountID: acc.ID, Name: "r"} require.NoError(t, db.Create(role).Error) svc := &CustomRoleService{repo: repository.NewCustomRoleRepo(db)} defer func() { _ = recover() }() _, _ = svc.GetByID(context.Background(), role.ID, acc.ID) } func TestCustomRoleService_Update_Cov62(t *testing.T) { db := cov62DB(t, &model.CustomRole{}) acc, _, _, _, _ := seedCov62(t, db) role := &model.CustomRole{AccountID: acc.ID, Name: "r"} require.NoError(t, db.Create(role).Error) svc := &CustomRoleService{repo: repository.NewCustomRoleRepo(db)} defer func() { _ = recover() }() _, _ = svc.Update(context.Background(), role.ID, acc.ID, UpdateCustomRoleRequest{Name: "updated-role"}) } func TestCustomRoleService_Delete_Cov62(t *testing.T) { db := cov62DB(t, &model.CustomRole{}) acc, _, _, _, _ := seedCov62(t, db) role := &model.CustomRole{AccountID: acc.ID, Name: "r2"} require.NoError(t, db.Create(role).Error) svc := &CustomRoleService{repo: repository.NewCustomRoleRepo(db)} defer func() { _ = recover() }() _ = svc.Delete(context.Background(), role.ID, acc.ID) } // ==================================================================== // InstallationConfigService tests // ==================================================================== func TestInstallationConfigService_Get_Cov62(t *testing.T) { db := cov62DB(t, &model.InstallationConfig{}) cfg := &model.InstallationConfig{Name: "test", Value: "val"} require.NoError(t, db.Create(cfg).Error) svc := &InstallationConfigService{repo: repository.NewInstallationConfigRepo(db)} defer func() { _ = recover() }() _, _ = svc.Get(context.Background(), cfg.ID) } func TestInstallationConfigService_GetByName_Cov62(t *testing.T) { db := cov62DB(t, &model.InstallationConfig{}) cfg := &model.InstallationConfig{Name: "test621", Value: "val"} require.NoError(t, db.Create(cfg).Error) svc := &InstallationConfigService{repo: repository.NewInstallationConfigRepo(db)} defer func() { _ = recover() }() _, _ = svc.GetByName(context.Background(), "test621") } func TestInstallationConfigService_List_Cov62(t *testing.T) { db := cov62DB(t, &model.InstallationConfig{}) svc := &InstallationConfigService{repo: repository.NewInstallationConfigRepo(db)} defer func() { _ = recover() }() _, _, _ = svc.List(context.Background(), 0, 10) } func TestInstallationConfigService_Create_Cov62(t *testing.T) { db := cov62DB(t, &model.InstallationConfig{}) svc := &InstallationConfigService{repo: repository.NewInstallationConfigRepo(db)} defer func() { _ = recover() }() _, _ = svc.Create(context.Background(), &CreateInstallationConfigRequest{Name: "new622", Value: "val"}) } func TestInstallationConfigService_Update_Cov62(t *testing.T) { db := cov62DB(t, &model.InstallationConfig{}) cfg := &model.InstallationConfig{Name: "up623", Value: "val"} require.NoError(t, db.Create(cfg).Error) svc := &InstallationConfigService{repo: repository.NewInstallationConfigRepo(db)} defer func() { _ = recover() }() _, _ = svc.Update(context.Background(), cfg.ID, &UpdateInstallationConfigRequest{Value: "newval"}) } func TestInstallationConfigService_Delete_Cov62(t *testing.T) { db := cov62DB(t, &model.InstallationConfig{}) cfg := &model.InstallationConfig{Name: "del624", Value: "val"} require.NoError(t, db.Create(cfg).Error) svc := &InstallationConfigService{repo: repository.NewInstallationConfigRepo(db)} defer func() { _ = recover() }() _ = svc.Delete(context.Background(), cfg.ID) } // ==================================================================== // LabelService tests // ==================================================================== func TestLabelService_GetConversationLabels_Cov62(t *testing.T) { db := cov62DB(t) _, _, _, _, conv := seedCov62(t, db) svc := &LabelService{convLabelRepo: repository.NewConversationLabelRepo(db), tagRepo: repository.NewTagRepo(db)} defer func() { _ = recover() }() _, _ = svc.GetConversationLabels(context.Background(), conv.ID) } func TestLabelService_AddLabelToConversation_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, conv := seedCov62(t, db) tag := &model.Tag{AccountID: acc.ID, Name: "testtag"} require.NoError(t, db.Create(tag).Error) svc := &LabelService{convLabelRepo: repository.NewConversationLabelRepo(db), tagRepo: repository.NewTagRepo(db)} defer func() { _ = recover() }() _, _ = svc.AddLabelToConversation(context.Background(), acc.ID, conv.ID, tag.ID) } func TestLabelService_RemoveLabelFromConversation_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, conv := seedCov62(t, db) tag := &model.Tag{AccountID: acc.ID, Name: "testtag2"} require.NoError(t, db.Create(tag).Error) cl := &model.ConversationLabel{ConversationID: conv.ID, TagID: tag.ID, AccountID: acc.ID} require.NoError(t, db.Create(cl).Error) svc := &LabelService{convLabelRepo: repository.NewConversationLabelRepo(db), tagRepo: repository.NewTagRepo(db)} defer func() { _ = recover() }() _ = svc.RemoveLabelFromConversation(context.Background(), conv.ID, tag.ID) } func TestLabelService_ReplaceConversationLabels_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, conv := seedCov62(t, db) tag := &model.Tag{AccountID: acc.ID, Name: "testtag3"} require.NoError(t, db.Create(tag).Error) svc := &LabelService{convLabelRepo: repository.NewConversationLabelRepo(db), tagRepo: repository.NewTagRepo(db)} defer func() { _ = recover() }() _, _ = svc.ReplaceConversationLabels(context.Background(), acc.ID, conv.ID, []uint{tag.ID}) } func TestLabelService_BatchAddLabel_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, conv := seedCov62(t, db) tag := &model.Tag{AccountID: acc.ID, Name: "batchtag"} require.NoError(t, db.Create(tag).Error) svc := &LabelService{convLabelRepo: repository.NewConversationLabelRepo(db), tagRepo: repository.NewTagRepo(db)} defer func() { _ = recover() }() _ = svc.BatchAddLabel(context.Background(), acc.ID, &BatchAddLabelRequest{TagID: tag.ID, ConversationIDs: []uint{conv.ID}}) } func TestLabelService_BatchRemoveLabel_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, conv := seedCov62(t, db) tag := &model.Tag{AccountID: acc.ID, Name: "batchtag2"} require.NoError(t, db.Create(tag).Error) cl := &model.ConversationLabel{ConversationID: conv.ID, TagID: tag.ID, AccountID: acc.ID} require.NoError(t, db.Create(cl).Error) svc := &LabelService{convLabelRepo: repository.NewConversationLabelRepo(db), tagRepo: repository.NewTagRepo(db)} defer func() { _ = recover() }() _ = svc.BatchRemoveLabel(context.Background(), acc.ID, &BatchRemoveLabelRequest{TagID: tag.ID, ConversationIDs: []uint{conv.ID}}) } func TestLabelService_GetConversationsByTag_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, conv := seedCov62(t, db) tag := &model.Tag{AccountID: acc.ID, Name: "gettag"} require.NoError(t, db.Create(tag).Error) cl := &model.ConversationLabel{ConversationID: conv.ID, TagID: tag.ID, AccountID: acc.ID} require.NoError(t, db.Create(cl).Error) svc := &LabelService{convLabelRepo: repository.NewConversationLabelRepo(db), tagRepo: repository.NewTagRepo(db)} defer func() { _ = recover() }() _, _, _ = svc.GetConversationsByTag(context.Background(), acc.ID, tag.ID, 1, 25) } // ==================================================================== // ReportingEventService tests // ==================================================================== func TestReportingEventService_ListByAccount_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, _ := seedCov62(t, db) svc := &ReportingEventService{repo: repository.NewReportingEventRepo(db)} defer func() { _ = recover() }() now := time.Now() _, _ = svc.ListByAccount(context.Background(), acc.ID, now.AddDate(0, -1, 0), now) } func TestReportingEventService_GetByMetric_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, _ := seedCov62(t, db) svc := &ReportingEventService{repo: repository.NewReportingEventRepo(db)} defer func() { _ = recover() }() now := time.Now() _, _ = svc.GetByMetric(context.Background(), acc.ID, "conversation_created", now.AddDate(0, -1, 0), now) } func TestReportingEventService_ListAccountEvents_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, _ := seedCov62(t, db) svc := &ReportingEventService{repo: repository.NewReportingEventRepo(db)} defer func() { _ = recover() }() _, _ = svc.ListAccountEvents(context.Background(), acc.ID, ReportingEventListFilter{Page: 1, PerPage: 25}) } func TestReportingEventService_Create_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, _ := seedCov62(t, db) svc := &ReportingEventService{repo: repository.NewReportingEventRepo(db)} defer func() { _ = recover() }() _ = svc.Create(context.Background(), &model.ReportingEvent{AccountID: acc.ID, Name: "test_event"}) } // ==================================================================== // RBACService tests // ==================================================================== func TestRBACService_GetAccountUser_Cov62(t *testing.T) { db := cov62DB(t, &model.CustomRole{}) acc, user, _, _, _ := seedCov62(t, db) svc := &RBACService{db: db} defer func() { _ = recover() }() _, _ = svc.GetAccountUser(user.ID, acc.ID) } func TestRBACService_ListAccountUsers_Cov62(t *testing.T) { db := cov62DB(t, &model.CustomRole{}) acc, _, _, _, _ := seedCov62(t, db) svc := &RBACService{db: db} defer func() { _ = recover() }() _, _ = svc.ListAccountUsers(acc.ID) } func TestRBACService_ListUserAccounts_Cov62(t *testing.T) { db := cov62DB(t, &model.CustomRole{}) _, user, _, _, _ := seedCov62(t, db) svc := &RBACService{db: db} defer func() { _ = recover() }() _, _ = svc.ListUserAccounts(user.ID) } func TestRBACService_UpdateAvailability_Cov62(t *testing.T) { db := cov62DB(t, &model.CustomRole{}) acc, user, _, _, _ := seedCov62(t, db) svc := &RBACService{db: db} defer func() { _ = recover() }() _ = svc.UpdateAvailability(user.ID, acc.ID, "online") } func TestRBACService_AddAccountUser_Cov62(t *testing.T) { db := cov62DB(t, &model.CustomRole{}) acc, _, _, _, _ := seedCov62(t, db) newUser := &model.User{AccountID: acc.ID, Name: "u2", Email: "u2@t.com", Password: "p"} require.NoError(t, db.Create(newUser).Error) svc := &RBACService{db: db} defer func() { _ = recover() }() _, _ = svc.AddAccountUser(newUser.ID, acc.ID, "agent", 0, 0) } func TestRBACService_CreateCustomRole_Cov62(t *testing.T) { db := cov62DB(t, &model.CustomRole{}) acc, _, _, _, _ := seedCov62(t, db) svc := &RBACService{db: db} defer func() { _ = recover() }() _, _ = svc.CreateCustomRole(acc.ID, "testrole62", nil, "desc") } func TestRBACService_ListCustomRoles_Cov62(t *testing.T) { db := cov62DB(t, &model.CustomRole{}) acc, _, _, _, _ := seedCov62(t, db) svc := &RBACService{db: db} defer func() { _ = recover() }() _, _ = svc.ListCustomRoles(acc.ID) } func TestRBACService_BuildPolicyContext_Cov62(t *testing.T) { db := cov62DB(t, &model.CustomRole{}) acc, user, _, _, _ := seedCov62(t, db) svc := &RBACService{db: db} defer func() { _ = recover() }() _, _ = svc.BuildPolicyContext(user.ID, acc.ID) } func TestRBACService_CanPerform_Cov62(t *testing.T) { db := cov62DB(t, &model.CustomRole{}) acc, user, _, _, _ := seedCov62(t, db) svc := &RBACService{db: db} defer func() { _ = recover() }() _, _ = svc.CanPerform(user.ID, acc.ID, "read", "conversation") } // ==================================================================== // DurableSearchIndexer tests // ==================================================================== func TestDurableSearchIndexer_IndexConversation_Cov62(t *testing.T) { db := cov62DB(t) _, _, _, _, conv := seedCov62(t, db) indexer := &DurableSearchIndexer{db: db} defer func() { _ = recover() }() _ = indexer.IndexConversation(context.Background(), conv) } func TestDurableSearchIndexer_DeleteConversation_Cov62(t *testing.T) { db := cov62DB(t) indexer := &DurableSearchIndexer{db: db} defer func() { _ = recover() }() _ = indexer.DeleteConversation(context.Background(), 1, 1) } func TestDurableSearchIndexer_IndexMessage_Cov62(t *testing.T) { db := cov62DB(t) _, _, _, _, conv := seedCov62(t, db) msg := &model.Message{AccountID: conv.AccountID, ConversationID: conv.ID, Content: "test", ContentType: "text", MessageType: "incoming"} require.NoError(t, db.Create(msg).Error) indexer := &DurableSearchIndexer{db: db} defer func() { _ = recover() }() _ = indexer.IndexMessage(context.Background(), msg) } func TestDurableSearchIndexer_DeleteMessage_Cov62(t *testing.T) { db := cov62DB(t) indexer := &DurableSearchIndexer{db: db} defer func() { _ = recover() }() _ = indexer.DeleteMessage(context.Background(), 1, 1) } func TestDurableSearchIndexer_IndexContact_Cov62(t *testing.T) { db := cov62DB(t) _, _, _, contact, _ := seedCov62(t, db) indexer := &DurableSearchIndexer{db: db} defer func() { _ = recover() }() _ = indexer.IndexContact(context.Background(), contact) } func TestDurableSearchIndexer_DeleteContact_Cov62(t *testing.T) { db := cov62DB(t) indexer := &DurableSearchIndexer{db: db} defer func() { _ = recover() }() _ = indexer.DeleteContact(context.Background(), 1, 1) } func TestDurableSearchIndexer_IndexCompany_Cov62(t *testing.T) { db := cov62DB(t, &model.Company{}) acc, _, _, _, _ := seedCov62(t, db) comp := &model.Company{AccountID: acc.ID, Name: "IdxCo"} require.NoError(t, db.Create(comp).Error) indexer := &DurableSearchIndexer{db: db} defer func() { _ = recover() }() _ = indexer.IndexCompany(context.Background(), comp) } func TestDurableSearchIndexer_DeleteCompany_Cov62(t *testing.T) { db := cov62DB(t, &model.Company{}) indexer := &DurableSearchIndexer{db: db} defer func() { _ = recover() }() _ = indexer.DeleteCompany(context.Background(), 1, 1) } func TestDurableSearchIndexer_IndexArticle_Cov62(t *testing.T) { db := cov62DB(t, &model.Article{}) acc, _, _, _, _ := seedCov62(t, db) article := &model.Article{AccountID: acc.ID, Title: "IdxArt", Slug: "idxart", Status: "draft"} require.NoError(t, db.Create(article).Error) indexer := &DurableSearchIndexer{db: db} defer func() { _ = recover() }() _ = indexer.IndexArticle(context.Background(), article) } func TestDurableSearchIndexer_DeleteArticle_Cov62(t *testing.T) { db := cov62DB(t, &model.Article{}) indexer := &DurableSearchIndexer{db: db} defer func() { _ = recover() }() _ = indexer.DeleteArticle(context.Background(), 1, 1) } // ==================================================================== // MessageService tests // ==================================================================== func TestMessageService_ListByConversation_Cov62(t *testing.T) { db := cov62DB(t) _, _, _, _, conv := seedCov62(t, db) require.NoError(t, db.Create(&model.Message{AccountID: conv.AccountID, ConversationID: conv.ID, Content: "msg", ContentType: "text", MessageType: "incoming"}).Error) svc := &MessageService{repo: repository.NewMessageRepo(db)} defer func() { _ = recover() }() _, _, _ = svc.ListByConversation(context.Background(), conv.ID, 0, 20) } func TestMessageService_GetByID_Cov62(t *testing.T) { db := cov62DB(t) _, _, _, _, conv := seedCov62(t, db) msg := &model.Message{AccountID: conv.AccountID, ConversationID: conv.ID, Content: "msg", ContentType: "text", MessageType: "incoming"} require.NoError(t, db.Create(msg).Error) svc := &MessageService{repo: repository.NewMessageRepo(db)} defer func() { _ = recover() }() _, _ = svc.GetByID(context.Background(), msg.ID) } func TestMessageService_GetByAccountAndID_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, conv := seedCov62(t, db) msg := &model.Message{AccountID: acc.ID, ConversationID: conv.ID, Content: "msg", ContentType: "text", MessageType: "incoming"} require.NoError(t, db.Create(msg).Error) svc := &MessageService{repo: repository.NewMessageRepo(db)} defer func() { _ = recover() }() _, _ = svc.GetByAccountAndID(context.Background(), acc.ID, msg.ID) } func TestMessageService_GetByConversationAndID_Cov62(t *testing.T) { db := cov62DB(t) _, _, _, _, conv := seedCov62(t, db) msg := &model.Message{AccountID: conv.AccountID, ConversationID: conv.ID, Content: "msg", ContentType: "text", MessageType: "incoming"} require.NoError(t, db.Create(msg).Error) svc := &MessageService{repo: repository.NewMessageRepo(db)} defer func() { _ = recover() }() _, _ = svc.GetByConversationAndID(context.Background(), conv.ID, msg.ID) } func TestMessageService_Search_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, _ := seedCov62(t, db) svc := &MessageService{repo: repository.NewMessageRepo(db)} defer func() { _ = recover() }() _, _, _ = svc.Search(context.Background(), acc.ID, "test", 0, 10, search.SearchModeILike) } func TestMessageService_ResolveConversationForRoute_Cov62(t *testing.T) { db := cov62DB(t) acc, _, _, _, conv := seedCov62(t, db) svc := &MessageService{repo: repository.NewMessageRepo(db)} defer func() { _ = recover() }() _, _ = svc.ResolveConversationForRoute(context.Background(), acc.ID, conv.ID) } func TestMessageService_DB_Cov62(t *testing.T) { db := cov62DB(t) svc := &MessageService{repo: repository.NewMessageRepo(db)} defer func() { _ = recover() }() _ = svc.DB() } // ==================================================================== // AssignmentPolicyService tests // ==================================================================== func TestAssignmentPolicyService_ListAccountPolicies_Cov62(t *testing.T) { db := cov62DB(t, &model.AssignmentPolicy{}, &model.InboxAssignmentPolicy{}) acc, _, _, _, _ := seedCov62(t, db) svc := &AssignmentPolicyService{policyRepo: repository.NewAssignmentPolicyRepo(db)} defer func() { _ = recover() }() _, _ = svc.ListAccountPolicies(context.Background(), acc.ID) } func TestAssignmentPolicyService_GetAccountPolicy_Cov62(t *testing.T) { db := cov62DB(t, &model.AssignmentPolicy{}, &model.InboxAssignmentPolicy{}) acc, _, _, _, _ := seedCov62(t, db) policy := &model.AssignmentPolicy{AccountID: acc.ID, Name: "p"} require.NoError(t, db.Create(policy).Error) svc := &AssignmentPolicyService{policyRepo: repository.NewAssignmentPolicyRepo(db)} defer func() { _ = recover() }() _, _ = svc.GetAccountPolicy(context.Background(), acc.ID, policy.ID) } func TestAssignmentPolicyService_GetAccountPolicy_Default_Cov62(t *testing.T) { db := cov62DB(t, &model.AssignmentPolicy{}, &model.InboxAssignmentPolicy{}) acc, _, _, _, _ := seedCov62(t, db) svc := &AssignmentPolicyService{policyRepo: repository.NewAssignmentPolicyRepo(db)} defer func() { _ = recover() }() _, _ = svc.GetAccountPolicy(context.Background(), acc.ID) } func TestAssignmentPolicyService_CreateAccountPolicy_Cov62(t *testing.T) { db := cov62DB(t, &model.AssignmentPolicy{}, &model.InboxAssignmentPolicy{}) acc, _, _, _, _ := seedCov62(t, db) svc := &AssignmentPolicyService{policyRepo: repository.NewAssignmentPolicyRepo(db)} defer func() { _ = recover() }() _, _ = svc.CreateAccountPolicy(context.Background(), acc.ID, CreatePolicyRequest{ Name: "policy62", AssignmentOrder: "round_robin", }) } func TestAssignmentPolicyService_UpdateAccountPolicy_Cov62(t *testing.T) { db := cov62DB(t, &model.AssignmentPolicy{}, &model.InboxAssignmentPolicy{}) acc, _, _, _, _ := seedCov62(t, db) policy := &model.AssignmentPolicy{AccountID: acc.ID, Name: "p2"} require.NoError(t, db.Create(policy).Error) svc := &AssignmentPolicyService{policyRepo: repository.NewAssignmentPolicyRepo(db)} defer func() { _ = recover() }() newName := "updated-policy" _, _ = svc.UpdateAccountPolicy(context.Background(), policy.ID, acc.ID, UpdatePolicyRequest{Name: newName}) }