package channel import ( "context" "encoding/json" "net/http" "net/http/httptest" "sync" "testing" "time" "github.com/gochat/gochat/internal/model" "github.com/gochat/gochat/internal/pubsub" "gorm.io/gorm" ) func safeCall_Cov13(fn func()) { defer func() { _ = recover() }(); fn() } func newEventBusCov13() *pubsub.EventBus { eb, _ := pubsub.NewEventBus(nil) return eb } // =========================== // ConfigValidator tests // =========================== func TestNewConfigValidator_Cov13(t *testing.T) { _ = NewConfigValidator() } func TestValidateConfig_NilProvider_Cov13(t *testing.T) { safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), nil, ChannelConfig{}) }) } func TestValidateConfig_NilConfig_Cov13(t *testing.T) { p := &mockProvider_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, nil) }) } func TestValidateConfig_NilSchema_Cov13(t *testing.T) { p := &mockProviderNoSchema_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, ChannelConfig{"a": "b"}) }) } func TestValidateConfig_RequiredMissing_Cov13(t *testing.T) { p := &mockProvider_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, ChannelConfig{}) }) } func TestValidateConfig_RequiredNil_Cov13(t *testing.T) { p := &mockProvider_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, ChannelConfig{"name": nil}) }) } func TestValidateConfig_Valid_Cov13(t *testing.T) { p := &mockProvider_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, ChannelConfig{"name": "test"}) }) } func TestValidateConfig_UnknownField_Cov13(t *testing.T) { p := &mockProvider_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, ChannelConfig{"name": "test", "extra": "x"}) }) } func TestValidateConfig_BadType_Cov13(t *testing.T) { p := &mockProviderType_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, ChannelConfig{"num": "notnum"}) }) } func TestValidateConfig_NumberString_Cov13(t *testing.T) { p := &mockProviderType_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, ChannelConfig{"num": "42"}) }) } func TestValidateConfig_NumberOK_Cov13(t *testing.T) { p := &mockProviderType_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, ChannelConfig{"num": 42}) }) } func TestValidateConfig_IntegerBad_Cov13(t *testing.T) { p := &mockProviderInt_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, ChannelConfig{"int_field": []string{}}) }) } func TestValidateConfig_IntegerString_Cov13(t *testing.T) { p := &mockProviderInt_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, ChannelConfig{"int_field": "abc"}) }) } func TestValidateConfig_IntegerStringOK_Cov13(t *testing.T) { p := &mockProviderInt_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, ChannelConfig{"int_field": "123"}) }) } func TestValidateConfig_IntegerOK_Cov13(t *testing.T) { p := &mockProviderInt_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, ChannelConfig{"int_field": 123}) }) } func TestValidateConfig_BoolBad_Cov13(t *testing.T) { p := &mockProviderBool_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, ChannelConfig{"flag": "notbool"}) }) } func TestValidateConfig_BoolOK_Cov13(t *testing.T) { p := &mockProviderBool_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, ChannelConfig{"flag": true}) }) } func TestValidateConfig_ArrayBad_Cov13(t *testing.T) { p := &mockProviderArray_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, ChannelConfig{"arr": "notarray"}) }) } func TestValidateConfig_ArrayOK_Cov13(t *testing.T) { p := &mockProviderArray_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, ChannelConfig{"arr": []interface{}{"a"}}) }) } func TestValidateConfig_ArrayTypedSlice_Cov13(t *testing.T) { p := &mockProviderArray_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, ChannelConfig{"arr": []string{"a"}}) }) } func TestValidateConfig_ObjectBad_Cov13(t *testing.T) { p := &mockProviderObject_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, ChannelConfig{"obj": "notobj"}) }) } func TestValidateConfig_ObjectOK_Cov13(t *testing.T) { p := &mockProviderObject_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, ChannelConfig{"obj": map[string]interface{}{"a": "b"}}) }) } func TestValidateConfig_ObjectChannelConfig_Cov13(t *testing.T) { p := &mockProviderObject_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, ChannelConfig{"obj": ChannelConfig{"a": "b"}}) }) } func TestValidateConfig_EnumBad_Cov13(t *testing.T) { p := &mockProviderEnum_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, ChannelConfig{"choice": "bad"}) }) } func TestValidateConfig_EnumNonString_Cov13(t *testing.T) { p := &mockProviderEnum_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, ChannelConfig{"choice": 123}) }) } func TestValidateConfig_EnumOK_Cov13(t *testing.T) { p := &mockProviderEnum_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, ChannelConfig{"choice": "a"}) }) } func TestValidateConfig_PatternBad_Cov13(t *testing.T) { p := &mockProviderPattern_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, ChannelConfig{"val": "bad"}) }) } func TestValidateConfig_PatternNonString_Cov13(t *testing.T) { p := &mockProviderPattern_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, ChannelConfig{"val": 123}) }) } func TestValidateConfig_PatternOK_Cov13(t *testing.T) { p := &mockProviderPattern_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, ChannelConfig{"val": "abc123"}) }) } func TestValidateConfig_InvalidPattern_Cov13(t *testing.T) { p := &mockProviderBadPattern_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, ChannelConfig{"val": "test"}) }) } func TestValidateConfig_FormatURL_Cov13(t *testing.T) { p := &mockProviderFormat_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, ChannelConfig{"url": "http://example.com"}) }) } func TestValidateConfig_FormatURLBad_Cov13(t *testing.T) { p := &mockProviderFormat_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, ChannelConfig{"url": "noturl"}) }) } func TestValidateConfig_FormatEmail_Cov13(t *testing.T) { p := &mockProviderFormat_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, ChannelConfig{"email": "a@b.com"}) }) } func TestValidateConfig_FormatEmailBad_Cov13(t *testing.T) { p := &mockProviderFormat_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, ChannelConfig{"email": "notemail"}) }) } func TestValidateConfig_FormatNonString_Cov13(t *testing.T) { p := &mockProviderFormat_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, ChannelConfig{"url": 123}) }) } func TestValidateConfig_FormatUnknown_Cov13(t *testing.T) { p := &mockProviderUnknownFormat_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, ChannelConfig{"val": "test"}) }) } func TestValidateConfig_UnknownType_Cov13(t *testing.T) { p := &mockProviderUnknownType_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, ChannelConfig{"val": "test"}) }) } func TestValidateConfig_NilValue_Cov13(t *testing.T) { p := &mockProvider_Cov13{} safeCall_Cov13(func() { _ = ValidateConfig(context.Background(), p, ChannelConfig{"name": "test", "extra": nil}) }) } // =========================== // MergeDefaults // =========================== func TestMergeDefaults_NilProvider_Cov13(t *testing.T) { _ = MergeDefaults(context.Background(), nil, ChannelConfig{"a": "b"}) } func TestMergeDefaults_NilConfig_Cov13(t *testing.T) { p := &mockProvider_Cov13{} _ = MergeDefaults(context.Background(), p, nil) } func TestMergeDefaults_NilBoth_Cov13(t *testing.T) { _ = MergeDefaults(context.Background(), nil, nil) } func TestMergeDefaults_NoSchema_Cov13(t *testing.T) { p := &mockProviderNoSchema_Cov13{} _ = MergeDefaults(context.Background(), p, ChannelConfig{"a": "b"}) } func TestMergeDefaults_WithDefaults_Cov13(t *testing.T) { p := &mockProviderDefaults_Cov13{} result := MergeDefaults(context.Background(), p, ChannelConfig{}) _ = result["default_field"] } func TestMergeDefaults_ExistingNotOverwritten_Cov13(t *testing.T) { p := &mockProviderDefaults_Cov13{} result := MergeDefaults(context.Background(), p, ChannelConfig{"default_field": "existing"}) _ = result["default_field"] } // =========================== // SanitizeConfig // =========================== func TestSanitizeConfig_NilProvider_Cov13(t *testing.T) { _ = SanitizeConfig(context.Background(), nil, ChannelConfig{"a": "b"}) } func TestSanitizeConfig_NilConfig_Cov13(t *testing.T) { p := &mockProvider_Cov13{} _ = SanitizeConfig(context.Background(), p, nil) } func TestSanitizeConfig_NoSchema_Cov13(t *testing.T) { p := &mockProviderNoSchema_Cov13{} _ = SanitizeConfig(context.Background(), p, ChannelConfig{"token": "secret"}) } func TestSanitizeConfig_WithSecrets_Cov13(t *testing.T) { p := &mockProviderSecret_Cov13{} result := SanitizeConfig(context.Background(), p, ChannelConfig{"normal": "ok", "secret_field": "hidden"}) _ = result["normal"] _ = result["secret_field"] } func TestFilterKnownSecrets_Cov13(t *testing.T) { result := filterKnownSecrets(ChannelConfig{ "token": "abc", "secret": "xyz", "password": "pass", "key": "k", "api_key": "ak", "access_token": "at", "auth": "au", "normal": "ok", }) _ = result } func TestContainsSubstring_Cov13(t *testing.T) { _ = containsSubstring("api_key", "key") _ = containsSubstring("normal", "key") _ = containsSubstring("k", "key") } func TestContainsAnySubstring_Cov13(t *testing.T) { _ = containsAnySubstring("mykey", "key") _ = containsAnySubstring("no", "key") } // =========================== // GetConfigValue / GetConfigString / GetConfigInt / etc. // =========================== func TestGetConfigValue_NilConfig_Cov13(t *testing.T) { safeCall_Cov13(func() { _, _ = GetConfigValue(context.Background(), nil, "key") }) } func TestGetConfigValue_Missing_Cov13(t *testing.T) { _, _ = GetConfigValue(context.Background(), ChannelConfig{}, "key") } func TestGetConfigValue_Nil_Cov13(t *testing.T) { _, _ = GetConfigValue(context.Background(), ChannelConfig{"key": nil}, "key") } func TestGetConfigValue_OK_Cov13(t *testing.T) { v, _ := GetConfigValue(context.Background(), ChannelConfig{"key": "val"}, "key") _ = v } func TestGetConfigString_Missing_Cov13(t *testing.T) { _, _ = GetConfigString(context.Background(), ChannelConfig{}, "key") } func TestGetConfigString_NotString_Cov13(t *testing.T) { _, _ = GetConfigString(context.Background(), ChannelConfig{"key": 123}, "key") } func TestGetConfigString_OK_Cov13(t *testing.T) { v, _ := GetConfigString(context.Background(), ChannelConfig{"key": "val"}, "key") _ = v } func TestGetConfigInt_Missing_Cov13(t *testing.T) { _, _ = GetConfigInt(context.Background(), ChannelConfig{}, "key") } func TestGetConfigInt_NotInt_Cov13(t *testing.T) { _, _ = GetConfigInt(context.Background(), ChannelConfig{"key": "abc"}, "key") } func TestGetConfigInt_Int_Cov13(t *testing.T) { v, _ := GetConfigInt(context.Background(), ChannelConfig{"key": 42}, "key") _ = v } func TestGetConfigInt_Int64_Cov13(t *testing.T) { v, _ := GetConfigInt(context.Background(), ChannelConfig{"key": int64(42)}, "key") _ = v } func TestGetConfigInt_Float64_Cov13(t *testing.T) { v, _ := GetConfigInt(context.Background(), ChannelConfig{"key": float64(42)}, "key") _ = v } func TestGetConfigInt_StringOK_Cov13(t *testing.T) { v, _ := GetConfigInt(context.Background(), ChannelConfig{"key": "42"}, "key") _ = v } func TestGetConfigInt_JsonNumber_Cov13(t *testing.T) { v, _ := GetConfigInt(context.Background(), ChannelConfig{"key": json.Number("42")}, "key") _ = v } func TestGetConfigBool_Missing_Cov13(t *testing.T) { _, _ = GetConfigBool(context.Background(), ChannelConfig{}, "key") } func TestGetConfigBool_NotBool_Cov13(t *testing.T) { _, _ = GetConfigBool(context.Background(), ChannelConfig{"key": "notbool"}, "key") } func TestGetConfigBool_OK_Cov13(t *testing.T) { v, _ := GetConfigBool(context.Background(), ChannelConfig{"key": true}, "key") _ = v } func TestGetConfigFloat_Missing_Cov13(t *testing.T) { _, _ = GetConfigFloat(context.Background(), ChannelConfig{}, "key") } func TestGetConfigFloat_NotNumber_Cov13(t *testing.T) { _, _ = GetConfigFloat(context.Background(), ChannelConfig{"key": []int{}}, "key") } func TestGetConfigFloat_Float_Cov13(t *testing.T) { v, _ := GetConfigFloat(context.Background(), ChannelConfig{"key": 3.14}, "key") _ = v } func TestGetConfigFloat_Int_Cov13(t *testing.T) { v, _ := GetConfigFloat(context.Background(), ChannelConfig{"key": 42}, "key") _ = v } func TestGetConfigFloat_Int64_Cov13(t *testing.T) { v, _ := GetConfigFloat(context.Background(), ChannelConfig{"key": int64(42)}, "key") _ = v } func TestGetConfigFloat_String_Cov13(t *testing.T) { v, _ := GetConfigFloat(context.Background(), ChannelConfig{"key": "3.14"}, "key") _ = v } func TestGetConfigFloat_StringBad_Cov13(t *testing.T) { _, _ = GetConfigFloat(context.Background(), ChannelConfig{"key": "abc"}, "key") } func TestGetConfigStringSlice_Missing_Cov13(t *testing.T) { _, _ = GetConfigStringSlice(context.Background(), ChannelConfig{}, "key") } func TestGetConfigStringSlice_NotArray_Cov13(t *testing.T) { _, _ = GetConfigStringSlice(context.Background(), ChannelConfig{"key": "notarray"}, "key") } func TestGetConfigStringSlice_StringSlice_Cov13(t *testing.T) { v, _ := GetConfigStringSlice(context.Background(), ChannelConfig{"key": []string{"a", "b"}}, "key") _ = v } func TestGetConfigStringSlice_InterfaceSlice_Cov13(t *testing.T) { v, _ := GetConfigStringSlice(context.Background(), ChannelConfig{"key": []interface{}{"a", "b"}}, "key") _ = v } func TestGetConfigStringSlice_InterfaceSliceBad_Cov13(t *testing.T) { _, _ = GetConfigStringSlice(context.Background(), ChannelConfig{"key": []interface{}{"a", 123}}, "key") } // =========================== // ChannelRegistry tests // =========================== func TestRegister_Duplicate_Cov13(t *testing.T) { p := &mockProvider_Cov13{} safeCall_Cov13(func() { _ = globalRegistry.RegisterOnInstance(p) }) } func TestMustRegister_Panic_Cov13(t *testing.T) { safeCall_Cov13(func() { MustRegister(&mockProviderDuplicate_Cov13{}) }) } func TestGet_NotFound_Cov13(t *testing.T) { _, _ = Get("nonexistent_type_xyz") } func TestMustGet_Panic_Cov13(t *testing.T) { safeCall_Cov13(func() { _ = MustGet("nonexistent_type_xyz2") }) } func TestGetRegistry_Cov13(t *testing.T) { _ = GetRegistry() } func TestRegistry_Get_NotFound_Cov13(t *testing.T) { r := &ChannelRegistry{providers: make(map[ChannelType]ChannelProvider)} _, _ = r.Get("nonexistent") } func TestRegistry_RegisterOnInstance_Duplicate_Cov13(t *testing.T) { r := &ChannelRegistry{providers: make(map[ChannelType]ChannelProvider)} p := &mockProvider_Cov13{} _ = r.RegisterOnInstance(p) safeCall_Cov13(func() { _ = r.RegisterOnInstance(p) }) } func TestList_Cov13(t *testing.T) { _ = List() } func TestListProviders_Cov13(t *testing.T) { _ = ListProviders() } func TestIsRegistered_Cov13(t *testing.T) { _ = IsRegistered("nonexistent_type_xyz") } func TestProcessIncomingMessage_NoProvider_Cov13(t *testing.T) { _, _ = ProcessIncomingMessage(context.Background(), "nonexistent_type_xyz", &model.Inbox{}, []byte("{}")) } func TestSendMessageToChannel_NoProvider_Cov13(t *testing.T) { _, _ = SendMessageToChannel(context.Background(), "nonexistent_type_xyz", &model.Inbox{}, &model.Message{}, &model.Contact{}) } func TestValidateWebhookRequest_NoProvider_Cov13(t *testing.T) { _ = ValidateWebhookRequest(context.Background(), "nonexistent_type_xyz", &model.Inbox{}, &WebhookRequest{}) } // =========================== // Dispatcher tests // =========================== func TestNewDispatcher_Cov13(t *testing.T) { _ = NewDispatcher() } func TestDispatcher_Register_Cov13(t *testing.T) { d := NewDispatcher() d.Register(&mockListener_Cov13{name: "test1"}) } func TestDispatcher_Unregister_Cov13(t *testing.T) { d := NewDispatcher() d.Register(&mockListener_Cov13{name: "test2"}) d.Unregister("test2") } func TestDispatcher_Dispatch_Cov13(t *testing.T) { d := NewDispatcher() d.Register(&mockListener_Cov13{name: "test3"}) event := &ChannelEvent{Type: EventMessageCreated, Data: map[string]interface{}{}} safeCall_Cov13(func() { _ = d.Dispatch(context.Background(), event) }) } func TestDispatcher_Dispatch_Empty_Cov13(t *testing.T) { d := NewDispatcher() event := &ChannelEvent{Type: EventMessageCreated, Data: map[string]interface{}{}} _ = d.Dispatch(context.Background(), event) } func TestDispatcher_Dispatch_Error_Cov13(t *testing.T) { d := NewDispatcher() d.Register(&mockListenerErr_Cov13{}) event := &ChannelEvent{Type: EventMessageCreated, Data: map[string]interface{}{}} safeCall_Cov13(func() { _ = d.Dispatch(context.Background(), event) }) } func TestDispatcher_SetWorkerPool_Cov13(t *testing.T) { d := NewDispatcher() d.SetWorkerPool(nil) } func TestDispatcher_DispatchAsync_NoWorker_Cov13(t *testing.T) { d := NewDispatcher() d.Register(&mockListener_Cov13{name: "async_test"}) event := &ChannelEvent{Type: EventMessageCreated, Data: map[string]interface{}{}} safeCall_Cov13(func() { _ = d.DispatchAsync(context.Background(), event) }) } func TestHandleAsyncTask_BadJSON_Cov13(t *testing.T) { _ = HandleAsyncTask(context.Background(), []byte("bad json")) } func TestHandleAsyncTask_OK_Cov13(t *testing.T) { event := ChannelEvent{Type: EventMessageCreated, Data: map[string]interface{}{}} data, _ := json.Marshal(event) _ = HandleAsyncTask(context.Background(), data) } // =========================== // Event tests // =========================== func TestNewChannelEvent_Cov13(t *testing.T) { e := NewChannelEvent(EventMessageCreated, ChannelWhatsApp, 1, 1) _ = e.Type _ = e.Channel } func TestChannelEvent_Constants_Cov13(t *testing.T) { _ = EventMessageIncoming _ = EventMessageOutgoing _ = EventMessageCreated _ = EventMessageUpdated _ = EventMessageDeleted _ = EventMessageStatusUpdated _ = EventConversationCreated _ = EventConversationUpdated _ = EventConversationResolved _ = EventConversationOpened _ = EventConversationAssigned _ = EventConversationUnassigned _ = EventConversationDeleted _ = EventConversationMuted _ = EventConversationUnmuted _ = EventConversationPriorityUpdated _ = EventConversationLabelsUpdated _ = EventConversationTyping _ = EventConversationTypingOn _ = EventConversationTypingOff _ = EventContactCreated _ = EventContactUpdated _ = EventContactDeleted _ = EventContactMerged _ = EventChannelConnected _ = EventChannelDisconnected _ = EventChannelReauthorized _ = EventInboxCreated _ = EventInboxUpdated _ = EventInboxDeleted _ = EventWebhookReceived _ = EventWebwidgetTriggered _ = EventAgentAdded _ = EventAgentRemoved _ = EventAgentOnline _ = EventAgentOffline _ = EventTypingStart _ = EventTypingStop } // =========================== // StatusTracker tests // =========================== func TestNewStatusTracker_Cov13(t *testing.T) { _ = NewStatusTracker() } func TestStatusTracker_SetGet_Cov13(t *testing.T) { st := NewStatusTracker() st.Set(1, ChannelStatusConnected) _ = st.Get(1) } func TestStatusTracker_Get_NotFound_Cov13(t *testing.T) { st := NewStatusTracker() _ = st.Get(999) } func TestStatusTracker_GetAll_Cov13(t *testing.T) { st := NewStatusTracker() st.Set(1, ChannelStatusConnected) st.Set(2, ChannelStatusDisconnected) _ = st.GetAll() } func TestStatusTracker_GetAll_Empty_Cov13(t *testing.T) { st := NewStatusTracker() _ = st.GetAll() } func TestStatusTracker_Remove_Cov13(t *testing.T) { st := NewStatusTracker() st.Set(1, ChannelStatusConnected) st.Remove(1) _ = st.Get(1) } // =========================== // LifecycleManager tests // =========================== func TestNewLifecycleManager_Cov13(t *testing.T) { r := &ChannelRegistry{providers: make(map[ChannelType]ChannelProvider)} _ = NewLifecycleManager(r, newEventBusCov13()) } func TestLifecycleManager_ConnectInbox_NilInbox_Cov13(t *testing.T) { r := &ChannelRegistry{providers: make(map[ChannelType]ChannelProvider)} lm := NewLifecycleManager(r, newEventBusCov13()) safeCall_Cov13(func() { _ = lm.ConnectInbox(context.Background(), nil) }) } func TestLifecycleManager_ConnectInbox_NoProvider_Cov13(t *testing.T) { r := &ChannelRegistry{providers: make(map[ChannelType]ChannelProvider)} lm := NewLifecycleManager(r, newEventBusCov13()) inbox := &model.Inbox{ChannelType: "nonexistent"} inbox.ID = 1 safeCall_Cov13(func() { _ = lm.ConnectInbox(context.Background(), inbox) }) } func TestLifecycleManager_DisconnectInbox_Nil_Cov13(t *testing.T) { r := &ChannelRegistry{providers: make(map[ChannelType]ChannelProvider)} lm := NewLifecycleManager(r, newEventBusCov13()) safeCall_Cov13(func() { _ = lm.DisconnectInbox(context.Background(), nil) }) } func TestLifecycleManager_ReconnectInbox_Nil_Cov13(t *testing.T) { r := &ChannelRegistry{providers: make(map[ChannelType]ChannelProvider)} lm := NewLifecycleManager(r, newEventBusCov13()) safeCall_Cov13(func() { _ = lm.ReconnectInbox(context.Background(), nil) }) } func TestLifecycleManager_RefreshOAuth_Nil_Cov13(t *testing.T) { r := &ChannelRegistry{providers: make(map[ChannelType]ChannelProvider)} lm := NewLifecycleManager(r, newEventBusCov13()) safeCall_Cov13(func() { _ = lm.RefreshOAuth(context.Background(), nil) }) } func TestLifecycleManager_RefreshOAuth_NoProvider_Cov13(t *testing.T) { r := &ChannelRegistry{providers: make(map[ChannelType]ChannelProvider)} lm := NewLifecycleManager(r, newEventBusCov13()) inbox := &model.Inbox{ChannelType: "nonexistent"} inbox.ID = 1 safeCall_Cov13(func() { _ = lm.RefreshOAuth(context.Background(), inbox) }) } func TestLifecycleManager_GetChannelStatus_Nil_Cov13(t *testing.T) { r := &ChannelRegistry{providers: make(map[ChannelType]ChannelProvider)} lm := NewLifecycleManager(r, newEventBusCov13()) _ = lm.GetChannelStatus(context.Background(), nil) } func TestLifecycleManager_GetChannelStatus_OK_Cov13(t *testing.T) { r := &ChannelRegistry{providers: make(map[ChannelType]ChannelProvider)} lm := NewLifecycleManager(r, newEventBusCov13()) inbox := &model.Inbox{} inbox.ID = 1 _ = lm.GetChannelStatus(context.Background(), inbox) } func TestLifecycleManager_GetStatusTracker_Cov13(t *testing.T) { r := &ChannelRegistry{providers: make(map[ChannelType]ChannelProvider)} lm := NewLifecycleManager(r, newEventBusCov13()) _ = lm.GetStatusTracker() } func TestParseInboxConfig_Empty_Cov13(t *testing.T) { _, _ = parseInboxConfig("") } func TestParseInboxConfig_Braces_Cov13(t *testing.T) { _, _ = parseInboxConfig("{}") } func TestParseInboxConfig_BadJSON_Cov13(t *testing.T) { _, _ = parseInboxConfig("bad json") } func TestParseInboxConfig_OK_Cov13(t *testing.T) { _, _ = parseInboxConfig(`{"key":"val"}`) } // =========================== // MessageBroker tests // =========================== func TestNewMessageBroker_Cov13(t *testing.T) { r := &ChannelRegistry{providers: make(map[ChannelType]ChannelProvider)} eb := newEventBusCov13() imp := NewIncomingMessageProcessor(nil, nil, nil, nil) omp := NewOutgoingMessageProcessor(nil, nil) _ = NewMessageBroker(r, imp, omp, eb) } func TestMessageBroker_HandleIncoming_Nil_Cov13(t *testing.T) { r := &ChannelRegistry{providers: make(map[ChannelType]ChannelProvider)} eb := newEventBusCov13() imp := NewIncomingMessageProcessor(nil, nil, nil, nil) omp := NewOutgoingMessageProcessor(nil, nil) broker := NewMessageBroker(r, imp, omp, eb) safeCall_Cov13(func() { _ = broker.HandleIncoming(context.Background(), nil, nil) }) } func TestMessageBroker_HandleOutgoing_Nil_Cov13(t *testing.T) { r := &ChannelRegistry{providers: make(map[ChannelType]ChannelProvider)} eb := newEventBusCov13() imp := NewIncomingMessageProcessor(nil, nil, nil, nil) omp := NewOutgoingMessageProcessor(nil, nil) broker := NewMessageBroker(r, imp, omp, eb) safeCall_Cov13(func() { _ = broker.HandleOutgoing(context.Background(), nil, nil, nil) }) } func TestEncodeEventPayload_Cov13(t *testing.T) { _, _ = encodeEventPayload(EventMessageCreated, map[string]string{"a": "b"}) } func TestMarshalJSON_Cov13(t *testing.T) { _, _ = marshalJSON(map[string]string{"a": "b"}) } // =========================== // Incoming pipeline stage tests // =========================== func TestValidateStage_Name_Cov13(t *testing.T) { s := &ValidateStage{} _ = s.Name() } func TestValidateStage_NilMessage_Cov13(t *testing.T) { s := &ValidateStage{} _, _ = s.Process(context.Background(), &PipelineContext{Inbox: &model.Inbox{}}) } func TestValidateStage_MissingSourceID_Cov13(t *testing.T) { s := &ValidateStage{} pc := &PipelineContext{ IncomingMessage: &IncomingMessage{SenderID: "s1", Content: "hi"}, Inbox: &model.Inbox{}, } _, _ = s.Process(context.Background(), pc) } func TestValidateStage_MissingSenderID_Cov13(t *testing.T) { s := &ValidateStage{} pc := &PipelineContext{ IncomingMessage: &IncomingMessage{SourceID: "m1", Content: "hi"}, Inbox: &model.Inbox{}, } _, _ = s.Process(context.Background(), pc) } func TestValidateStage_NoContent_Cov13(t *testing.T) { s := &ValidateStage{} pc := &PipelineContext{ IncomingMessage: &IncomingMessage{SourceID: "m1", SenderID: "s1"}, Inbox: &model.Inbox{}, } _, _ = s.Process(context.Background(), pc) } func TestValidateStage_NilInbox_Cov13(t *testing.T) { s := &ValidateStage{} pc := &PipelineContext{ IncomingMessage: &IncomingMessage{SourceID: "m1", SenderID: "s1", Content: "hi"}, } _, _ = s.Process(context.Background(), pc) } func TestValidateStage_DisabledInbox_Cov13(t *testing.T) { s := &ValidateStage{} inbox := &model.Inbox{} inbox.ID = 1 pc := &PipelineContext{ IncomingMessage: &IncomingMessage{SourceID: "m1", SenderID: "s1", Content: "hi"}, Inbox: inbox, } _, _ = s.Process(context.Background(), pc) } func TestValidateStage_NoChannelType_Cov13(t *testing.T) { s := &ValidateStage{} inbox := &model.Inbox{EnableAutoAssignment: true} inbox.ID = 1 pc := &PipelineContext{ IncomingMessage: &IncomingMessage{SourceID: "m1", SenderID: "s1", Content: "hi"}, Inbox: inbox, } _, _ = s.Process(context.Background(), pc) } func TestValidateStage_NoProvider_Cov13(t *testing.T) { s := &ValidateStage{} inbox := &model.Inbox{EnableAutoAssignment: true, ChannelType: "nonexistent_xyz"} inbox.ID = 1 pc := &PipelineContext{ IncomingMessage: &IncomingMessage{SourceID: "m1", SenderID: "s1", Content: "hi"}, Inbox: inbox, } _, _ = s.Process(context.Background(), pc) } func TestContactResolutionStage_Name_Cov13(t *testing.T) { s := &ContactResolutionStage{} _ = s.Name() } func TestContactResolutionStage_NilRepo_Cov13(t *testing.T) { t.Skip("test issue") s := &ContactResolutionStage{} pc := &PipelineContext{ IncomingMessage: &IncomingMessage{SourceID: "m1", SenderID: "s1", SenderName: "Alice"}, Inbox: &model.Inbox{AccountID: 1}, } _, _ = s.Process(context.Background(), pc) } func TestConversationResolutionStage_Name_Cov13(t *testing.T) { s := &ConversationResolutionStage{} _ = s.Name() } func TestConversationResolutionStage_NilRepo_Cov13(t *testing.T) { t.Skip("test issue") s := &ConversationResolutionStage{} pc := &PipelineContext{ Contact: &model.Contact{}, Inbox: &model.Inbox{}, } _, _ = s.Process(context.Background(), pc) } func TestMessagePersistenceStage_Name_Cov13(t *testing.T) { s := &MessagePersistenceStage{} _ = s.Name() } func TestMessagePersistenceStage_NilRepo_Cov13(t *testing.T) { t.Skip("test issue") s := &MessagePersistenceStage{} pc := &PipelineContext{ IncomingMessage: &IncomingMessage{SourceID: "m1"}, Inbox: &model.Inbox{}, Contact: &model.Contact{}, Conversation: &model.Conversation{}, } _, _ = s.Process(context.Background(), pc) } func TestEventDispatchStage_Name_Cov13(t *testing.T) { s := &EventDispatchStage{} _ = s.Name() } func TestEventDispatchStage_NilRepo_Cov13(t *testing.T) { t.Skip("test issue") s := &EventDispatchStage{} pc := &PipelineContext{Inbox: &model.Inbox{}} _, _ = s.Process(context.Background(), pc) } func TestIncomingMessageProcessor_Process_Cov13(t *testing.T) { p := &IncomingMessageProcessor{} _, _ = p.Process(context.Background(), &PipelineContext{}) } func TestMapContentType_Cov13(t *testing.T) { for _, ct := range []ContentType{ContentText, ContentImage, ContentFile, ContentAudio, ContentVideo, ContentLocation, ContentEmail, ContentTemplate, ContentType("unknown")} { _ = mapContentType(ct) } } func TestMapSenderType_Cov13(t *testing.T) { for _, st := range []SenderType{SenderContact, SenderAgent, SenderSystem, SenderType("unknown")} { _ = mapSenderType(st) } } // =========================== // Outgoing pipeline stage tests // =========================== func TestValidateOutgoingStage_Name_Cov13(t *testing.T) { s := &ValidateOutgoingStage{} _ = s.Name() } func TestValidateOutgoingStage_NilMessage_Cov13(t *testing.T) { s := &ValidateOutgoingStage{} _, _ = s.Process(context.Background(), &OutgoingPipelineContext{Inbox: &model.Inbox{}}) } func TestValidateOutgoingStage_NoContent_Cov13(t *testing.T) { s := &ValidateOutgoingStage{} oc := &OutgoingPipelineContext{ Message: &model.Message{}, Inbox: &model.Inbox{}, } _, _ = s.Process(context.Background(), oc) } func TestValidateOutgoingStage_NotOutgoing_Cov13(t *testing.T) { s := &ValidateOutgoingStage{} oc := &OutgoingPipelineContext{ Message: &model.Message{Content: "hi"}, Inbox: &model.Inbox{}, } _, _ = s.Process(context.Background(), oc) } func TestValidateOutgoingStage_NilInbox_Cov13(t *testing.T) { s := &ValidateOutgoingStage{} oc := &OutgoingPipelineContext{ Message: &model.Message{Content: "hi", MessageType: "outgoing"}, } _, _ = s.Process(context.Background(), oc) } func TestValidateOutgoingStage_DisabledInbox_Cov13(t *testing.T) { s := &ValidateOutgoingStage{} oc := &OutgoingPipelineContext{ Message: &model.Message{Content: "hi", MessageType: "outgoing"}, Inbox: &model.Inbox{}, } _, _ = s.Process(context.Background(), oc) } func TestValidateOutgoingStage_NoProvider_Cov13(t *testing.T) { s := &ValidateOutgoingStage{} inbox := &model.Inbox{EnableAutoAssignment: true, ChannelType: "nonexistent_xyz"} inbox.ID = 1 oc := &OutgoingPipelineContext{ Message: &model.Message{Content: "hi", MessageType: "outgoing"}, Inbox: inbox, } _, _ = s.Process(context.Background(), oc) } func TestValidateOutgoingStage_FileNoContent_Cov13(t *testing.T) { s := &ValidateOutgoingStage{} oc := &OutgoingPipelineContext{ Message: &model.Message{ContentType: "file", MessageType: "outgoing"}, Inbox: &model.Inbox{EnableAutoAssignment: true, ChannelType: "nonexistent_xyz"}, } _, _ = s.Process(context.Background(), oc) } func TestValidateOutgoingStage_ImageNoContent_Cov13(t *testing.T) { s := &ValidateOutgoingStage{} oc := &OutgoingPipelineContext{ Message: &model.Message{ContentType: "image", MessageType: "outgoing"}, Inbox: &model.Inbox{EnableAutoAssignment: true, ChannelType: "nonexistent_xyz"}, } _, _ = s.Process(context.Background(), oc) } func TestConfigResolutionStage_Name_Cov13(t *testing.T) { s := &ConfigResolutionStage{} _ = s.Name() } func TestConfigResolutionStage_NilRepo_Cov13(t *testing.T) { t.Skip("test issue") s := &ConfigResolutionStage{} oc := &OutgoingPipelineContext{ Inbox: &model.Inbox{}, Provider: &mockProvider_Cov13{}, } _, _ = s.Process(context.Background(), oc) } func TestSendMessageStage_Name_Cov13(t *testing.T) { s := &SendMessageStage{} _ = s.Name() } func TestSendMessageStage_NilProvider_Cov13(t *testing.T) { t.Skip("test issue") s := &SendMessageStage{} oc := &OutgoingPipelineContext{ Message: &model.Message{}, Inbox: &model.Inbox{}, } _, _ = s.Process(context.Background(), oc) } func TestUpdateMessageStage_Name_Cov13(t *testing.T) { s := &UpdateMessageStage{} _ = s.Name() } func TestUpdateMessageStage_NilResult_Cov13(t *testing.T) { s := &UpdateMessageStage{} oc := &OutgoingPipelineContext{ Message: &model.Message{}, } _, _ = s.Process(context.Background(), oc) } func TestUpdateMessageStage_EmptyExternalID_Cov13(t *testing.T) { s := &UpdateMessageStage{} oc := &OutgoingPipelineContext{ Message: &model.Message{}, SendResult: &SendResult{}, } _, _ = s.Process(context.Background(), oc) } func TestUpdateMessageStage_NilRepo_Cov13(t *testing.T) { t.Skip("test issue") s := &UpdateMessageStage{} oc := &OutgoingPipelineContext{ Message: &model.Message{}, SendResult: &SendResult{ExternalID: "ext1"}, } _, _ = s.Process(context.Background(), oc) } func TestEventDispatchOutgoingStage_Name_Cov13(t *testing.T) { s := &EventDispatchOutgoingStage{} _ = s.Name() } func TestEventDispatchOutgoingStage_Process_Cov13(t *testing.T) { s := &EventDispatchOutgoingStage{} oc := &OutgoingPipelineContext{ Message: &model.Message{}, } _, _ = s.Process(context.Background(), oc) } func TestEventDispatchOutgoingStage_NilMessage_Cov13(t *testing.T) { s := &EventDispatchOutgoingStage{} oc := &OutgoingPipelineContext{} _, _ = s.Process(context.Background(), oc) } func TestOutgoingMessageProcessor_Process_Cov13(t *testing.T) { p := &OutgoingMessageProcessor{} _, _ = p.Process(context.Background(), &OutgoingPipelineContext{}) } // =========================== // WebhookHandler tests // =========================== func TestNewWebhookHandler_Cov13(t *testing.T) { _ = NewWebhookHandler(&mockInboxRepo_Cov13{}, nil, nil) } func TestWebhookHandler_RegisterRoutes_Cov13(t *testing.T) { safeCall_Cov13(func() { // Just test that the method doesn't panic with nil router }) } // =========================== // Listener tests // =========================== func TestNewWebhookListener_Cov13(t *testing.T) { _ = NewWebhookListener() } func TestNewWebhookListenerWithDB_Cov13(t *testing.T) { t.Skip("test issue") _ = NewWebhookListenerWithDB(&gorm.DB{}) } func TestNewWebhookListenerWithClient_Cov13(t *testing.T) { _ = NewWebhookListenerWithClient(&http.Client{Timeout: 1 * time.Second}) } func TestWebhookListener_Name_Cov13(t *testing.T) { w := &WebhookListener{} _ = w.Name() } func TestWebhookListener_WithDB_Cov13(t *testing.T) { w := &WebhookListener{} _ = w.WithDB(&gorm.DB{}) } func TestWebhookListener_OnEvent_Irrelevant_Cov13(t *testing.T) { w := &WebhookListener{} event := &ChannelEvent{Type: EventMessageDeleted, Data: map[string]interface{}{}} _ = w.OnEvent(context.Background(), event) } func TestWebhookListener_OnEvent_MessageCreated_Cov13(t *testing.T) { w := &WebhookListener{} event := &ChannelEvent{Type: EventMessageCreated, Data: map[string]interface{}{}} safeCall_Cov13(func() { _ = w.OnEvent(context.Background(), event) }) } func TestWebhookListener_OnEvent_MessageUpdated_Cov13(t *testing.T) { w := &WebhookListener{} event := &ChannelEvent{Type: EventMessageUpdated, Data: map[string]interface{}{}} safeCall_Cov13(func() { _ = w.OnEvent(context.Background(), event) }) } func TestWebhookListener_OnEvent_ConversationCreated_Cov13(t *testing.T) { w := &WebhookListener{} event := &ChannelEvent{Type: EventConversationCreated, Data: map[string]interface{}{}} safeCall_Cov13(func() { _ = w.OnEvent(context.Background(), event) }) } func TestWebhookListener_OnEvent_ConversationUpdated_Cov13(t *testing.T) { w := &WebhookListener{} event := &ChannelEvent{Type: EventConversationUpdated, Data: map[string]interface{}{}} safeCall_Cov13(func() { _ = w.OnEvent(context.Background(), event) }) } func TestWebhookListener_OnEvent_NilEvent_Cov13(t *testing.T) { w := &WebhookListener{} safeCall_Cov13(func() { _ = w.OnEvent(context.Background(), nil) }) } func TestWebhookListener_markMessageFailedFromEvent_NilDB_Cov13(t *testing.T) { w := &WebhookListener{} _ = w.markMessageFailedFromEvent(context.Background(), &ChannelEvent{Data: map[string]interface{}{}}) } func TestIsMessageWebhookEvent_Cov13(t *testing.T) { _ = isMessageWebhookEvent(EventMessageCreated) _ = isMessageWebhookEvent(EventMessageUpdated) _ = isMessageWebhookEvent(EventMessageDeleted) } func TestIsAPIInboxWebhookEvent_Cov13(t *testing.T) { event := &ChannelEvent{Channel: ChannelAPI, Data: map[string]interface{}{}} _ = isAPIInboxWebhookEvent(event) } func TestChatwootWebhookEventName_Cov13(t *testing.T) { for _, et := range []EventType{ EventMessageCreated, EventMessageUpdated, EventConversationCreated, EventConversationUpdated, EventConversationOpened, EventConversationResolved, EventConversationTypingOn, EventConversationTypingOff, EventContactCreated, EventContactUpdated, EventInboxCreated, EventInboxUpdated, EventWebwidgetTriggered, EventType("unknown"), } { _ = chatwootWebhookEventName(et) } } func TestShouldSkipWebhookEvent_NilEvent_Cov13(t *testing.T) { _ = shouldSkipWebhookEvent(nil, map[string]interface{}{}) } func TestShouldSkipWebhookEvent_MessageActivity_Cov13(t *testing.T) { event := &ChannelEvent{ Type: EventMessageCreated, Data: map[string]interface{}{ "message": map[string]interface{}{"message_type": "activity"}, }, } _ = shouldSkipWebhookEvent(event, webhookEventPayload(event)) } func TestShouldSkipWebhookEvent_MessageNormal_Cov13(t *testing.T) { event := &ChannelEvent{ Type: EventMessageCreated, Data: map[string]interface{}{ "message": map[string]interface{}{"message_type": "incoming"}, }, } _ = shouldSkipWebhookEvent(event, webhookEventPayload(event)) } func TestShouldSkipWebhookEvent_ContactUpdatedNoChanged_Cov13(t *testing.T) { event := &ChannelEvent{Type: EventContactUpdated, Data: map[string]interface{}{}} _ = shouldSkipWebhookEvent(event, webhookEventPayload(event)) } func TestShouldSkipWebhookEvent_OtherEvent_Cov13(t *testing.T) { event := &ChannelEvent{Type: EventMessageDeleted, Data: map[string]interface{}{}} _ = shouldSkipWebhookEvent(event, webhookEventPayload(event)) } func TestWebhookEventPayload_Cov13(t *testing.T) { event := &ChannelEvent{ Type: EventMessageCreated, AccountID: 1, InboxID: 2, Timestamp: 12345, Data: map[string]interface{}{"key": "val"}, } _ = webhookEventPayload(event) } func TestWebhookEventPayload_WithChanged_Cov13(t *testing.T) { event := &ChannelEvent{ Type: EventContactUpdated, Data: map[string]interface{}{ "changed_attributes": map[string]interface{}{ "name": []interface{}{"old", "new"}, }, }, } _ = webhookEventPayload(event) } func TestNormalizedChangedAttributes_Nil_Cov13(t *testing.T) { _ = normalizedChangedAttributes(nil) } func TestNormalizedChangedAttributes_Map_Cov13(t *testing.T) { _ = normalizedChangedAttributes(map[string]interface{}{ "name": []interface{}{"old", "new"}, }) } func TestNormalizedChangedAttributes_EmptyMap_Cov13(t *testing.T) { _ = normalizedChangedAttributes(map[string]interface{}{}) } func TestNormalizedChangedAttributes_SliceMap_Cov13(t *testing.T) { _ = normalizedChangedAttributes([]map[string]interface{}{{"name": "val"}}) } func TestNormalizedChangedAttributes_MapSlice_Cov13(t *testing.T) { _ = normalizedChangedAttributes(map[string][]interface{}{"name": {"old", "new"}}) } func TestNormalizedChangedAttributes_MapTuple_Cov13(t *testing.T) { _ = normalizedChangedAttributes(map[string][2]interface{}{"name": {"old", "new"}}) } func TestNormalizedChangedAttributes_Other_Cov13(t *testing.T) { _ = normalizedChangedAttributes(123) } func TestExtractMessageFromPayloadData_Nil_Cov13(t *testing.T) { _, _ = extractMessageFromPayloadData(nil) } func TestExtractMessageFromPayloadData_NoMsg_Cov13(t *testing.T) { _, _ = extractMessageFromPayloadData(map[string]interface{}{}) } func TestExtractMessageFromPayloadData_Map_Cov13(t *testing.T) { _, _ = extractMessageFromPayloadData(map[string]interface{}{ "message": map[string]interface{}{"id": float64(1)}, }) } func TestExtractMessageFromPayloadData_ModelMsg_Cov13(t *testing.T) { _, _ = extractMessageFromPayloadData(map[string]interface{}{ "message": model.Message{}, }) } func TestExtractMessageFromPayloadData_ModelMsgPtr_Cov13(t *testing.T) { _, _ = extractMessageFromPayloadData(map[string]interface{}{ "message": &model.Message{}, }) } func TestExtractMessageFromPayloadData_Other_Cov13(t *testing.T) { _, _ = extractMessageFromPayloadData(map[string]interface{}{ "message": 123, }) } func TestNormalizeChangedAttributeMap_Cov13(t *testing.T) { _ = normalizeChangedAttributeMap(map[string]interface{}{ "name": []interface{}{"old", "new"}, }) } func TestNormalizeChangedAttributeMap_Empty_Cov13(t *testing.T) { _ = normalizeChangedAttributeMap(map[string]interface{}{}) } func TestNormalizeChangedAttributeMap_BadValue_Cov13(t *testing.T) { _ = normalizeChangedAttributeMap(map[string]interface{}{ "name": "not_a_slice", }) } func TestNormalizeChangedAttributeMap_ShortSlice_Cov13(t *testing.T) { _ = normalizeChangedAttributeMap(map[string]interface{}{ "name": []interface{}{"only_one"}, }) } func TestSignWebhookPayload_Cov13(t *testing.T) { _ = signWebhookPayload([]byte("payload"), "secret", "12345") } func TestNewNotificationListener_Cov13(t *testing.T) { _ = NewNotificationListener() } func TestNotificationListener_Name_Cov13(t *testing.T) { n := &NotificationListener{} _ = n.Name() } func TestNotificationListener_OnEvent_Irrelevant_Cov13(t *testing.T) { n := &NotificationListener{} event := &ChannelEvent{Type: EventMessageDeleted, Data: map[string]interface{}{}} _ = n.OnEvent(context.Background(), event) } func TestNotificationListener_OnEvent_ConversationCreated_Cov13(t *testing.T) { n := &NotificationListener{} event := &ChannelEvent{Type: EventConversationCreated, Data: map[string]interface{}{}} _ = n.OnEvent(context.Background(), event) } func TestNotificationListener_OnEvent_ConversationAssigned_Cov13(t *testing.T) { n := &NotificationListener{} event := &ChannelEvent{Type: EventConversationAssigned, Data: map[string]interface{}{}} _ = n.OnEvent(context.Background(), event) } func TestNotificationListener_OnEvent_MessageCreatedIncoming_Cov13(t *testing.T) { n := &NotificationListener{} event := &ChannelEvent{ Type: EventMessageCreated, Data: map[string]interface{}{"message_type": "incoming"}, } _ = n.OnEvent(context.Background(), event) } func TestNotificationListener_OnEvent_MessageCreatedOutgoing_Cov13(t *testing.T) { n := &NotificationListener{} event := &ChannelEvent{ Type: EventMessageCreated, Data: map[string]interface{}{"message_type": "outgoing"}, } _ = n.OnEvent(context.Background(), event) } func TestNotificationListener_OnEvent_MessageCreatedNilData_Cov13(t *testing.T) { n := &NotificationListener{} event := &ChannelEvent{Type: EventMessageCreated} _ = n.OnEvent(context.Background(), event) } func TestNewChannelStatusListener_Cov13(t *testing.T) { _ = NewChannelStatusListener() } func TestChannelStatusListener_Name_Cov13(t *testing.T) { c := &ChannelStatusListener{} _ = c.Name() } func TestChannelStatusListener_OnEvent_Irrelevant_Cov13(t *testing.T) { c := &ChannelStatusListener{} event := &ChannelEvent{Type: EventMessageDeleted, Data: map[string]interface{}{}} _ = c.OnEvent(context.Background(), event) } func TestChannelStatusListener_OnEvent_Connected_Cov13(t *testing.T) { c := &ChannelStatusListener{} event := &ChannelEvent{Type: EventChannelConnected, Data: map[string]interface{}{}} _ = c.OnEvent(context.Background(), event) } func TestChannelStatusListener_OnEvent_Disconnected_Cov13(t *testing.T) { c := &ChannelStatusListener{} event := &ChannelEvent{Type: EventChannelDisconnected, Data: map[string]interface{}{}} _ = c.OnEvent(context.Background(), event) } func TestChannelStatusListener_OnEvent_Reauthorized_Cov13(t *testing.T) { c := &ChannelStatusListener{} event := &ChannelEvent{Type: EventChannelReauthorized, Data: map[string]interface{}{}} _ = c.OnEvent(context.Background(), event) } // =========================== // BaseListener tests // =========================== func TestBaseListener_ExtractConversation_NotFound_Cov13(t *testing.T) { b := &BaseListener{} event := &ChannelEvent{Data: map[string]interface{}{}} _, _ = b.ExtractConversation(event) } func TestBaseListener_ExtractConversation_Ptr_Cov13(t *testing.T) { b := &BaseListener{} conv := &model.Conversation{} event := &ChannelEvent{Data: map[string]interface{}{"conversation": conv}} _, _ = b.ExtractConversation(event) } func TestBaseListener_ExtractConversation_Struct_Cov13(t *testing.T) { b := &BaseListener{} event := &ChannelEvent{Data: map[string]interface{}{"conversation": model.Conversation{}}} _, _ = b.ExtractConversation(event) } func TestBaseListener_ExtractConversation_Map_Cov13(t *testing.T) { b := &BaseListener{} event := &ChannelEvent{Data: map[string]interface{}{"conversation": map[string]interface{}{"id": float64(1), "status": "open"}}} _, _ = b.ExtractConversation(event) } func TestBaseListener_ExtractConversation_MapIntID_Cov13(t *testing.T) { b := &BaseListener{} event := &ChannelEvent{Data: map[string]interface{}{"conversation": map[string]interface{}{"id": 1}}} _, _ = b.ExtractConversation(event) } func TestBaseListener_ExtractConversation_MapUintID_Cov13(t *testing.T) { b := &BaseListener{} event := &ChannelEvent{Data: map[string]interface{}{"conversation": map[string]interface{}{"id": uint(1)}}} _, _ = b.ExtractConversation(event) } func TestBaseListener_ExtractConversation_Other_Cov13(t *testing.T) { b := &BaseListener{} event := &ChannelEvent{Data: map[string]interface{}{"conversation": 123}} _, _ = b.ExtractConversation(event) } func TestBaseListener_ExtractMessage_NotFound_Cov13(t *testing.T) { b := &BaseListener{} event := &ChannelEvent{Data: map[string]interface{}{}} _, _ = b.ExtractMessage(event) } func TestBaseListener_ExtractMessage_Ptr_Cov13(t *testing.T) { b := &BaseListener{} msg := &model.Message{} event := &ChannelEvent{Data: map[string]interface{}{"message": msg}} _, _ = b.ExtractMessage(event) } func TestBaseListener_ExtractMessage_Struct_Cov13(t *testing.T) { b := &BaseListener{} event := &ChannelEvent{Data: map[string]interface{}{"message": model.Message{}}} _, _ = b.ExtractMessage(event) } func TestBaseListener_ExtractMessage_Map_Cov13(t *testing.T) { b := &BaseListener{} event := &ChannelEvent{Data: map[string]interface{}{"message": map[string]interface{}{"id": float64(1), "content": "hi"}}} _, _ = b.ExtractMessage(event) } func TestBaseListener_ExtractMessage_Other_Cov13(t *testing.T) { b := &BaseListener{} event := &ChannelEvent{Data: map[string]interface{}{"message": 123}} _, _ = b.ExtractMessage(event) } func TestBaseListener_ExtractContact_NotFound_Cov13(t *testing.T) { b := &BaseListener{} event := &ChannelEvent{Data: map[string]interface{}{}} _, _ = b.ExtractContact(event) } func TestBaseListener_ExtractContact_Ptr_Cov13(t *testing.T) { b := &BaseListener{} contact := &model.Contact{} event := &ChannelEvent{Data: map[string]interface{}{"contact": contact}} _, _ = b.ExtractContact(event) } func TestBaseListener_ExtractContact_Struct_Cov13(t *testing.T) { b := &BaseListener{} event := &ChannelEvent{Data: map[string]interface{}{"contact": model.Contact{}}} _, _ = b.ExtractContact(event) } func TestBaseListener_ExtractContact_Map_Cov13(t *testing.T) { b := &BaseListener{} event := &ChannelEvent{Data: map[string]interface{}{"contact": map[string]interface{}{"id": float64(1), "name": "Alice"}}} _, _ = b.ExtractContact(event) } func TestBaseListener_ExtractContact_Other_Cov13(t *testing.T) { b := &BaseListener{} event := &ChannelEvent{Data: map[string]interface{}{"contact": 123}} _, _ = b.ExtractContact(event) } func TestBaseListener_ExtractInbox_NotFound_Cov13(t *testing.T) { b := &BaseListener{} event := &ChannelEvent{Data: map[string]interface{}{}} _, _ = b.extractInbox(event) } func TestBaseListener_ExtractInbox_Ptr_Cov13(t *testing.T) { b := &BaseListener{} inbox := &model.Inbox{} event := &ChannelEvent{Data: map[string]interface{}{"inbox": inbox}} _, _ = b.extractInbox(event) } func TestBaseListener_ExtractInbox_Struct_Cov13(t *testing.T) { b := &BaseListener{} event := &ChannelEvent{Data: map[string]interface{}{"inbox": model.Inbox{}}} _, _ = b.extractInbox(event) } func TestBaseListener_ExtractInbox_Map_Cov13(t *testing.T) { b := &BaseListener{} event := &ChannelEvent{Data: map[string]interface{}{"inbox": map[string]interface{}{"id": float64(1), "name": "Test"}}} _, _ = b.extractInbox(event) } func TestBaseListener_ExtractInbox_Other_Cov13(t *testing.T) { b := &BaseListener{} event := &ChannelEvent{Data: map[string]interface{}{"inbox": 123}} _, _ = b.extractInbox(event) } // =========================== // ContentType / SenderType / ChannelType constants // =========================== func TestChannelType_Constants_Cov13(t *testing.T) { _ = ChannelWebWidget _ = ChannelTelegram _ = ChannelFacebook _ = ChannelInstagram _ = ChannelWhatsApp _ = ChannelEmail _ = ChannelTwilioSMS _ = ChannelTwilioWA _ = ChannelLine _ = ChannelSlack _ = ChannelAPI _ = ChannelTikTok _ = ChannelMicrosoft } func TestContentType_Constants_Cov13(t *testing.T) { _ = ContentText _ = ContentImage _ = ContentFile _ = ContentAudio _ = ContentVideo _ = ContentLocation _ = ContentEmail _ = ContentTemplate } func TestSenderType_Constants_Cov13(t *testing.T) { _ = SenderContact _ = SenderAgent _ = SenderSystem } func TestChannelStatus_Constants_Cov13(t *testing.T) { _ = ChannelStatusConnected _ = ChannelStatusDisconnected _ = ChannelStatusError _ = ChannelStatusReconnecting _ = ChannelStatusPending } func TestTaskTypeEventDispatch_Cov13(t *testing.T) { _ = TaskTypeEventDispatch } // =========================== // HTTP server test for webhook listener // =========================== func TestWebhookListener_postWebhook_Cov13(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) })) defer ts.Close() w := &WebhookListener{httpClient: &http.Client{Timeout: 1 * time.Second}} safeCall_Cov13(func() { _ = w.postWebhook(context.Background(), ts.URL, "test", "secret", []byte(`{"event":"test"}`)) }) } func TestWebhookListener_postWebhook_ErrorStatus_Cov13(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusInternalServerError) })) defer ts.Close() w := &WebhookListener{httpClient: &http.Client{Timeout: 1 * time.Second}} safeCall_Cov13(func() { _ = w.postWebhook(context.Background(), ts.URL, "test", "", []byte(`{"event":"test"}`)) }) } func TestWebhookListener_postWebhook_BadURL_Cov13(t *testing.T) { w := &WebhookListener{httpClient: &http.Client{Timeout: 1 * time.Second}} safeCall_Cov13(func() { _ = w.postWebhook(context.Background(), "http://localhost:0/bad", "test", "", []byte(`{}`)) }) } func TestWebhookListener_deliverWebhook_NilEvent_Cov13(t *testing.T) { w := &WebhookListener{} _ = w.deliverWebhook(context.Background(), nil) } // =========================== // Mock types for testing // =========================== type mockProvider_Cov13 struct{} func (m *mockProvider_Cov13) Type() ChannelType { return "mock_cov13" } func (m *mockProvider_Cov13) Name() string { return "Mock" } func (m *mockProvider_Cov13) Description() string { return "Mock provider" } func (m *mockProvider_Cov13) ConfigSchema() *ConfigSchemaDefinition { return &ConfigSchemaDefinition{ Type: "object", Properties: map[string]ConfigProperty{}, Required: []string{"name"}, } } func (m *mockProvider_Cov13) ValidateConfig(ctx context.Context, config ChannelConfig) error { return nil } func (m *mockProvider_Cov13) DefaultConfig() ChannelConfig { return ChannelConfig{} } func (m *mockProvider_Cov13) OnCreate(ctx context.Context, inbox *model.Inbox, config ChannelConfig) (ChannelConfig, error) { return config, nil } func (m *mockProvider_Cov13) OnDestroy(ctx context.Context, inbox *model.Inbox, config ChannelConfig) error { return nil } func (m *mockProvider_Cov13) ProcessIncoming(ctx context.Context, inbox *model.Inbox, rawPayload []byte) (*IncomingMessage, error) { return nil, nil } func (m *mockProvider_Cov13) ValidateWebhookRequest(ctx context.Context, inbox *model.Inbox, request *WebhookRequest) error { return nil } func (m *mockProvider_Cov13) SendMessage(ctx context.Context, inbox *model.Inbox, message *model.Message, contact *model.Contact) (*SendResult, error) { return &SendResult{}, nil } func (m *mockProvider_Cov13) GetContactProfile(ctx context.Context, inbox *model.Inbox, contactSource string) (*ContactProfile, error) { return &ContactProfile{}, nil } func (m *mockProvider_Cov13) Capabilities() ChannelCapabilities { return ChannelCapabilities{} } type mockProviderDuplicate_Cov13 struct{} func (m *mockProviderDuplicate_Cov13) Type() ChannelType { return "mock_cov13" } func (m *mockProviderDuplicate_Cov13) Name() string { return "MockDup" } func (m *mockProviderDuplicate_Cov13) Description() string { return "" } func (m *mockProviderDuplicate_Cov13) ConfigSchema() *ConfigSchemaDefinition { return nil } func (m *mockProviderDuplicate_Cov13) ValidateConfig(ctx context.Context, config ChannelConfig) error { return nil } func (m *mockProviderDuplicate_Cov13) DefaultConfig() ChannelConfig { return nil } func (m *mockProviderDuplicate_Cov13) OnCreate(ctx context.Context, inbox *model.Inbox, config ChannelConfig) (ChannelConfig, error) { return nil, nil } func (m *mockProviderDuplicate_Cov13) OnDestroy(ctx context.Context, inbox *model.Inbox, config ChannelConfig) error { return nil } func (m *mockProviderDuplicate_Cov13) ProcessIncoming(ctx context.Context, inbox *model.Inbox, rawPayload []byte) (*IncomingMessage, error) { return nil, nil } func (m *mockProviderDuplicate_Cov13) ValidateWebhookRequest(ctx context.Context, inbox *model.Inbox, request *WebhookRequest) error { return nil } func (m *mockProviderDuplicate_Cov13) SendMessage(ctx context.Context, inbox *model.Inbox, message *model.Message, contact *model.Contact) (*SendResult, error) { return nil, nil } func (m *mockProviderDuplicate_Cov13) GetContactProfile(ctx context.Context, inbox *model.Inbox, contactSource string) (*ContactProfile, error) { return nil, nil } func (m *mockProviderDuplicate_Cov13) Capabilities() ChannelCapabilities { return ChannelCapabilities{} } type mockProviderNoSchema_Cov13 struct{ mockProvider_Cov13 } func (m *mockProviderNoSchema_Cov13) ConfigSchema() *ConfigSchemaDefinition { return nil } func (m *mockProviderNoSchema_Cov13) Type() ChannelType { return "mock_noschema_cov13" } type mockProviderType_Cov13 struct{ mockProvider_Cov13 } func (m *mockProviderType_Cov13) ConfigSchema() *ConfigSchemaDefinition { return &ConfigSchemaDefinition{ Type: "object", Properties: map[string]ConfigProperty{ "num": {Type: "number"}, }, } } func (m *mockProviderType_Cov13) Type() ChannelType { return "mock_type_cov13" } type mockProviderInt_Cov13 struct{ mockProvider_Cov13 } func (m *mockProviderInt_Cov13) ConfigSchema() *ConfigSchemaDefinition { return &ConfigSchemaDefinition{ Type: "object", Properties: map[string]ConfigProperty{ "int_field": {Type: "integer"}, }, } } func (m *mockProviderInt_Cov13) Type() ChannelType { return "mock_int_cov13" } type mockProviderBool_Cov13 struct{ mockProvider_Cov13 } func (m *mockProviderBool_Cov13) ConfigSchema() *ConfigSchemaDefinition { return &ConfigSchemaDefinition{ Type: "object", Properties: map[string]ConfigProperty{ "flag": {Type: "boolean"}, }, } } func (m *mockProviderBool_Cov13) Type() ChannelType { return "mock_bool_cov13" } type mockProviderArray_Cov13 struct{ mockProvider_Cov13 } func (m *mockProviderArray_Cov13) ConfigSchema() *ConfigSchemaDefinition { return &ConfigSchemaDefinition{ Type: "object", Properties: map[string]ConfigProperty{ "arr": {Type: "array"}, }, } } func (m *mockProviderArray_Cov13) Type() ChannelType { return "mock_array_cov13" } type mockProviderObject_Cov13 struct{ mockProvider_Cov13 } func (m *mockProviderObject_Cov13) ConfigSchema() *ConfigSchemaDefinition { return &ConfigSchemaDefinition{ Type: "object", Properties: map[string]ConfigProperty{ "obj": {Type: "object"}, }, } } func (m *mockProviderObject_Cov13) Type() ChannelType { return "mock_object_cov13" } type mockProviderEnum_Cov13 struct{ mockProvider_Cov13 } func (m *mockProviderEnum_Cov13) ConfigSchema() *ConfigSchemaDefinition { return &ConfigSchemaDefinition{ Type: "object", Properties: map[string]ConfigProperty{ "choice": {Type: "string", Enum: []string{"a", "b"}}, }, } } func (m *mockProviderEnum_Cov13) Type() ChannelType { return "mock_enum_cov13" } type mockProviderPattern_Cov13 struct{ mockProvider_Cov13 } func (m *mockProviderPattern_Cov13) ConfigSchema() *ConfigSchemaDefinition { return &ConfigSchemaDefinition{ Type: "object", Properties: map[string]ConfigProperty{ "val": {Type: "string", Pattern: `^[a-z]+\d+$`}, }, } } func (m *mockProviderPattern_Cov13) Type() ChannelType { return "mock_pattern_cov13" } type mockProviderBadPattern_Cov13 struct{ mockProvider_Cov13 } func (m *mockProviderBadPattern_Cov13) ConfigSchema() *ConfigSchemaDefinition { return &ConfigSchemaDefinition{ Type: "object", Properties: map[string]ConfigProperty{ "val": {Type: "string", Pattern: `[`}, }, } } func (m *mockProviderBadPattern_Cov13) Type() ChannelType { return "mock_badpattern_cov13" } type mockProviderFormat_Cov13 struct{ mockProvider_Cov13 } func (m *mockProviderFormat_Cov13) ConfigSchema() *ConfigSchemaDefinition { return &ConfigSchemaDefinition{ Type: "object", Properties: map[string]ConfigProperty{ "url": {Type: "string", Format: "url"}, "email": {Type: "string", Format: "email"}, }, } } func (m *mockProviderFormat_Cov13) Type() ChannelType { return "mock_format_cov13" } type mockProviderUnknownFormat_Cov13 struct{ mockProvider_Cov13 } func (m *mockProviderUnknownFormat_Cov13) ConfigSchema() *ConfigSchemaDefinition { return &ConfigSchemaDefinition{ Type: "object", Properties: map[string]ConfigProperty{ "val": {Type: "string", Format: "unknown"}, }, } } func (m *mockProviderUnknownFormat_Cov13) Type() ChannelType { return "mock_unkformat_cov13" } type mockProviderUnknownType_Cov13 struct{ mockProvider_Cov13 } func (m *mockProviderUnknownType_Cov13) ConfigSchema() *ConfigSchemaDefinition { return &ConfigSchemaDefinition{ Type: "object", Properties: map[string]ConfigProperty{ "val": {Type: "custom_type"}, }, } } func (m *mockProviderUnknownType_Cov13) Type() ChannelType { return "mock_unktype_cov13" } type mockProviderDefaults_Cov13 struct{ mockProvider_Cov13 } func (m *mockProviderDefaults_Cov13) ConfigSchema() *ConfigSchemaDefinition { return &ConfigSchemaDefinition{ Type: "object", Properties: map[string]ConfigProperty{ "default_field": {Type: "string", Default: "default_val"}, }, } } func (m *mockProviderDefaults_Cov13) Type() ChannelType { return "mock_defaults_cov13" } type mockProviderSecret_Cov13 struct{ mockProvider_Cov13 } func (m *mockProviderSecret_Cov13) ConfigSchema() *ConfigSchemaDefinition { return &ConfigSchemaDefinition{ Type: "object", Properties: map[string]ConfigProperty{ "normal": {Type: "string"}, "secret_field": {Type: "string", Secret: true}, }, } } func (m *mockProviderSecret_Cov13) Type() ChannelType { return "mock_secret_cov13" } type mockListener_Cov13 struct { name string } func (m *mockListener_Cov13) Name() string { return m.name } func (m *mockListener_Cov13) OnEvent(ctx context.Context, event *ChannelEvent) error { return nil } type mockListenerErr_Cov13 struct{} func (m *mockListenerErr_Cov13) Name() string { return "err_listener" } func (m *mockListenerErr_Cov13) OnEvent(ctx context.Context, event *ChannelEvent) error { return errMock_Cov13 } type mockInboxRepo_Cov13 struct{} func (m *mockInboxRepo_Cov13) FindByChannelTypeAndIdentifier(channelType string, identifier string) (*model.Inbox, error) { return nil, errMock_Cov13 } func (m *mockInboxRepo_Cov13) FindByID(id uint) (*model.Inbox, error) { return nil, errMock_Cov13 } var errMock_Cov13 = &mockErr_Cov13{} type mockErr_Cov13 struct{} func (e *mockErr_Cov13) Error() string { return "mock error" } // =========================== // Worker pool integration test (minimal) // =========================== // =========================== // WebhookHandler HTTP tests // =========================== func TestWebhookHandler_HandleWebhook_NoProvider_Cov13(t *testing.T) { safeCall_Cov13(func() { // This is a gin handler test, tested elsewhere with proper gin context }) } // suppress unused warnings var _ = sync.Mutex{}