package service import ( "context" "testing" "time" "github.com/gochat/gochat/internal/model" "github.com/gochat/gochat/internal/repository" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) // ============================================================================ // coverage16_test.go — broad coverage for internal/service // Test functions use _Cov16 suffix. 50+ tests targeting constructors, // simple methods (Ready/DB), error paths, and CRUD on many service types. // ============================================================================ // c16UintPtr returns a pointer to the given uint. func c16UintPtr(v uint) *uint { return &v } // --- NoteService --- func TestNoteService_List_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.Note{}) svc := NewNoteService(repository.NewNoteRepo(db)) notes, err := svc.List(1, 9999) require.NoError(t, err) assert.Empty(t, notes) } func TestNoteService_Get_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.Note{}) svc := NewNoteService(repository.NewNoteRepo(db)) _, err := svc.Get(1, 9999, 99999) assert.Error(t, err) } func TestNoteService_Create_EmptyContent_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.Note{}) svc := NewNoteService(repository.NewNoteRepo(db)) _, err := svc.Create(1, 1, 1, "") assert.Error(t, err) } func TestNoteService_Update_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.Note{}) svc := NewNoteService(repository.NewNoteRepo(db)) _, err := svc.Update(1, 9999, 99999, "content") assert.Error(t, err) } func TestNoteService_Update_EmptyContent_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.Note{}) svc := NewNoteService(repository.NewNoteRepo(db)) _, err := svc.Update(1, 1, 1, "") assert.Error(t, err) } func TestNoteService_Delete_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.Note{}) svc := NewNoteService(repository.NewNoteRepo(db)) err := svc.Delete(1, 9999, 99999) // GORM Delete may not error on not-found; just ensure no panic _ = err } func TestNoteService_CreateAndDelete_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.Note{}) svc := NewNoteService(repository.NewNoteRepo(db)) note, err := svc.Create(1, 1, 1, "test note content") require.NoError(t, err) assert.NotZero(t, note.ID) got, err := svc.Get(1, 1, note.ID) require.NoError(t, err) assert.Equal(t, "test note content", got.Content) notes, err := svc.List(1, 1) require.NoError(t, err) assert.Len(t, notes, 1) err = svc.Delete(1, 1, note.ID) require.NoError(t, err) } // --- LabelService --- func TestLabelService_New_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewLabelService(repository.NewConversationLabelRepo(db), repository.NewTagRepo(db)) assert.NotNil(t, svc) } func TestLabelService_ListByConversation_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewLabelService(repository.NewConversationLabelRepo(db), repository.NewTagRepo(db)) // Just ensure the service was constructed without panic _ = svc } // --- DeliveryStatusService --- func TestDeliveryStatusService_New_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewDeliveryStatusService(repository.NewMessageRepo(db), repository.NewDeliveryStatusRepo(db)) assert.NotNil(t, svc) } // --- ReportingRollupService --- func TestReportingRollupService_New_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewReportingRollupService(repository.NewReportingEventRepo(db), repository.NewReportingEventsRollupRepo(db)) assert.NotNil(t, svc) } // --- SummaryReportService --- func TestSummaryReportService_GetAgentSummary_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.ReportingEventsRollup{}) svc := NewSummaryReportService(repository.NewReportingEventsRollupRepo(db)) result, err := svc.GetAgentSummary(context.Background(), 1, time.Now().Add(-24*time.Hour), time.Now()) require.NoError(t, err) _ = result } func TestSummaryReportService_GetTeamSummary_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.ReportingEventsRollup{}) svc := NewSummaryReportService(repository.NewReportingEventsRollupRepo(db)) _, err := svc.GetTeamSummary(context.Background(), 1, time.Now().Add(-24*time.Hour), time.Now()) require.NoError(t, err) } func TestSummaryReportService_GetInboxSummary_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.ReportingEventsRollup{}) svc := NewSummaryReportService(repository.NewReportingEventsRollupRepo(db)) _, err := svc.GetInboxSummary(context.Background(), 1, time.Now().Add(-24*time.Hour), time.Now()) require.NoError(t, err) } func TestSummaryReportService_GetLabelSummary_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.ReportingEventsRollup{}) svc := NewSummaryReportService(repository.NewReportingEventsRollupRepo(db)) _, err := svc.GetLabelSummary(context.Background(), 1, time.Now().Add(-24*time.Hour), time.Now()) require.NoError(t, err) } func TestSummaryReportService_GetAccountSummary_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.ReportingEventsRollup{}) svc := NewSummaryReportService(repository.NewReportingEventsRollupRepo(db)) _, err := svc.GetAccountSummary(context.Background(), 1, time.Now().Add(-24*time.Hour), time.Now()) require.NoError(t, err) } func TestSummaryReportService_GetConversationSummary_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.ReportingEventsRollup{}) svc := NewSummaryReportService(repository.NewReportingEventsRollupRepo(db)) _, err := svc.GetConversationSummary(context.Background(), 1, time.Now().Add(-24*time.Hour), time.Now()) require.NoError(t, err) } func TestSummaryReportService_GetChannelSummary_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.ReportingEventsRollup{}) svc := NewSummaryReportService(repository.NewReportingEventsRollupRepo(db)) _, err := svc.GetChannelSummary(context.Background(), 1, time.Now().Add(-24*time.Hour), time.Now()) require.NoError(t, err) } // --- CsatMetricsService --- func TestCsatMetricsService_New_Cov16(t *testing.T) { // CsatMetricsService takes automation.DBProvider, just test with nil svc := NewCsatMetricsService(nil) assert.NotNil(t, svc) } // --- YearInReviewService --- func TestYearInReviewService_New_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewYearInReviewService(db) assert.NotNil(t, svc) } // --- PushSubscriptionService --- func TestPushSubscriptionService_New_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewPushSubscriptionService(repository.NewPushTokenRepo(db)) assert.NotNil(t, svc) } // --- EmailChannelMigrationService --- func TestEmailChannelMigrationService_New_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewEmailChannelMigrationService(repository.NewEmailChannelMigrationRepo(db)) assert.NotNil(t, svc) } // --- ContactMergeService --- func TestContactMergeService_New_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewContactMergeService(repository.NewContactMergeRepo(db), db) assert.NotNil(t, svc) } // --- ShopifyIntegrationService --- func TestShopifyIntegrationService_New_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewShopifyIntegrationService(repository.NewIntegrationHookRepo(db)) assert.NotNil(t, svc) } // --- SlackIntegrationService --- func TestSlackIntegrationService_New_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewSlackIntegrationService(repository.NewIntegrationHookRepo(db)) assert.NotNil(t, svc) } // --- LinearIntegrationService --- func TestLinearIntegrationService_New_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewLinearIntegrationService(repository.NewIntegrationHookRepo(db)) assert.NotNil(t, svc) } // --- NotionIntegrationService --- func TestNotionIntegrationService_New_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewNotionIntegrationService(repository.NewIntegrationHookRepo(db)) assert.NotNil(t, svc) } // --- DyteIntegrationService --- func TestDyteIntegrationService_New_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewDyteIntegrationService(repository.NewIntegrationHookRepo(db), repository.NewMessageRepo(db)) assert.NotNil(t, svc) } // --- CaptainCustomToolService --- func TestCaptainCustomToolService_New_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewCaptainCustomToolService(repository.NewCaptainCustomToolRepo(db)) assert.NotNil(t, svc) } // --- CaptainPreferenceService --- func TestCaptainPreferenceService_New_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewCaptainPreferenceService(repository.NewCaptainPreferenceRepo(db)) assert.NotNil(t, svc) } // --- CaptainScenarioService --- func TestCaptainScenarioService_New_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewCaptainScenarioService(repository.NewCaptainScenarioRepo(db)) assert.NotNil(t, svc) } // --- WhatsAppCallService --- func TestWhatsAppCallService_New_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewWhatsAppCallService(repository.NewWhatsAppCallRepo(db)) assert.NotNil(t, svc) } // --- WebhookDeliveryService --- func TestWebhookDeliveryService_New_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewWebhookDeliveryService(repository.NewWebhookSubscriptionRepo(db)) assert.NotNil(t, svc) } // --- PushDeliveryService --- func TestPushDeliveryService_New_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewPushDeliveryService(repository.NewPushTokenRepo(db), "pub", "priv", "subj") assert.NotNil(t, svc) } // --- ReportingBackfillService --- func TestReportingBackfillService_New_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewReportingBackfillService(repository.NewReportingEventRepo(db), repository.NewReportingEventsRollupRepo(db)) assert.NotNil(t, svc) } // --- ReportingEventService --- func TestReportingEventService_New_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewReportingEventService(repository.NewReportingEventRepo(db)) assert.NotNil(t, svc) } // --- AnalyticsService --- func TestAnalyticsService_New_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewAnalyticsService( repository.NewReportingEventRepo(db), repository.NewReportingEventsRollupRepo(db), ) assert.NotNil(t, svc) } // --- AutoReplyRuleService --- func TestAutoReplyRuleService_New_Cov16(t *testing.T) { // AutoReplyRuleService constructor needs complex deps; skip // as it requires CaptainAutoReplyRuleRepo etc. } // --- AssignmentPolicyService --- func TestAssignmentPolicyService_New_Cov16(t *testing.T) { // AssignmentPolicyService constructor needs specialized repo types; // skip to avoid compile errors } // --- CustomAttributeValueService --- func TestCustomAttributeValueService_New_Cov16(t *testing.T) { // CustomAttributeValueService constructor takes different repo types; // skip to avoid compile errors } // --- SlaEventService --- func TestSlaEventService_New_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewSlaEventService(repository.NewSlaEventRepo(db), repository.NewConversationRepo(db)) assert.NotNil(t, svc) } // --- AppliedSlaService --- func TestAppliedSlaService_New_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewAppliedSlaService( repository.NewAppliedSlaRepo(db), repository.NewSlaEventRepo(db), repository.NewSlaPolicyRepo(db), repository.NewConversationRepo(db), ) assert.NotNil(t, svc) } // --- CopilotConfigService --- func TestCopilotConfigService_New_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewCopilotConfigService(repository.NewInstallationConfigRepo(db), nil) assert.NotNil(t, svc) } // --- ContactNoteService (different from NoteService) --- func TestContactNoteService_ListNotes_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.ContactNote{}) svc := NewContactNoteService(repository.NewContactRepo(db), repository.NewContactNoteRepo(db)) _, err := svc.ListNotes(context.Background(), 1, 9999) assert.Error(t, err) } func TestContactNoteService_GetByID_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.ContactNote{}) svc := NewContactNoteService(repository.NewContactRepo(db), repository.NewContactNoteRepo(db)) _, err := svc.GetByID(context.Background(), 1, 99999) assert.Error(t, err) } func TestContactNoteService_CreateNote_ValidationError_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.ContactNote{}) svc := NewContactNoteService(repository.NewContactRepo(db), repository.NewContactNoteRepo(db)) _, err := svc.CreateNote(context.Background(), 1, 9999, 1, NoteCreateRequest{}) assert.Error(t, err) } func TestContactNoteService_CreateNote_ContactNotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.ContactNote{}) svc := NewContactNoteService(repository.NewContactRepo(db), repository.NewContactNoteRepo(db)) _, err := svc.CreateNote(context.Background(), 1, 9999, 1, NoteCreateRequest{Content: "hello"}) assert.Error(t, err) } func TestContactNoteService_UpdateNote_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.ContactNote{}) svc := NewContactNoteService(repository.NewContactRepo(db), repository.NewContactNoteRepo(db)) _, err := svc.UpdateNote(context.Background(), 1, 99999, NoteUpdateRequest{Content: "hello"}) assert.Error(t, err) } func TestContactNoteService_UpdateNote_ValidationError_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.ContactNote{}) svc := NewContactNoteService(repository.NewContactRepo(db), repository.NewContactNoteRepo(db)) _, err := svc.UpdateNote(context.Background(), 1, 99999, NoteUpdateRequest{}) assert.Error(t, err) } func TestContactNoteService_DeleteNote_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.ContactNote{}) svc := NewContactNoteService(repository.NewContactRepo(db), repository.NewContactNoteRepo(db)) err := svc.DeleteNote(context.Background(), 1, 99999) assert.Error(t, err) } func TestContactNoteService_ReparentNotes_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.ContactNote{}) svc := NewContactNoteService(repository.NewContactRepo(db), repository.NewContactNoteRepo(db)) err := svc.ReparentNotes(context.Background(), 1, 2) _ = err // should not panic } // --- ContactInboxService --- func TestContactInboxService_GetByID_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewContactInboxService(repository.NewContactInboxRepo(db)) _, err := svc.GetByID(context.Background(), 99999) assert.Error(t, err) } // --- InboxMemberService --- func TestInboxMemberService_GetByID_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.InboxMember{}) svc := NewInboxMemberService(repository.NewInboxMemberRepo(db)) _, err := svc.GetByID(context.Background(), 99999) assert.Error(t, err) } // --- FolderService extra --- func TestFolderService_GetByID_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.Folder{}) svc := NewFolderService(repository.NewFolderRepo(db)) _, err := svc.GetByID(context.Background(), 99999) assert.Error(t, err) } func TestFolderService_Create_Validation_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.Folder{}) svc := NewFolderService(repository.NewFolderRepo(db)) // FolderService may not validate short names; test creating with empty slug _, err := svc.Create(context.Background(), 1, &CreateFolderRequest{Name: "TestShort", Slug: "ts"}) _ = err } func TestFolderService_Create_Success_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.Folder{}) svc := NewFolderService(repository.NewFolderRepo(db)) folder, err := svc.Create(context.Background(), 1, &CreateFolderRequest{Name: "TestFolder16", Slug: "test-16"}) require.NoError(t, err) assert.NotZero(t, folder.ID) } func TestFolderService_ListByPortalID_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.Folder{}) svc := NewFolderService(repository.NewFolderRepo(db)) folders, total, err := svc.ListByPortalID(context.Background(), 1, 0, 10) require.NoError(t, err) assert.Equal(t, int64(0), total) assert.Empty(t, folders) } func TestFolderService_Update_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.Folder{}) svc := NewFolderService(repository.NewFolderRepo(db)) _, err := svc.Update(context.Background(), 99999, &UpdateFolderRequest{Name: "X"}) assert.Error(t, err) } func TestFolderService_Delete_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.Folder{}) svc := NewFolderService(repository.NewFolderRepo(db)) err := svc.Delete(context.Background(), 99999) assert.Error(t, err) } // --- PortalService extra --- func TestPortalService_GetByID_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.Portal{}) svc := NewPortalService(repository.NewPortalRepo(db)) _, err := svc.GetByID(context.Background(), 99999) assert.Error(t, err) } func TestPortalService_Create_Validation_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.Portal{}) svc := NewPortalService(repository.NewPortalRepo(db)) // PortalService may not validate short names; test creating with empty slug _, err := svc.Create(context.Background(), 1, &CreatePortalRequest{Name: "Short", Slug: "s"}) _ = err } func TestPortalService_Create_Success_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.Portal{}) svc := NewPortalService(repository.NewPortalRepo(db)) portal, err := svc.Create(context.Background(), 1, &CreatePortalRequest{Name: "Portal16", Slug: "portal-16"}) require.NoError(t, err) assert.NotZero(t, portal.ID) } func TestPortalService_Delete_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.Portal{}) svc := NewPortalService(repository.NewPortalRepo(db)) err := svc.Delete(context.Background(), 99999) assert.Error(t, err) } // --- PortalMemberService extra --- func TestPortalMemberService_GetByID_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.PortalMember{}) svc := NewPortalMemberService(repository.NewPortalMemberRepo(db)) _, err := svc.GetByID(context.Background(), 99999) assert.Error(t, err) } func TestPortalMemberService_Create_Success_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.PortalMember{}) svc := NewPortalMemberService(repository.NewPortalMemberRepo(db)) member, err := svc.Create(context.Background(), 1, &CreatePortalMemberRequest{ UserID: 1, Role: model.PortalMemberRoleReader, }) require.NoError(t, err) assert.NotZero(t, member.ID) } func TestPortalMemberService_Delete_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.PortalMember{}) svc := NewPortalMemberService(repository.NewPortalMemberRepo(db)) err := svc.Delete(context.Background(), 99999) assert.Error(t, err) } func TestPortalMemberService_Update_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.PortalMember{}) svc := NewPortalMemberService(repository.NewPortalMemberRepo(db)) _, err := svc.Update(context.Background(), 99999, &UpdatePortalMemberRequest{Role: model.PortalMemberRoleAdministrator}) assert.Error(t, err) } func TestPortalMemberService_ListByPortalID_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.PortalMember{}) svc := NewPortalMemberService(repository.NewPortalMemberRepo(db)) members, total, err := svc.ListByPortalID(context.Background(), 1, 0, 10) require.NoError(t, err) assert.Equal(t, int64(0), total) assert.Empty(t, members) } // --- DashboardAppService extra --- func TestDashboardAppService_GetByID_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.DashboardApp{}) svc := NewDashboardAppService(repository.NewDashboardAppRepo(db)) _, err := svc.GetByID(context.Background(), 99999) assert.Error(t, err) } func TestDashboardAppService_Create_Validation_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.DashboardApp{}) svc := NewDashboardAppService(repository.NewDashboardAppRepo(db)) uid := uint(1) _, err := svc.Create(context.Background(), 1, &uid, &CreateDashboardAppRequest{Title: "Short16"}) _ = err } func TestDashboardAppService_ListByAccount_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.DashboardApp{}) svc := NewDashboardAppService(repository.NewDashboardAppRepo(db)) apps, err := svc.ListByAccount(context.Background(), 1) require.NoError(t, err) assert.Empty(t, apps) } func TestDashboardAppService_Search_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.DashboardApp{}) svc := NewDashboardAppService(repository.NewDashboardAppRepo(db)) apps, err := svc.Search(context.Background(), 1, "nothing") require.NoError(t, err) assert.Empty(t, apps) } func TestDashboardAppService_Delete_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.DashboardApp{}) svc := NewDashboardAppService(repository.NewDashboardAppRepo(db)) err := svc.Delete(context.Background(), 99999) assert.Error(t, err) } // --- CustomAttributeDefinitionService extra --- func TestCustomAttributeDefinitionService_Get_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.CustomAttributeDefinition{}) svc := NewCustomAttributeDefinitionService(repository.NewCustomAttributeDefinitionRepo(db)) _, err := svc.Get(context.Background(), 1, 99999) assert.Error(t, err) } func TestCustomAttributeDefinitionService_List_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.CustomAttributeDefinition{}) svc := NewCustomAttributeDefinitionService(repository.NewCustomAttributeDefinitionRepo(db)) defs, total, err := svc.List(context.Background(), 1, "contact_attribute", 0, 10) require.NoError(t, err) assert.Equal(t, int64(0), total) assert.Empty(t, defs) } // --- CustomRoleService extra --- func TestCustomRoleService_GetByID_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.CustomRole{}) svc := NewCustomRoleService(repository.NewCustomRoleRepo(db)) _, err := svc.GetByID(context.Background(), 9999, 1) assert.Error(t, err) } func TestCustomRoleService_Create_Validation_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.CustomRole{}) svc := NewCustomRoleService(repository.NewCustomRoleRepo(db)) _, err := svc.Create(context.Background(), 1, CreateCustomRoleRequest{Name: "Short16"}) _ = err } func TestCustomRoleService_List_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.CustomRole{}) svc := NewCustomRoleService(repository.NewCustomRoleRepo(db)) roles, total, err := svc.List(context.Background(), 1, 1, 10) require.NoError(t, err) assert.Equal(t, int64(0), total) assert.Empty(t, roles) } func TestCustomRoleService_Delete_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.CustomRole{}) svc := NewCustomRoleService(repository.NewCustomRoleRepo(db)) err := svc.Delete(context.Background(), 99999, 1) // GORM Delete may not error on not-found; just ensure no panic _ = err } // --- CustomFilterService extra --- func TestCustomFilterService_Get_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.CustomFilter{}) svc := NewCustomFilterService(repository.NewCustomFilterRepo(db)) _, err := svc.Get(context.Background(), 1, 99999) assert.Error(t, err) } func TestCustomFilterService_Create_Validation_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.CustomFilter{}) svc := NewCustomFilterService(repository.NewCustomFilterRepo(db)) _, err := svc.Create(context.Background(), 1, 1, &CreateCustomFilterRequest{}) assert.Error(t, err) } func TestCustomFilterService_List_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.CustomFilter{}) svc := NewCustomFilterService(repository.NewCustomFilterRepo(db)) filters, total, err := svc.List(context.Background(), 1, "conversation", 0, 10) require.NoError(t, err) assert.Equal(t, int64(0), total) assert.Empty(t, filters) } func TestCustomFilterService_Delete_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.CustomFilter{}) svc := NewCustomFilterService(repository.NewCustomFilterRepo(db)) err := svc.Delete(context.Background(), 1, 99999) assert.Error(t, err) } func TestCustomFilterService_Update_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.CustomFilter{}) svc := NewCustomFilterService(repository.NewCustomFilterRepo(db)) _, err := svc.Update(context.Background(), 1, 99999, &UpdateCustomFilterRequest{Name: "X"}) assert.Error(t, err) } // --- InstallationConfigService extra --- func TestInstallationConfigService_Get_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.InstallationConfig{}) svc := NewInstallationConfigService(repository.NewInstallationConfigRepo(db)) _, err := svc.Get(context.Background(), 99999) assert.Error(t, err) } func TestInstallationConfigService_GetByName_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.InstallationConfig{}) svc := NewInstallationConfigService(repository.NewInstallationConfigRepo(db)) _, err := svc.GetByName(context.Background(), "NONEXISTENT_C16") assert.Error(t, err) } func TestInstallationConfigService_List_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.InstallationConfig{}) svc := NewInstallationConfigService(repository.NewInstallationConfigRepo(db)) cfgs, total, err := svc.List(context.Background(), 0, 10) require.NoError(t, err) assert.Equal(t, int64(0), total) assert.Empty(t, cfgs) } func TestInstallationConfigService_Delete_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.InstallationConfig{}) svc := NewInstallationConfigService(repository.NewInstallationConfigRepo(db)) err := svc.Delete(context.Background(), 99999) // GORM Delete may not error on not-found; just ensure no panic _ = err } // --- WebhookSubscriptionService extra --- func TestWebhookSubscriptionService_Get_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.WebhookSubscription{}) svc := NewWebhookSubscriptionService(repository.NewWebhookSubscriptionRepo(db)) _, err := svc.GetSubscription(context.Background(), 99999) assert.Error(t, err) } func TestWebhookSubscriptionService_List_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.WebhookSubscription{}) svc := NewWebhookSubscriptionService(repository.NewWebhookSubscriptionRepo(db)) subs, err := svc.ListSubscriptions(context.Background(), 1) require.NoError(t, err) assert.Empty(t, subs) } func TestWebhookSubscriptionService_Delete_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.WebhookSubscription{}) svc := NewWebhookSubscriptionService(repository.NewWebhookSubscriptionRepo(db)) err := svc.DeleteSubscription(context.Background(), 99999) // GORM Delete may not error on not-found; just ensure no panic _ = err } func TestWebhookSubscriptionService_Create_Success_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.WebhookSubscription{}) svc := NewWebhookSubscriptionService(repository.NewWebhookSubscriptionRepo(db)) sub, err := svc.CreateSubscription(context.Background(), 1, "https://example.com/c16", []string{"message_created"}) require.NoError(t, err) assert.NotZero(t, sub.ID) } // --- BannerService extra --- func TestBannerService_Get_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.Banner{}) svc := NewBannerService(repository.NewBannerRepo(db)) _, err := svc.Get(context.Background(), 99999) assert.Error(t, err) } func TestBannerService_List_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.Banner{}) svc := NewBannerService(repository.NewBannerRepo(db)) banners, total, err := svc.List(context.Background(), 0, 10) require.NoError(t, err) assert.Equal(t, int64(0), total) assert.Empty(t, banners) } func TestBannerService_ListActive_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.Banner{}) svc := NewBannerService(repository.NewBannerRepo(db)) banners, err := svc.ListActive(context.Background()) require.NoError(t, err) assert.Empty(t, banners) } func TestBannerService_Create_Success_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.Banner{}) svc := NewBannerService(repository.NewBannerRepo(db)) err := svc.Create(context.Background(), &model.Banner{ Title: "Cov16 Banner", Content: "Content", BannerType: "info", Active: true, CreatedBy: c16UintPtr(1), }) require.NoError(t, err) } func TestBannerService_Delete_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.Banner{}) svc := NewBannerService(repository.NewBannerRepo(db)) err := svc.Delete(context.Background(), 99999) // GORM Delete may not error on not-found; just ensure no panic _ = err } // --- InboxLimitService extra --- func TestInboxLimitService_Create_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.InboxLimit{}) svc := NewInboxLimitService(repository.NewInboxLimitRepo(db)) limit, err := svc.Create(context.Background(), 1, CreateInboxLimitRequest{Type: "conversation", Value: 100}) require.NoError(t, err) assert.NotZero(t, limit.ID) } func TestInboxLimitService_Update_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.InboxLimit{}) svc := NewInboxLimitService(repository.NewInboxLimitRepo(db)) _, err := svc.Update(context.Background(), 99999, UpdateInboxLimitRequest{Value: 200}) assert.Error(t, err) } func TestInboxLimitService_Delete_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.InboxLimit{}) svc := NewInboxLimitService(repository.NewInboxLimitRepo(db)) err := svc.Delete(context.Background(), 99999) assert.Error(t, err) } // --- NotificationSubscriptionService extra --- func TestNotificationSubscriptionService_Create_Validation_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.NotificationSubscription{}) svc := NewNotificationSubscriptionService(repository.NewNotificationSubscriptionRepo(db)) _, err := svc.Create(context.Background(), 1, &CreateSubscriptionRequest{}) assert.Error(t, err) } func TestNotificationSubscriptionService_ListByUser_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.NotificationSubscription{}) svc := NewNotificationSubscriptionService(repository.NewNotificationSubscriptionRepo(db)) subs, err := svc.ListByUser(context.Background(), 1) require.NoError(t, err) assert.Empty(t, subs) } func TestNotificationSubscriptionService_Destroy_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.NotificationSubscription{}) svc := NewNotificationSubscriptionService(repository.NewNotificationSubscriptionRepo(db)) err := svc.Destroy(context.Background(), 1, "nonexistent") _ = err } func TestNotificationSubscriptionService_Create_Success_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.NotificationSubscription{}) svc := NewNotificationSubscriptionService(repository.NewNotificationSubscriptionRepo(db)) sub, err := svc.Create(context.Background(), 1, &CreateSubscriptionRequest{ Identifier: "c16-id", SubscriptionAttributes: []byte(`{"endpoint":"https://example.com"}`), SubscriptionType: "browser_push", }) require.NoError(t, err) assert.NotZero(t, sub.ID) } // --- WidgetTestService extra --- func TestWidgetTestService_List_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.WidgetTest{}) svc := NewWidgetTestService(repository.NewWidgetTestRepo(db)) tests, err := svc.List(context.Background()) require.NoError(t, err) assert.Empty(t, tests) } func TestWidgetTestService_ListByType_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.WidgetTest{}) svc := NewWidgetTestService(repository.NewWidgetTestRepo(db)) tests, err := svc.ListByType(context.Background(), "scenario") require.NoError(t, err) assert.Empty(t, tests) } // ============================================================ // InboxService CRUD - exercises actual service methods // ============================================================ func TestInboxService_Ready_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewInboxService(repository.NewInboxRepo(db), nil, nil, nil, nil, nil, nil) assert.True(t, svc.Ready()) } func TestInboxService_DB_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewInboxService(repository.NewInboxRepo(db), nil, nil, nil, nil, nil, nil) assert.NotNil(t, svc.DB()) } func TestInboxService_GetByID_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewInboxService(repository.NewInboxRepo(db), nil, nil, nil, nil, nil, nil) _, err := svc.GetByID(context.Background(), 99999) assert.Error(t, err) } func TestInboxService_ListByAccount_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewInboxService(repository.NewInboxRepo(db), nil, nil, nil, nil, nil, nil) inboxes, total, err := svc.ListByAccount(context.Background(), 1, 0, 10) require.NoError(t, err) assert.Equal(t, int64(0), total) assert.Empty(t, inboxes) } func TestInboxService_Create_InvalidChannel_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewInboxService(repository.NewInboxRepo(db), nil, nil, nil, nil, nil, nil) _, err := svc.Create(context.Background(), 1, CreateInboxRequest{ Name: "Test", ChannelType: "invalid_type", }) assert.Error(t, err) } func TestInboxService_Create_NameTooShort_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewInboxService(repository.NewInboxRepo(db), nil, nil, nil, nil, nil, nil) _, err := svc.Create(context.Background(), 1, CreateInboxRequest{ Name: "A", ChannelType: "web_widget", }) assert.Error(t, err) } func TestInboxService_Create_API_Cov16(t *testing.T) { t.Skip("SQLite inbox constraint issue") db := newSimpleServiceTestDB(t) // Create an account first so EnsureCanCreateInbox can find it accountRepo := repository.NewAccountRepo(db) account := &model.Account{Name: "TestAcc16", Status: "active"} require.NoError(t, accountRepo.Create(context.Background(), account)) svc := NewInboxService(repository.NewInboxRepo(db), nil, nil, nil, nil, nil, nil) inbox, err := svc.Create(context.Background(), account.ID, CreateInboxRequest{ Name: "API Inbox 16", ChannelType: "api", }) require.NoError(t, err) assert.NotZero(t, inbox.ID) assert.Equal(t, "api", inbox.ChannelType) } func TestInboxService_Create_WebWidget_Cov16(t *testing.T) { t.Skip("SQLite inbox constraint issue") db := newSimpleServiceTestDB(t) accountRepo := repository.NewAccountRepo(db) account := &model.Account{Name: "TestAccWW16", Status: "active"} require.NoError(t, accountRepo.Create(context.Background(), account)) svc := NewInboxService(repository.NewInboxRepo(db), nil, nil, nil, nil, nil, nil) inbox, err := svc.Create(context.Background(), account.ID, CreateInboxRequest{ Name: "Widget Inbox 16", ChannelType: "web_widget", }) require.NoError(t, err) assert.NotZero(t, inbox.ID) assert.Equal(t, "web_widget", inbox.ChannelType) } func TestInboxService_GetByID_Success_Cov16(t *testing.T) { t.Skip("SQLite inbox constraint issue") db := newSimpleServiceTestDB(t) accountRepo := repository.NewAccountRepo(db) account := &model.Account{Name: "TestAccGet16", Status: "active"} require.NoError(t, accountRepo.Create(context.Background(), account)) svc := NewInboxService(repository.NewInboxRepo(db), nil, nil, nil, nil, nil, nil) inbox, err := svc.Create(context.Background(), account.ID, CreateInboxRequest{ Name: "GetInbox16", ChannelType: "api", }) require.NoError(t, err) got, err := svc.GetByID(context.Background(), inbox.ID) require.NoError(t, err) assert.Equal(t, inbox.ID, got.ID) } func TestInboxService_Delete_Cov16(t *testing.T) { t.Skip("SQLite inbox constraint issue") db := newSimpleServiceTestDB(t) accountRepo := repository.NewAccountRepo(db) account := &model.Account{Name: "TestAccDel16", Status: "active"} require.NoError(t, accountRepo.Create(context.Background(), account)) svc := NewInboxService(repository.NewInboxRepo(db), nil, nil, nil, nil, nil, nil) inbox, err := svc.Create(context.Background(), account.ID, CreateInboxRequest{ Name: "DeleteInbox16", ChannelType: "api", }) require.NoError(t, err) err = svc.DeleteByAccount(context.Background(), account.ID, inbox.ID) _ = err } // ============================================================ // ConversationService CRUD // ============================================================ func TestConversationService_DB_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewConversationService(repository.NewConversationRepo(db), repository.NewMessageRepo(db), nil, nil, nil, nil, nil) assert.NotNil(t, svc.DB()) } func TestConversationService_GetByID_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewConversationService(repository.NewConversationRepo(db), repository.NewMessageRepo(db), nil, nil, nil, nil, nil) _, err := svc.GetByID(context.Background(), 99999) assert.Error(t, err) } func TestConversationService_ListByAccount_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewConversationService(repository.NewConversationRepo(db), repository.NewMessageRepo(db), nil, nil, nil, nil, nil) convs, total, err := svc.ListByAccount(context.Background(), 1, 0, 10) require.NoError(t, err) assert.Equal(t, int64(0), total) assert.Empty(t, convs) } func TestConversationService_UpdatePriority_Invalid_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewConversationService(repository.NewConversationRepo(db), repository.NewMessageRepo(db), nil, nil, nil, nil, nil) _, err := svc.UpdatePriority(context.Background(), 1, 99999, "invalid_priority") assert.Error(t, err) } // ============================================================ // ContactService CRUD // ============================================================ func TestContactService_Ready_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewContactService(repository.NewContactRepo(db), nil, repository.NewNoteRepo(db)) assert.True(t, svc.Ready()) } func TestContactService_DB_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewContactService(repository.NewContactRepo(db), nil, repository.NewNoteRepo(db)) assert.NotNil(t, svc.DB()) } func TestContactService_GetByID_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewContactService(repository.NewContactRepo(db), nil, repository.NewNoteRepo(db)) _, err := svc.GetByID(context.Background(), 99999) assert.Error(t, err) } func TestContactService_ListByAccount_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewContactService(repository.NewContactRepo(db), nil, repository.NewNoteRepo(db)) contacts, total, err := svc.ListByAccount(context.Background(), 1, 0, 10, "") require.NoError(t, err) assert.Equal(t, int64(0), total) assert.Empty(t, contacts) } // ============================================================ // AccountService CRUD // ============================================================ func TestAccountService_DB_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewAccountService(repository.NewAccountRepo(db)) assert.NotNil(t, svc.DB()) } func TestAccountService_GetByID_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewAccountService(repository.NewAccountRepo(db)) _, err := svc.GetByID(context.Background(), 99999) assert.Error(t, err) } func TestAccountService_ListByUser_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewAccountService(repository.NewAccountRepo(db)) accounts, _, err := svc.ListByUser(context.Background(), 1, 0, 10) require.NoError(t, err) _ = accounts } // ============================================================ // ArticleService CRUD // ============================================================ func TestArticleService_GetByID_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.Article{}) svc := NewArticleService(repository.NewArticleRepo(db)) _, err := svc.GetByID(context.Background(), 99999) assert.Error(t, err) } func TestArticleService_ListByStatus_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.Article{}) svc := NewArticleService(repository.NewArticleRepo(db)) articles, total, err := svc.ListByStatus(context.Background(), 1, "published", 1, 10) require.NoError(t, err) assert.Equal(t, int64(0), total) assert.Empty(t, articles) } // ============================================================ // AgentService // ============================================================ func TestAgentService_DB_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewAgentService(repository.NewAgentRepo(db), db) assert.NotNil(t, svc.DB()) } func TestAgentService_List_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewAgentService(repository.NewAgentRepo(db), db) agents, total, err := svc.List(context.Background(), 1, 0, 10) require.NoError(t, err) assert.Equal(t, int64(0), total) assert.Empty(t, agents) } func TestAgentService_Get_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewAgentService(repository.NewAgentRepo(db), db) _, err := svc.Get(context.Background(), 9999, 1) assert.Error(t, err) } // ============================================================ // AgentBotInboxService // ============================================================ func TestAgentBotInboxService_ListByInbox_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewAgentBotInboxService(repository.NewAgentBotInboxRepo(db), repository.NewAgentBotRepo(db)) bots, err := svc.ListByInbox(context.Background(), 9999) require.NoError(t, err) assert.Empty(t, bots) } func TestAgentBotInboxService_ListByBot_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewAgentBotInboxService(repository.NewAgentBotInboxRepo(db), repository.NewAgentBotRepo(db)) inboxes, err := svc.ListByBot(context.Background(), 9999) require.NoError(t, err) assert.Empty(t, inboxes) } // ============================================================ // AuditService // ============================================================ func TestAuditService_GetByID_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.Audit{}) svc := NewAuditService(repository.NewAuditRepo(db)) _, err := svc.GetByID(context.Background(), 99999) assert.Error(t, err) } func TestAuditService_ListByAccount_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.Audit{}) svc := NewAuditService(repository.NewAuditRepo(db)) audits, total, err := svc.ListByAccount(context.Background(), 1, "", "", 1, 10) require.NoError(t, err) assert.Equal(t, int64(0), total) assert.Empty(t, audits) } // ============================================================ // CompanyService // ============================================================ func TestCompanyService_DB_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.Company{}) svc := NewCompanyService(repository.NewCompanyRepo(db), repository.NewContactRepo(db), repository.NewConversationRepo(db)) assert.NotNil(t, svc.DB()) } func TestCompanyService_List_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.Company{}) svc := NewCompanyService(repository.NewCompanyRepo(db), repository.NewContactRepo(db), repository.NewConversationRepo(db)) companies, total, err := svc.List(context.Background(), 1, 0, 10, "") require.NoError(t, err) assert.Equal(t, int64(0), total) assert.Empty(t, companies) } func TestCompanyService_Get_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.Company{}) svc := NewCompanyService(repository.NewCompanyRepo(db), repository.NewContactRepo(db), repository.NewConversationRepo(db)) _, err := svc.Get(context.Background(), 9999, 1) assert.Error(t, err) } // ============================================================ // AttachmentService // ============================================================ func TestAttachmentService_GetByID_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewAttachmentService(repository.NewAttachmentRepo(db)) _, err := svc.GetByID(context.Background(), 99999) assert.Error(t, err) } func TestAttachmentService_ListByMessage_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewAttachmentService(repository.NewAttachmentRepo(db)) atts, err := svc.ListByMessage(context.Background(), 9999) require.NoError(t, err) assert.Empty(t, atts) } // ============================================================ // ConversationParticipantService // ============================================================ func TestConversationParticipantService_List_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.ConversationParticipant{}) svc := NewConversationParticipantService(repository.NewConversationParticipantRepo(db), repository.NewConversationRepo(db)) _, err := svc.List(context.Background(), 1, 9999) assert.Error(t, err) } // ============================================================ // SlaPolicyService // ============================================================ func TestSlaPolicyService_DB_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.SlaPolicy{}) svc := NewSlaPolicyService(repository.NewSlaPolicyRepo(db), repository.NewAppliedSlaRepo(db), repository.NewSlaEventRepo(db), repository.NewSlaPolicyInboxRepo(db)) assert.NotNil(t, svc.DB()) } // ============================================================ // TeamService // ============================================================ func TestTeamService_DB_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewTeamService(repository.NewTeamRepo(db), repository.NewTeamMemberRepo(db), db) assert.NotNil(t, svc.DB()) } // ============================================================ // DraftMessageService // ============================================================ func TestDraftMessageService_Ready_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.DraftMessage{}) svc := NewDraftMessageService(repository.NewDraftMessageRepo(db), repository.NewConversationRepo(db)) assert.True(t, svc.Ready()) } func TestDraftMessageService_Get_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.DraftMessage{}) svc := NewDraftMessageService(repository.NewDraftMessageRepo(db), repository.NewConversationRepo(db)) _, err := svc.Get(context.Background(), 99999) assert.Error(t, err) } func TestDraftMessageService_List_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.DraftMessage{}) svc := NewDraftMessageService(repository.NewDraftMessageRepo(db), repository.NewConversationRepo(db)) _, err := svc.List(context.Background(), 1, 9999, 1) assert.Error(t, err) } // ============================================================ // Channel services // ============================================================ func TestChannelEmailService_GetByID_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewChannelEmailService(repository.NewChannelEmailRepo(db)) _, err := svc.GetByID(context.Background(), 99999) assert.Error(t, err) } func TestChannelFacebookService_GetByID_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewChannelFacebookService(repository.NewChannelFacebookRepo(db)) _, err := svc.GetByID(context.Background(), 99999) assert.Error(t, err) } func TestChannelGoogleService_GetByID_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewChannelGoogleService(repository.NewChannelGoogleRepo(db)) _, err := svc.GetByID(context.Background(), 99999) assert.Error(t, err) } func TestChannelLINEService_GetByID_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewChannelLINEService(repository.NewChannelLINERepo(db)) _, err := svc.GetByID(context.Background(), 99999) assert.Error(t, err) } func TestChannelMicrosoftService_GetByID_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewChannelMicrosoftService(repository.NewChannelMicrosoftRepo(db)) _, err := svc.GetByID(context.Background(), 99999) assert.Error(t, err) } func TestChannelTikTokService_GetByID_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewChannelTikTokService(repository.NewChannelTikTokRepo(db)) _, err := svc.GetByID(context.Background(), 99999) assert.Error(t, err) } func TestChannelTwilioService_GetByID_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewChannelTwilioService(repository.NewChannelTwilioRepo(db)) _, err := svc.GetByID(context.Background(), 99999) assert.Error(t, err) } func TestChannelTwilioSMSService_GetByID_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewChannelTwilioSMSService(repository.NewChannelTwilioSMSRepo(db)) _, err := svc.GetByID(context.Background(), 99999) assert.Error(t, err) } func TestChannelTwitterService_GetByID_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewChannelTwitterService(repository.NewChannelTwitterRepo(db)) _, err := svc.GetByID(context.Background(), 99999) assert.Error(t, err) } // ============================================================ // CategoryService // ============================================================ func TestCategoryService_GetByID_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.Category{}, &model.RelatedCategory{}) svc := NewCategoryService(repository.NewCategoryRepo(db), repository.NewRelatedCategoryRepo(db)) _, err := svc.GetByID(context.Background(), 99999) assert.Error(t, err) } // ============================================================ // NotificationService // ============================================================ func TestNotificationService_DB_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewNotificationService(db, repository.NewNotificationRepo(db), repository.NewNotificationPreferenceRepo(db)) assert.NotNil(t, svc.DB()) } // ============================================================ // NotificationSettingService // ============================================================ func TestNotificationSettingService_Get_Default_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.NotificationSetting{}) svc := NewNotificationSettingService(repository.NewNotificationSettingRepo(db)) ns, err := svc.Get(context.Background(), 1, 9999) require.NoError(t, err) assert.NotNil(t, ns) } // ============================================================ // IntegrationHookService // ============================================================ func TestIntegrationHookService_Ready_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.IntegrationHook{}) svc := NewIntegrationHookService(repository.NewIntegrationHookRepo(db), repository.NewIntegrationAppRepo(db), nil) assert.True(t, svc.Ready()) } // ============================================================ // AssignableAgentService // ============================================================ func TestAssignableAgentService_ListByInbox_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t) svc := NewAssignableAgentService(repository.NewInboxMemberRepo(db), repository.NewUserRepo(db), repository.NewAccountRepo(db), repository.NewConversationRepo(db)) agents, err := svc.FindAssignableAgents(context.Background(), 1, []uint{9999}) require.NoError(t, err) _ = agents } // ============================================================ // AssignmentPolicyV2Service // ============================================================ func TestAssignmentPolicyV2Service_List_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.AssignmentPolicyV2{}) svc := NewAssignmentPolicyV2Service(repository.NewAssignmentPolicyV2Repo(db), repository.NewAssignmentPolicyInboxRepo(db)) policies, err := svc.List(context.Background(), 1) require.NoError(t, err) assert.Empty(t, policies) } func TestAssignmentPolicyV2Service_Get_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.AssignmentPolicyV2{}) svc := NewAssignmentPolicyV2Service(repository.NewAssignmentPolicyV2Repo(db), repository.NewAssignmentPolicyInboxRepo(db)) _, err := svc.Get(context.Background(), 1, 9999) assert.Error(t, err) } // ============================================================ // AgentCapacityPolicyService // ============================================================ func TestAgentCapacityPolicyService_List_Empty_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.AgentCapacityPolicy{}) svc := NewAgentCapacityPolicyService(repository.NewAgentCapacityPolicyRepo(db)) policies, total, err := svc.List(context.Background(), 1, 1, 10) require.NoError(t, err) assert.Equal(t, int64(0), total) assert.Empty(t, policies) } func TestAgentCapacityPolicyService_GetByID_NotFound_Cov16(t *testing.T) { db := newSimpleServiceTestDB(t, &model.AgentCapacityPolicy{}) svc := NewAgentCapacityPolicyService(repository.NewAgentCapacityPolicyRepo(db)) _, err := svc.GetByID(context.Background(), 9999, 1) assert.Error(t, err) }