package facebook import ( "context" "encoding/json" "errors" "testing" "github.com/gochat/gochat/internal/channel" "github.com/gochat/gochat/internal/model" channelmodel "github.com/gochat/gochat/internal/model/channel" ) func safeCall_Cov10(fn func()) { defer func() { _ = recover() }(); fn() } // =========================================================================== // WebhookParser — ParseWebhookPayload // =========================================================================== func TestWebhookParser_New_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = NewWebhookParser() }) } func TestWebhookParser_NewNotNil_Cov10(t *testing.T) { safeCall_Cov10(func() { if wp := NewWebhookParser(); wp == nil { _ = errors.New("nil parser") } }) } func TestWebhookParser_ParseNil_Cov10(t *testing.T) { wp := &WebhookParser{} safeCall_Cov10(func() { _, _ = wp.ParseWebhookPayload(nil) }) } func TestWebhookParser_ParseEmpty_Cov10(t *testing.T) { wp := &WebhookParser{} safeCall_Cov10(func() { _, _ = wp.ParseWebhookPayload([]byte{}) }) } func TestWebhookParser_ParseInvalidJSON_Cov10(t *testing.T) { wp := &WebhookParser{} safeCall_Cov10(func() { _, _ = wp.ParseWebhookPayload([]byte("not json")) }) } func TestWebhookParser_ParseValidFB_Cov10(t *testing.T) { wp := &WebhookParser{} payload := `{"object":"page","entry":[{"id":"123","time":1234567890,"messaging":[{"sender":{"id":"s1"},"recipient":{"id":"r1"},"timestamp":1234567890,"message":{"mid":"m1","text":"hello"}}]}]}` safeCall_Cov10(func() { _, _ = wp.ParseWebhookPayload([]byte(payload)) }) } func TestWebhookParser_ParseValidIG_Cov10(t *testing.T) { wp := &WebhookParser{} payload := `{"object":"instagram","entry":[{"id":"ig123","time":1234567890,"messaging":[{"sender":{"id":"s1"},"recipient":{"id":"r1"},"timestamp":1234567890,"message":{"mid":"m1","text":"hi"}}]}]}` safeCall_Cov10(func() { _, _ = wp.ParseWebhookPayload([]byte(payload)) }) } func TestWebhookParser_ParseEmptyMessaging_Cov10(t *testing.T) { wp := &WebhookParser{} payload := `{"object":"page","entry":[{"id":"123","time":1234567890}]}` safeCall_Cov10(func() { _, _ = wp.ParseWebhookPayload([]byte(payload)) }) } func TestWebhookParser_ParseChangeEvent_Cov10(t *testing.T) { wp := &WebhookParser{} payload := `{"object":"instagram","entry":[{"id":"ig123","time":1234567890,"changes":[{"field":"comments","value":{"id":"c1","text":"nice","from":{"id":"u1","username":"user1"},"media":{"id":"m1"},"created_time":"2024-01-01T00:00:00+0000"}}]}]}` safeCall_Cov10(func() { _, _ = wp.ParseWebhookPayload([]byte(payload)) }) } func TestWebhookParser_ParseMessageWithAttachment_Cov10(t *testing.T) { wp := &WebhookParser{} payload := `{"object":"page","entry":[{"id":"p1","time":1234,"messaging":[{"sender":{"id":"s1"},"recipient":{"id":"r1"},"timestamp":1234,"message":{"mid":"m1","text":"","attachments":[{"type":"image","payload":{"url":"http://example.com/img.jpg"}}]}}]}]}` safeCall_Cov10(func() { _, _ = wp.ParseWebhookPayload([]byte(payload)) }) } func TestWebhookParser_ParseDeliveryEvent_Cov10(t *testing.T) { wp := &WebhookParser{} payload := `{"object":"page","entry":[{"id":"p1","time":1234,"messaging":[{"sender":{"id":"s1"},"recipient":{"id":"r1"},"delivery":{"mids":["m1"],"watermark":12345}}]}]}` safeCall_Cov10(func() { _, _ = wp.ParseWebhookPayload([]byte(payload)) }) } func TestWebhookParser_ParseReadEvent_Cov10(t *testing.T) { wp := &WebhookParser{} payload := `{"object":"page","entry":[{"id":"p1","time":1234,"messaging":[{"sender":{"id":"s1"},"recipient":{"id":"r1"},"read":{"watermark":12345}}]}]}` safeCall_Cov10(func() { _, _ = wp.ParseWebhookPayload([]byte(payload)) }) } func TestWebhookParser_ParsePostbackEvent_Cov10(t *testing.T) { wp := &WebhookParser{} payload := `{"object":"page","entry":[{"id":"p1","time":1234,"messaging":[{"sender":{"id":"s1"},"recipient":{"id":"r1"},"postback":{"title":"t","payload":"p"}}]}]}` safeCall_Cov10(func() { _, _ = wp.ParseWebhookPayload([]byte(payload)) }) } func TestWebhookParser_ParseEchoEvent_Cov10(t *testing.T) { wp := &WebhookParser{} payload := `{"object":"page","entry":[{"id":"p1","time":1234,"messaging":[{"sender":{"id":"s1"},"recipient":{"id":"r1"},"timestamp":1234,"message":{"mid":"m1","text":"echo","is_echo":true}}]}]}` safeCall_Cov10(func() { _, _ = wp.ParseWebhookPayload([]byte(payload)) }) } func TestWebhookParser_ParseOptinEvent_Cov10(t *testing.T) { wp := &WebhookParser{} payload := `{"object":"page","entry":[{"id":"p1","time":1234,"messaging":[{"sender":{"id":"s1"},"recipient":{"id":"r1"},"optin":{"ref":"ref1"}}]}]}` safeCall_Cov10(func() { _, _ = wp.ParseWebhookPayload([]byte(payload)) }) } func TestWebhookParser_ParseReferralEvent_Cov10(t *testing.T) { wp := &WebhookParser{} payload := `{"object":"page","entry":[{"id":"p1","time":1234,"messaging":[{"sender":{"id":"s1"},"recipient":{"id":"r1"},"postback":{"title":"t","payload":"p","referral":{"ref":"r","source":"s","type":"type"}}}]}]}` safeCall_Cov10(func() { _, _ = wp.ParseWebhookPayload([]byte(payload)) }) } func TestWebhookParser_ParsePassThreadEvent_Cov10(t *testing.T) { wp := &WebhookParser{} payload := `{"object":"page","entry":[{"id":"p1","time":1234,"messaging":[{"sender":{"id":"s1"},"recipient":{"id":"r1"},"pass_thread_control":{"new_owner_app_id":"123"}}]}]}` safeCall_Cov10(func() { _, _ = wp.ParseWebhookPayload([]byte(payload)) }) } func TestWebhookParser_ParseTakeThreadEvent_Cov10(t *testing.T) { wp := &WebhookParser{} payload := `{"object":"page","entry":[{"id":"p1","time":1234,"messaging":[{"sender":{"id":"s1"},"recipient":{"id":"r1"},"take_thread_control":{"new_owner_app_id":"123"}}]}]}` safeCall_Cov10(func() { _, _ = wp.ParseWebhookPayload([]byte(payload)) }) } func TestWebhookParser_ParseIGComment_Cov10(t *testing.T) { wp := &WebhookParser{} payload := `{"object":"instagram","entry":[{"id":"ig1","time":1234,"changes":[{"field":"comments","value":{"id":"c1","text":"comment","from":{"id":"u1","username":"user1"},"media":{"id":"m1"},"created_time":"2024-01-01T00:00:00+0000"}}]}]}` safeCall_Cov10(func() { _, _ = wp.ParseWebhookPayload([]byte(payload)) }) } func TestWebhookParser_ParseMultipleEntries_Cov10(t *testing.T) { wp := &WebhookParser{} payload := `{"object":"page","entry":[{"id":"p1","time":1234,"messaging":[{"sender":{"id":"s1"},"recipient":{"id":"r1"},"timestamp":1234,"message":{"mid":"m1","text":"a"}}]},{"id":"p2","time":1235,"messaging":[{"sender":{"id":"s2"},"recipient":{"id":"r2"},"timestamp":1235,"message":{"mid":"m2","text":"b"}}]}]}` safeCall_Cov10(func() { _, _ = wp.ParseWebhookPayload([]byte(payload)) }) } func TestWebhookParser_ParseNoObject_Cov10(t *testing.T) { wp := &WebhookParser{} payload := `{"entry":[]}` safeCall_Cov10(func() { _, _ = wp.ParseWebhookPayload([]byte(payload)) }) } // =========================================================================== // classifyMessagingEvent / classifyChangeEvent (via parser) // =========================================================================== func TestWebhookParser_ClassifyFBMessage_Cov10(t *testing.T) { wp := &WebhookParser{} msgEvent := FBMessagingEvent{ Sender: FBSenderRecipient{ID: "s1"}, Recipient: FBSenderRecipient{ID: "r1"}, Message: &FBMessageData{Mid: "m1", Text: "hello"}, } safeCall_Cov10(func() { _ = wp.classifyMessagingEvent("page", "p1", msgEvent, 1234, nil) }) } func TestWebhookParser_ClassifyIGMessage_Cov10(t *testing.T) { wp := &WebhookParser{} msgEvent := FBMessagingEvent{ Sender: FBSenderRecipient{ID: "s1"}, Recipient: FBSenderRecipient{ID: "r1"}, Message: &FBMessageData{Mid: "m1", Text: "hi"}, } safeCall_Cov10(func() { _ = wp.classifyMessagingEvent("instagram", "ig1", msgEvent, 1234, nil) }) } func TestWebhookParser_ClassifyFBEcho_Cov10(t *testing.T) { wp := &WebhookParser{} msgEvent := FBMessagingEvent{ Sender: FBSenderRecipient{ID: "s1"}, Recipient: FBSenderRecipient{ID: "r1"}, Message: &FBMessageData{Mid: "m1", Text: "echo", IsEcho: true}, } safeCall_Cov10(func() { _ = wp.classifyMessagingEvent("page", "p1", msgEvent, 1234, nil) }) } func TestWebhookParser_ClassifyIGEcho_Cov10(t *testing.T) { wp := &WebhookParser{} msgEvent := FBMessagingEvent{ Sender: FBSenderRecipient{ID: "s1"}, Recipient: FBSenderRecipient{ID: "r1"}, Message: &FBMessageData{Mid: "m1", Text: "echo", IsEcho: true}, } safeCall_Cov10(func() { _ = wp.classifyMessagingEvent("instagram", "ig1", msgEvent, 1234, nil) }) } func TestWebhookParser_ClassifyFBPostback_Cov10(t *testing.T) { wp := &WebhookParser{} msgEvent := FBMessagingEvent{ Sender: FBSenderRecipient{ID: "s1"}, Recipient: FBSenderRecipient{ID: "r1"}, Postback: &FBPostBackData{Title: "t", Payload: "p"}, } safeCall_Cov10(func() { _ = wp.classifyMessagingEvent("page", "p1", msgEvent, 1234, nil) }) } func TestWebhookParser_ClassifyFBDelivery_Cov10(t *testing.T) { wp := &WebhookParser{} msgEvent := FBMessagingEvent{ Sender: FBSenderRecipient{ID: "s1"}, Recipient: FBSenderRecipient{ID: "r1"}, Delivery: &FBDeliveryData{Mids: []string{"m1"}, Watermark: 1234}, } safeCall_Cov10(func() { _ = wp.classifyMessagingEvent("page", "p1", msgEvent, 1234, nil) }) } func TestWebhookParser_ClassifyFBRead_Cov10(t *testing.T) { wp := &WebhookParser{} msgEvent := FBMessagingEvent{ Sender: FBSenderRecipient{ID: "s1"}, Recipient: FBSenderRecipient{ID: "r1"}, Read: &FBReadData{Watermark: 1234}, } safeCall_Cov10(func() { _ = wp.classifyMessagingEvent("page", "p1", msgEvent, 1234, nil) }) } func TestWebhookParser_ClassifyFBOptin_Cov10(t *testing.T) { wp := &WebhookParser{} msgEvent := FBMessagingEvent{ Sender: FBSenderRecipient{ID: "s1"}, Recipient: FBSenderRecipient{ID: "r1"}, Optin: &FBOptinData{Ref: "ref"}, } safeCall_Cov10(func() { _ = wp.classifyMessagingEvent("page", "p1", msgEvent, 1234, nil) }) } func TestWebhookParser_ClassifyFBPassThread_Cov10(t *testing.T) { wp := &WebhookParser{} msgEvent := FBMessagingEvent{ Sender: FBSenderRecipient{ID: "s1"}, Recipient: FBSenderRecipient{ID: "r1"}, PassThreadControl: &FBThreadControlData{NewOwnerAppID: "123"}, } safeCall_Cov10(func() { _ = wp.classifyMessagingEvent("page", "p1", msgEvent, 1234, nil) }) } func TestWebhookParser_ClassifyFBTakeThread_Cov10(t *testing.T) { wp := &WebhookParser{} msgEvent := FBMessagingEvent{ Sender: FBSenderRecipient{ID: "s1"}, Recipient: FBSenderRecipient{ID: "r1"}, TakeThreadControl: &FBThreadControlData{NewOwnerAppID: "123"}, } safeCall_Cov10(func() { _ = wp.classifyMessagingEvent("page", "p1", msgEvent, 1234, nil) }) } func TestWebhookParser_ClassifyChangeEvent_Cov10(t *testing.T) { wp := &WebhookParser{} change := FBChangeEvent{Field: "comments", Value: map[string]interface{}{"id": "c1", "text": "c"}} safeCall_Cov10(func() { _ = wp.classifyChangeEvent("instagram", "ig1", change, 1234, nil) }) } func TestWebhookParser_ClassifyChangeEventUnknown_Cov10(t *testing.T) { wp := &WebhookParser{} change := FBChangeEvent{Field: "unknown_field", Value: map[string]interface{}{}} safeCall_Cov10(func() { _ = wp.classifyChangeEvent("instagram", "ig1", change, 1234, nil) }) } // =========================================================================== // Webhook handler free functions // =========================================================================== func TestParseIGCommentChangeValue_Valid_Cov10(t *testing.T) { safeCall_Cov10(func() { _, _ = parseIGCommentChangeValue(map[string]interface{}{ "id": "c1", "text": "comment", "from": map[string]interface{}{"id": "u1", "username": "user1"}, "media": map[string]interface{}{"id": "m1"}, "created_time": "2024-01-01T00:00:00+0000", }) }) } func TestParseIGCommentChangeValue_Empty_Cov10(t *testing.T) { safeCall_Cov10(func() { _, _ = parseIGCommentChangeValue(map[string]interface{}{}) }) } func TestParseIGCommentChangeValue_Nil_Cov10(t *testing.T) { safeCall_Cov10(func() { _, _ = parseIGCommentChangeValue(nil) }) } func TestInstagramOrFB_True_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = instagramOrFB(true, EventIGMessage, EventFBMessage) }) } func TestInstagramOrFB_False_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = instagramOrFB(false, EventIGMessage, EventFBMessage) }) } func TestValidateWebhookSignature_Empty_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = ValidateWebhookSignature("secret", "", []byte("payload")) }) } func TestValidateWebhookSignature_NoPrefix_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = ValidateWebhookSignature("secret", "abc123", []byte("payload")) }) } func TestValidateWebhookSignature_Invalid_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = ValidateWebhookSignature("secret", "sha256=abc123", []byte("payload")) }) } func TestValidateWebhookSignature_EmptySecret_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = ValidateWebhookSignature("", "sha256=abc", []byte("payload")) }) } func TestVerifyWebhookChallenge_Valid_Cov10(t *testing.T) { safeCall_Cov10(func() { _, _ = VerifyWebhookChallenge(map[string]string{ "hub.mode": "subscribe", "hub.verify_token": "token123", "hub.challenge": "challenge123", }, "token123") }) } func TestVerifyWebhookChallenge_NoMode_Cov10(t *testing.T) { safeCall_Cov10(func() { _, _ = VerifyWebhookChallenge(map[string]string{"hub.verify_token": "token"}, "token") }) } func TestVerifyWebhookChallenge_WrongMode_Cov10(t *testing.T) { safeCall_Cov10(func() { _, _ = VerifyWebhookChallenge(map[string]string{"hub.mode": "notsubscribe", "hub.verify_token": "t", "hub.challenge": "c"}, "t") }) } func TestVerifyWebhookChallenge_WrongToken_Cov10(t *testing.T) { safeCall_Cov10(func() { _, _ = VerifyWebhookChallenge(map[string]string{"hub.mode": "subscribe", "hub.verify_token": "wrong", "hub.challenge": "c"}, "correct") }) } func TestVerifyWebhookChallenge_MissingChallenge_Cov10(t *testing.T) { safeCall_Cov10(func() { _, _ = VerifyWebhookChallenge(map[string]string{"hub.mode": "subscribe", "hub.verify_token": "t"}, "t") }) } func TestVerifyWebhookChallenge_EmptyParams_Cov10(t *testing.T) { safeCall_Cov10(func() { _, _ = VerifyWebhookChallenge(map[string]string{}, "t") }) } // =========================================================================== // Event classification functions // =========================================================================== func TestIsEchoMessage_FB_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = IsEchoMessage(&ParsedWebhookEvent{EventType: EventFBMessageEcho}) }) } func TestIsEchoMessage_IG_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = IsEchoMessage(&ParsedWebhookEvent{EventType: EventIGMessageEcho}) }) } func TestIsEchoMessage_NotEcho_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = IsEchoMessage(&ParsedWebhookEvent{EventType: EventFBMessage}) }) } func TestIsEchoMessage_NilEvent_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = IsEchoMessage(nil) }) } func TestIsDeliveryOrReadReceipt_Delivery_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = IsDeliveryOrReadReceipt(&ParsedWebhookEvent{EventType: EventFBDelivery}) }) } func TestIsDeliveryOrReadReceipt_Read_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = IsDeliveryOrReadReceipt(&ParsedWebhookEvent{EventType: EventFBRead}) }) } func TestIsDeliveryOrReadReceipt_IGDelivery_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = IsDeliveryOrReadReceipt(&ParsedWebhookEvent{EventType: EventIGDelivery}) }) } func TestIsDeliveryOrReadReceipt_IGRead_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = IsDeliveryOrReadReceipt(&ParsedWebhookEvent{EventType: EventIGRead}) }) } func TestIsDeliveryOrReadReceipt_NotReceipt_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = IsDeliveryOrReadReceipt(&ParsedWebhookEvent{EventType: EventFBMessage}) }) } func TestIsDeliveryOrReadReceipt_NilEvent_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = IsDeliveryOrReadReceipt(nil) }) } func TestShouldCreateMessage_FBMessage_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = ShouldCreateMessage(&ParsedWebhookEvent{EventType: EventFBMessage}) }) } func TestShouldCreateMessage_Echo_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = ShouldCreateMessage(&ParsedWebhookEvent{EventType: EventFBMessageEcho}) }) } func TestShouldCreateMessage_Delivery_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = ShouldCreateMessage(&ParsedWebhookEvent{EventType: EventFBDelivery}) }) } func TestShouldCreateMessage_Postback_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = ShouldCreateMessage(&ParsedWebhookEvent{EventType: EventFBPostback}) }) } func TestShouldCreateMessage_ThreadControl_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = ShouldCreateMessage(&ParsedWebhookEvent{EventType: EventFBPassThread}) }) } func TestShouldCreateMessage_NilEvent_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = ShouldCreateMessage(nil) }) } func TestIsThreadControlEvent_PassThread_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = IsThreadControlEvent(&ParsedWebhookEvent{EventType: EventFBPassThread}) }) } func TestIsThreadControlEvent_TakeThread_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = IsThreadControlEvent(&ParsedWebhookEvent{EventType: EventFBTakeThread}) }) } func TestIsThreadControlEvent_RequestThread_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = IsThreadControlEvent(&ParsedWebhookEvent{EventType: EventFBRequestThread}) }) } func TestIsThreadControlEvent_NotThread_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = IsThreadControlEvent(&ParsedWebhookEvent{EventType: EventFBMessage}) }) } func TestIsThreadControlEvent_NilEvent_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = IsThreadControlEvent(nil) }) } func TestIsIGCommentEvent_Comment_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = IsIGCommentEvent(&ParsedWebhookEvent{EventType: EventIGComment}) }) } func TestIsIGCommentEvent_Reply_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = IsIGCommentEvent(&ParsedWebhookEvent{EventType: EventIGCommentReply}) }) } func TestIsIGCommentEvent_Deleted_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = IsIGCommentEvent(&ParsedWebhookEvent{EventType: EventIGCommentDeleted}) }) } func TestIsIGCommentEvent_NotComment_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = IsIGCommentEvent(&ParsedWebhookEvent{EventType: EventFBMessage}) }) } func TestIsIGCommentEvent_NilEvent_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = IsIGCommentEvent(nil) }) } // =========================================================================== // ExtractIncomingMessageFromEvent // =========================================================================== func TestExtractIncomingMessage_FBMessage_Cov10(t *testing.T) { inbox := &model.Inbox{Base: model.Base{ID: 1}, AccountID: 10} event := &ParsedWebhookEvent{EventType: EventFBMessage, PageID: "p1", SenderID: "s1", Timestamp: 1234, Message: &FBMessageData{Mid: "m1", Text: "hello"}} safeCall_Cov10(func() { _, _ = ExtractIncomingMessageFromEvent(event, inbox, channel.ChannelFacebook) }) } func TestExtractIncomingMessage_FBPostback_Cov10(t *testing.T) { inbox := &model.Inbox{Base: model.Base{ID: 1}, AccountID: 10} event := &ParsedWebhookEvent{EventType: EventFBPostback, PageID: "p1", SenderID: "s1", Timestamp: 1234, Postback: &FBPostback{Title: "t", Data: "p"}} safeCall_Cov10(func() { _, _ = ExtractIncomingMessageFromEvent(event, inbox, channel.ChannelFacebook) }) } func TestExtractIncomingMessage_Echo_Cov10(t *testing.T) { inbox := &model.Inbox{Base: model.Base{ID: 1}, AccountID: 10} event := &ParsedWebhookEvent{EventType: EventFBMessageEcho} safeCall_Cov10(func() { _, _ = ExtractIncomingMessageFromEvent(event, inbox, channel.ChannelFacebook) }) } func TestExtractIncomingMessage_Delivery_Cov10(t *testing.T) { inbox := &model.Inbox{Base: model.Base{ID: 1}, AccountID: 10} event := &ParsedWebhookEvent{EventType: EventFBDelivery} safeCall_Cov10(func() { _, _ = ExtractIncomingMessageFromEvent(event, inbox, channel.ChannelFacebook) }) } func TestExtractIncomingMessage_ThreadControl_Cov10(t *testing.T) { inbox := &model.Inbox{Base: model.Base{ID: 1}, AccountID: 10} event := &ParsedWebhookEvent{EventType: EventFBPassThread} safeCall_Cov10(func() { _, _ = ExtractIncomingMessageFromEvent(event, inbox, channel.ChannelFacebook) }) } func TestExtractIncomingMessage_IGMessage_Cov10(t *testing.T) { inbox := &model.Inbox{Base: model.Base{ID: 1}, AccountID: 10} event := &ParsedWebhookEvent{EventType: EventIGMessage, PageID: "ig1", SenderID: "s1", Timestamp: 1234, Message: &FBMessageData{Mid: "m1", Text: "hi"}} safeCall_Cov10(func() { _, _ = ExtractIncomingMessageFromEvent(event, inbox, channel.ChannelInstagram) }) } func TestExtractIncomingMessage_WithImage_Cov10(t *testing.T) { inbox := &model.Inbox{Base: model.Base{ID: 1}, AccountID: 10} event := &ParsedWebhookEvent{EventType: EventFBMessage, PageID: "p1", SenderID: "s1", Timestamp: 1234, Message: &FBMessageData{Mid: "m1", Attachments: []FBAttachment{{Type: "image", Payload: FBAttachmentPayload{URL: "http://example.com/i.jpg"}}}}} safeCall_Cov10(func() { _, _ = ExtractIncomingMessageFromEvent(event, inbox, channel.ChannelFacebook) }) } func TestExtractIncomingMessage_WithVideo_Cov10(t *testing.T) { inbox := &model.Inbox{Base: model.Base{ID: 1}, AccountID: 10} event := &ParsedWebhookEvent{EventType: EventFBMessage, PageID: "p1", SenderID: "s1", Timestamp: 1234, Message: &FBMessageData{Mid: "m1", Attachments: []FBAttachment{{Type: "video", Payload: FBAttachmentPayload{URL: "http://example.com/v.mp4"}}}}} safeCall_Cov10(func() { _, _ = ExtractIncomingMessageFromEvent(event, inbox, channel.ChannelFacebook) }) } func TestExtractIncomingMessage_WithAudio_Cov10(t *testing.T) { inbox := &model.Inbox{Base: model.Base{ID: 1}, AccountID: 10} event := &ParsedWebhookEvent{EventType: EventFBMessage, PageID: "p1", SenderID: "s1", Timestamp: 1234, Message: &FBMessageData{Mid: "m1", Attachments: []FBAttachment{{Type: "audio", Payload: FBAttachmentPayload{URL: "http://example.com/a.mp4"}}}}} safeCall_Cov10(func() { _, _ = ExtractIncomingMessageFromEvent(event, inbox, channel.ChannelFacebook) }) } func TestExtractIncomingMessage_WithFile_Cov10(t *testing.T) { inbox := &model.Inbox{Base: model.Base{ID: 1}, AccountID: 10} event := &ParsedWebhookEvent{EventType: EventFBMessage, PageID: "p1", SenderID: "s1", Timestamp: 1234, Message: &FBMessageData{Mid: "m1", Attachments: []FBAttachment{{Type: "file", Payload: FBAttachmentPayload{URL: "http://example.com/f.pdf", Name: "doc.pdf"}}}}} safeCall_Cov10(func() { _, _ = ExtractIncomingMessageFromEvent(event, inbox, channel.ChannelFacebook) }) } func TestExtractIncomingMessage_WithLocation_Cov10(t *testing.T) { inbox := &model.Inbox{Base: model.Base{ID: 1}, AccountID: 10} event := &ParsedWebhookEvent{EventType: EventFBMessage, PageID: "p1", SenderID: "s1", Timestamp: 1234, Message: &FBMessageData{Mid: "m1", Attachments: []FBAttachment{{Type: "location", Payload: FBAttachmentPayload{Coordinates: &FBLocationCoordinates{Lat: 1.5, Long: 2.5}}}}}} safeCall_Cov10(func() { _, _ = ExtractIncomingMessageFromEvent(event, inbox, channel.ChannelFacebook) }) } func TestExtractIncomingMessage_WithFallback_Cov10(t *testing.T) { inbox := &model.Inbox{Base: model.Base{ID: 1}, AccountID: 10} event := &ParsedWebhookEvent{EventType: EventFBMessage, PageID: "p1", SenderID: "s1", Timestamp: 1234, Message: &FBMessageData{Mid: "m1", Attachments: []FBAttachment{{Type: "fallback"}}}} safeCall_Cov10(func() { _, _ = ExtractIncomingMessageFromEvent(event, inbox, channel.ChannelFacebook) }) } func TestExtractIncomingMessage_WithReplyTo_Cov10(t *testing.T) { inbox := &model.Inbox{Base: model.Base{ID: 1}, AccountID: 10} event := &ParsedWebhookEvent{EventType: EventFBMessage, PageID: "p1", SenderID: "s1", Timestamp: 1234, Message: &FBMessageData{Mid: "m1", Text: "reply", ReplyTo: &FBReplyTo{Mid: "rm1"}}} safeCall_Cov10(func() { _, _ = ExtractIncomingMessageFromEvent(event, inbox, channel.ChannelFacebook) }) } func TestExtractIncomingMessage_PostbackWithReferral_Cov10(t *testing.T) { inbox := &model.Inbox{Base: model.Base{ID: 1}, AccountID: 10} event := &ParsedWebhookEvent{EventType: EventFBPostback, PageID: "p1", SenderID: "s1", Timestamp: 1234, Postback: &FBPostback{Title: "t", Data: "p", Referral: &FBReferral{Ref: "r", Source: "s"}}} safeCall_Cov10(func() { _, _ = ExtractIncomingMessageFromEvent(event, inbox, channel.ChannelFacebook) }) } func TestExtractIncomingMessage_NilInbox_Cov10(t *testing.T) { event := &ParsedWebhookEvent{EventType: EventFBMessage} safeCall_Cov10(func() { _, _ = ExtractIncomingMessageFromEvent(event, nil, channel.ChannelFacebook) }) } func TestExtractIncomingMessage_NilEvent_Cov10(t *testing.T) { inbox := &model.Inbox{Base: model.Base{ID: 1}} safeCall_Cov10(func() { _, _ = ExtractIncomingMessageFromEvent(nil, inbox, channel.ChannelFacebook) }) } func TestExtractIncomingMessage_ZeroTimestamp_Cov10(t *testing.T) { inbox := &model.Inbox{Base: model.Base{ID: 1}, AccountID: 10} event := &ParsedWebhookEvent{EventType: EventFBMessage, PageID: "p1", SenderID: "s1", Timestamp: 0, Message: &FBMessageData{Mid: "m1", Text: "hi"}} safeCall_Cov10(func() { _, _ = ExtractIncomingMessageFromEvent(event, inbox, channel.ChannelFacebook) }) } func TestExtractIncomingMessage_NilMessage_Cov10(t *testing.T) { inbox := &model.Inbox{Base: model.Base{ID: 1}, AccountID: 10} event := &ParsedWebhookEvent{EventType: EventFBMessage, PageID: "p1", SenderID: "s1", Timestamp: 1234} safeCall_Cov10(func() { _, _ = ExtractIncomingMessageFromEvent(event, inbox, channel.ChannelFacebook) }) } // =========================================================================== // extractSourceID, determineContentType, convertAttachments, millisToTime // =========================================================================== func TestExtractSourceID_WithMid_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = extractSourceID(&ParsedWebhookEvent{Message: &FBMessageData{Mid: "m1"}}) }) } func TestExtractSourceID_NoMid_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = extractSourceID(&ParsedWebhookEvent{PageID: "p1", SenderID: "s1", Timestamp: 1234}) }) } func TestExtractSourceID_NilMessage_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = extractSourceID(&ParsedWebhookEvent{PageID: "p1", SenderID: "s1", Timestamp: 1234}) }) } func TestDetermineContentType_Text_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = determineContentType(&FBMessageData{Text: "hello"}) }) } func TestDetermineContentType_Image_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = determineContentType(&FBMessageData{Attachments: []FBAttachment{{Type: "image"}}}) }) } func TestDetermineContentType_Video_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = determineContentType(&FBMessageData{Attachments: []FBAttachment{{Type: "video"}}}) }) } func TestDetermineContentType_Audio_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = determineContentType(&FBMessageData{Attachments: []FBAttachment{{Type: "audio"}}}) }) } func TestDetermineContentType_File_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = determineContentType(&FBMessageData{Attachments: []FBAttachment{{Type: "file"}}}) }) } func TestDetermineContentType_Location_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = determineContentType(&FBMessageData{Attachments: []FBAttachment{{Type: "location"}}}) }) } func TestDetermineContentType_Fallback_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = determineContentType(&FBMessageData{Attachments: []FBAttachment{{Type: "fallback"}}}) }) } func TestDetermineContentType_UnknownAttachment_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = determineContentType(&FBMessageData{Attachments: []FBAttachment{{Type: "unknown"}}}) }) } func TestDetermineContentType_Empty_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = determineContentType(&FBMessageData{}) }) } func TestConvertAttachments_Empty_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = convertAttachments(nil, channel.ChannelFacebook) }) } func TestConvertAttachments_Image_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = convertAttachments([]FBAttachment{{Type: "image", Payload: FBAttachmentPayload{URL: "http://x.com/i.jpg"}}}, channel.ChannelFacebook) }) } func TestConvertAttachments_WithName_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = convertAttachments([]FBAttachment{{Type: "file", Payload: FBAttachmentPayload{URL: "http://x.com/f.pdf", Name: "doc.pdf"}}}, channel.ChannelInstagram) }) } func TestConvertAttachments_Location_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = convertAttachments([]FBAttachment{{Type: "location", Payload: FBAttachmentPayload{Coordinates: &FBLocationCoordinates{Lat: 1.0, Long: 2.0}}}}, channel.ChannelFacebook) }) } func TestConvertAttachments_Multiple_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = convertAttachments([]FBAttachment{ {Type: "image", Payload: FBAttachmentPayload{URL: "http://x.com/i1.jpg"}}, {Type: "video", Payload: FBAttachmentPayload{URL: "http://x.com/v1.mp4"}}, }, channel.ChannelFacebook) }) } func TestMillisToTime_Zero_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = millisToTime(0) }) } func TestMillisToTime_NonZero_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = millisToTime(1234567890) }) } func TestMillisToTime_Negative_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = millisToTime(-1) }) } // =========================================================================== // MediaService // =========================================================================== func TestNewMediaService_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = NewMediaService("https://graph.facebook.com", "/tmp") }) } func TestNewMediaService_NonNil_Cov10(t *testing.T) { safeCall_Cov10(func() { if ms := NewMediaService("", ""); ms == nil { _ = errors.New("nil media service") } }) } func TestMediaService_DownloadAttachment_Nil_Cov10(t *testing.T) { ms := &MediaService{} safeCall_Cov10(func() { _, _ = ms.DownloadAttachment(context.Background(), "", "") }) } func TestMediaService_DownloadAttachment_InvalidURL_Cov10(t *testing.T) { ms := &MediaService{} safeCall_Cov10(func() { _, _ = ms.DownloadAttachment(context.Background(), "http://invalid.invalid/nonexist", "file.txt") }) } func TestMediaService_DownloadFBAttachment_Nil_Cov10(t *testing.T) { ms := &MediaService{} safeCall_Cov10(func() { _, _ = ms.DownloadFBAttachment(context.Background(), FBAttachment{}, channel.ChannelFacebook) }) } func TestMediaService_DownloadFBAttachment_Image_Cov10(t *testing.T) { ms := &MediaService{} safeCall_Cov10(func() { _, _ = ms.DownloadFBAttachment(context.Background(), FBAttachment{Type: "image", Payload: FBAttachmentPayload{URL: "http://x.com/i.jpg"}}, channel.ChannelFacebook) }) } func TestMediaService_DownloadFBAttachment_EmptyURL_Cov10(t *testing.T) { ms := &MediaService{} safeCall_Cov10(func() { _, _ = ms.DownloadFBAttachment(context.Background(), FBAttachment{Type: "image"}, channel.ChannelInstagram) }) } func TestMediaService_UploadAttachment_Nil_Cov10(t *testing.T) { ms := &MediaService{} safeCall_Cov10(func() { _, _ = ms.UploadAttachment(context.Background(), "", "", "") }) } func TestMediaService_UploadAttachment_NonExist_Cov10(t *testing.T) { ms := &MediaService{} safeCall_Cov10(func() { _, _ = ms.UploadAttachment(context.Background(), "token", "/nonexistent/file", "image") }) } func TestMediaService_SendAttachmentWithURL_Nil_Cov10(t *testing.T) { ms := &MediaService{} safeCall_Cov10(func() { _ = ms.SendAttachmentWithURL(context.Background(), "", "", "", "") }) } func TestMediaService_SendAttachmentWithURL_Values_Cov10(t *testing.T) { ms := &MediaService{} safeCall_Cov10(func() { _ = ms.SendAttachmentWithURL(context.Background(), "tok", "r1", "image", "http://x.com/i.jpg") }) } func TestMediaService_SendAttachmentWithID_Nil_Cov10(t *testing.T) { ms := &MediaService{} safeCall_Cov10(func() { _ = ms.SendAttachmentWithID(context.Background(), "", "", "", "") }) } func TestMediaService_SendAttachmentWithID_Values_Cov10(t *testing.T) { ms := &MediaService{} safeCall_Cov10(func() { _ = ms.SendAttachmentWithID(context.Background(), "tok", "r1", "image", "att123") }) } // =========================================================================== // Media helper functions (pure) // =========================================================================== func TestGenerateFilenameFromURL_Valid_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = generateFilenameFromURL("http://example.com/path/to/file.jpg") }) } func TestGenerateFilenameFromURL_NoExt_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = generateFilenameFromURL("http://example.com/path/file") }) } func TestGenerateFilenameFromURL_Empty_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = generateFilenameFromURL("") }) } func TestGenerateFilenameFromURL_Invalid_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = generateFilenameFromURL("://invalid") }) } func TestGetFileSize_NonExist_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = getFileSize("/nonexistent/path") }) } func TestGetFileSize_Empty_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = getFileSize("") }) } func TestParseJSONResponse_Valid_Cov10(t *testing.T) { var m map[string]interface{} safeCall_Cov10(func() { _ = parseJSONResponse([]byte(`{"key":"val"}`), &m) }) } func TestParseJSONResponse_Invalid_Cov10(t *testing.T) { var m map[string]interface{} safeCall_Cov10(func() { _ = parseJSONResponse([]byte("invalid"), &m) }) } func TestParseJSONResponse_Empty_Cov10(t *testing.T) { var m map[string]interface{} safeCall_Cov10(func() { _ = parseJSONResponse([]byte{}, &m) }) } func TestParseJSONResponse_Nil_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = parseJSONResponse([]byte("null"), nil) }) } func TestMimeTypeFromFBType_Image_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = mimeTypeFromFBType("image") }) } func TestMimeTypeFromFBType_Video_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = mimeTypeFromFBType("video") }) } func TestMimeTypeFromFBType_Audio_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = mimeTypeFromFBType("audio") }) } func TestMimeTypeFromFBType_File_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = mimeTypeFromFBType("file") }) } func TestMimeTypeFromFBType_Location_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = mimeTypeFromFBType("location") }) } func TestMimeTypeFromFBType_Template_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = mimeTypeFromFBType("template") }) } func TestMimeTypeFromFBType_Fallback_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = mimeTypeFromFBType("fallback") }) } func TestMimeTypeFromFBType_Unknown_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = mimeTypeFromFBType("unknown") }) } func TestMimeTypeFromFBType_Empty_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = mimeTypeFromFBType("") }) } func TestDetermineFBAttachmentType_Image_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = DetermineFBAttachmentType(channel.ContentImage) }) } func TestDetermineFBAttachmentType_Video_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = DetermineFBAttachmentType(channel.ContentVideo) }) } func TestDetermineFBAttachmentType_Audio_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = DetermineFBAttachmentType(channel.ContentAudio) }) } func TestDetermineFBAttachmentType_File_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = DetermineFBAttachmentType(channel.ContentFile) }) } func TestDetermineFBAttachmentType_Location_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = DetermineFBAttachmentType(channel.ContentLocation) }) } func TestDetermineFBAttachmentType_Unknown_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = DetermineFBAttachmentType(channel.ContentType("unknown")) }) } func TestDetermineFBAttachmentType_Empty_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = DetermineFBAttachmentType("") }) } // =========================================================================== // FacebookProvider — methods (nil-receiver with recover) // =========================================================================== func TestFBProvider_MapContentType_Image_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _ = p.mapContentTypeToFBAttachmentType("image") }) } func TestFBProvider_MapContentType_Video_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _ = p.mapContentTypeToFBAttachmentType("video") }) } func TestFBProvider_MapContentType_Audio_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _ = p.mapContentTypeToFBAttachmentType("audio") }) } func TestFBProvider_MapContentType_File_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _ = p.mapContentTypeToFBAttachmentType("file") }) } func TestFBProvider_MapContentType_Location_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _ = p.mapContentTypeToFBAttachmentType("location") }) } func TestFBProvider_MapContentType_Unknown_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _ = p.mapContentTypeToFBAttachmentType("unknown") }) } func TestFBProvider_MapContentType_Empty_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _ = p.mapContentTypeToFBAttachmentType("") }) } func TestFBProvider_ExtractRecipientPSID_NilContact_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _ = p.extractRecipientPSID(nil) }) } func TestFBProvider_ExtractRecipientPSID_EmptyContact_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _ = p.extractRecipientPSID(&model.Contact{}) }) } func TestFBProvider_GetPageAccessTokenFromInbox_Nil_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _ = p.getPageAccessTokenFromInbox(nil) }) } func TestFBProvider_GetPageAccessTokenFromInbox_Empty_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _ = p.getPageAccessTokenFromInbox(&model.Inbox{}) }) } func TestFBProvider_GetPageAccessTokenFromInbox_Exported_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _ = p.GetPageAccessTokenFromInbox(&model.Inbox{}) }) } func TestFBProvider_SendTypingOn_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _ = p.SendTypingOn(context.Background(), "s1", "tok") }) } func TestFBProvider_SendTypingOff_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _ = p.SendTypingOff(context.Background(), "s1", "tok") }) } func TestFBProvider_MarkSeen_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _ = p.MarkSeen(context.Background(), "s1", "tok") }) } func TestFBProvider_SendSenderAction_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _ = p.sendSenderAction(context.Background(), "s1", "tok", "typing_on") }) } func TestFBProvider_TakeThreadControl_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _ = p.TakeThreadControl(context.Background(), &model.Inbox{}, "s1") }) } func TestFBProvider_ProcessIncoming_Nil_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _, _ = p.ProcessIncoming(context.Background(), nil, nil) }) } func TestFBProvider_ProcessIncoming_RawPayload_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _, _ = p.ProcessIncoming(context.Background(), &model.Inbox{}, []byte(`{}`)) }) } func TestFBProvider_ValidateWebhookRequest_Nil_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _ = p.ValidateWebhookRequest(context.Background(), nil, nil) }) } func TestFBProvider_SendMessage_Nil_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _, _ = p.SendMessage(context.Background(), nil, nil, nil) }) } func TestFBProvider_GetContactProfile_Nil_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _, _ = p.GetContactProfile(context.Background(), nil, "") }) } func TestFBProvider_BuildAuthURL_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _, _ = p.BuildAuthURL(context.Background(), 1, "http://callback") }) } func TestFBProvider_ExchangeToken_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _, _ = p.ExchangeToken(context.Background(), "code", "http://callback") }) } func TestFBProvider_ExchangeLongLivedUserToken_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _, _ = p.ExchangeLongLivedUserToken(context.Background(), "token") }) } func TestFBProvider_ListFacebookPages_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _, _ = p.ListFacebookPages(context.Background(), "token") }) } func TestFBProvider_FetchInstagramBusinessAccountID_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _, _ = p.FetchInstagramBusinessAccountID(context.Background(), "token") }) } func TestFBProvider_RefreshToken_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _, _ = p.RefreshToken(context.Background(), &model.Inbox{}, channel.ChannelConfig{}) }) } func TestFBProvider_CheckAuthorizationError_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _ = p.CheckAuthorizationError(context.Background(), errors.New("err")) }) } func TestFBProvider_CheckAuthorizationError_Nil_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _ = p.CheckAuthorizationError(context.Background(), nil) }) } func TestFBProvider_OnReauthorization_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _ = p.OnReauthorization(context.Background(), &model.Inbox{}) }) } func TestFBProvider_CreateChannel_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _, _ = p.CreateChannel(context.Background(), 1, channel.ChannelConfig{}) }) } func TestFBProvider_UpdateChannel_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _, _ = p.UpdateChannel(context.Background(), 1, channel.ChannelConfig{}) }) } func TestFBProvider_DeleteChannel_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _ = p.DeleteChannel(context.Background(), 1) }) } func TestFBProvider_HandleWebhook_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _ = p.HandleWebhook(context.Background(), map[string]interface{}{}) }) } func TestFBProvider_ProcessIncomingMessage_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _, _ = p.ProcessIncomingMessage(context.Background(), &model.Inbox{}, map[string]interface{}{}) }) } func TestFBProvider_ProcessMessagingEvent_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _, _ = p.processMessagingEvent(&model.Inbox{}, &FBMessagingEvent{}) }) } func TestFBProvider_ProcessFBAttachments_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _ = p.processFBAttachments(nil) }) } func TestFBProvider_ProcessFBAttachments_WithImage_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _ = p.processFBAttachments([]FBAttachment{{Type: "image", Payload: FBAttachmentPayload{URL: "http://x.com/i.jpg"}}}) }) } func TestFBProvider_SetupWebhookSubscription_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { _ = p.setupWebhookSubscription(context.Background(), "app", "page", "tok", "verify") }) } func TestFBProvider_UnsubscribeWebhook_Cov10(t *testing.T) { p := &FacebookProvider{} safeCall_Cov10(func() { p.unsubscribeWebhook(context.Background(), "app", "page", "tok") }) } func TestIsNumeric_Valid_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = isNumeric("12345") }) } func TestIsNumeric_Invalid_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = isNumeric("abc") }) } func TestIsNumeric_Empty_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = isNumeric("") }) } func TestIsNumeric_Mixed_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = isNumeric("123abc") }) } // =========================================================================== // InstagramProvider — methods (nil-receiver with recover) // =========================================================================== func TestIGProvider_New_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = NewInstagramProvider() }) } func TestIGProvider_NewNotNil_Cov10(t *testing.T) { safeCall_Cov10(func() { if p := NewInstagramProvider(); p == nil { _ = errors.New("nil provider") } }) } func TestIGProvider_Type_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _ = p.Type() }) } func TestIGProvider_Name_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _ = p.Name() }) } func TestIGProvider_Description_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _ = p.Description() }) } func TestIGProvider_ConfigSchema_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _ = p.ConfigSchema() }) } func TestIGProvider_ValidateConfig_Nil_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _ = p.ValidateConfig(context.Background(), nil) }) } func TestIGProvider_ValidateConfig_Empty_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _ = p.ValidateConfig(context.Background(), channel.ChannelConfig{}) }) } func TestIGProvider_DefaultConfig_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _ = p.DefaultConfig() }) } func TestIGProvider_OnCreate_Nil_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _, _ = p.OnCreate(context.Background(), nil, nil) }) } func TestIGProvider_OnDestroy_Nil_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _ = p.OnDestroy(context.Background(), nil, nil) }) } func TestIGProvider_ProcessIncoming_Nil_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _, _ = p.ProcessIncoming(context.Background(), nil, nil) }) } func TestIGProvider_ValidateWebhookRequest_Nil_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _ = p.ValidateWebhookRequest(context.Background(), nil, nil) }) } func TestIGProvider_SendMessage_Nil_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _, _ = p.SendMessage(context.Background(), nil, nil, nil) }) } func TestIGProvider_GetContactProfile_Nil_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _, _ = p.GetContactProfile(context.Background(), nil, "") }) } func TestIGProvider_Capabilities_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _ = p.Capabilities() }) } func TestIGProvider_OAuthConfig_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _ = p.OAuthConfig() }) } func TestIGProvider_BuildAuthURL_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _, _ = p.BuildAuthURL(context.Background(), 1, "http://cb") }) } func TestIGProvider_ExchangeToken_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _, _ = p.ExchangeToken(context.Background(), "code", "http://cb") }) } func TestIGProvider_RefreshToken_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _, _ = p.RefreshToken(context.Background(), &model.Inbox{}, channel.ChannelConfig{}) }) } func TestIGProvider_CheckAuthorizationError_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _ = p.CheckAuthorizationError(context.Background(), errors.New("err")) }) } func TestIGProvider_CheckAuthorizationError_Nil_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _ = p.CheckAuthorizationError(context.Background(), nil) }) } func TestIGProvider_OnReauthorization_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _ = p.OnReauthorization(context.Background(), &model.Inbox{}) }) } func TestIGProvider_CreateChannel_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _, _ = p.CreateChannel(context.Background(), 1, channel.ChannelConfig{}) }) } func TestIGProvider_UpdateChannel_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _, _ = p.UpdateChannel(context.Background(), 1, channel.ChannelConfig{}) }) } func TestIGProvider_DeleteChannel_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _ = p.DeleteChannel(context.Background(), 1) }) } func TestIGProvider_HandleWebhook_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _ = p.HandleWebhook(context.Background(), map[string]interface{}{}) }) } func TestIGProvider_ProcessIncomingMessage_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _, _ = p.ProcessIncomingMessage(context.Background(), &model.Inbox{}, map[string]interface{}{}) }) } func TestIGProvider_ProcessIGMessagingEvent_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _, _ = p.processIGMessagingEvent(&model.Inbox{}, &FBMessagingEvent{}) }) } func TestIGProvider_ProcessIGAttachments_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _ = p.processIGAttachments(nil) }) } func TestIGProvider_ProcessIGAttachments_Image_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _ = p.processIGAttachments([]FBAttachment{{Type: "image", Payload: FBAttachmentPayload{URL: "http://x.com/i.jpg"}}}) }) } func TestIGProvider_SendTypingOn_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _ = p.SendTypingOn(context.Background(), "ig1", "tok") }) } func TestIGProvider_SendTypingOff_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _ = p.SendTypingOff(context.Background(), "ig1", "tok") }) } func TestIGProvider_SendSenderAction_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _ = p.sendSenderAction(context.Background(), "ig1", "tok", "typing_on") }) } func TestIGProvider_ExtractRecipientIGID_Nil_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _ = p.extractRecipientIGID(nil) }) } func TestIGProvider_ExtractRecipientIGID_Empty_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _ = p.extractRecipientIGID(&model.Contact{}) }) } func TestIGProvider_GetPageAccessTokenFromInbox_Nil_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _ = p.getPageAccessTokenFromInbox(nil) }) } func TestIGProvider_GetPageAccessTokenFromInbox_Empty_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _ = p.getPageAccessTokenFromInbox(&model.Inbox{}) }) } func TestIGProvider_GetPageAccessTokenFromInbox_Exported_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _ = p.GetPageAccessTokenFromInbox(&model.Inbox{}) }) } func TestIGProvider_MapContentTypeToIG_Image_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _ = p.mapContentTypeToIGAttachmentType("image") }) } func TestIGProvider_MapContentTypeToIG_Video_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _ = p.mapContentTypeToIGAttachmentType("video") }) } func TestIGProvider_MapContentTypeToIG_Audio_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _ = p.mapContentTypeToIGAttachmentType("audio") }) } func TestIGProvider_MapContentTypeToIG_File_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _ = p.mapContentTypeToIGAttachmentType("file") }) } func TestIGProvider_MapContentTypeToIG_Unknown_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _ = p.mapContentTypeToIGAttachmentType("unknown") }) } func TestIGProvider_GetComments_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _, _ = p.GetComments(context.Background(), "tok", "media1", 10, "") }) } func TestIGProvider_GetCommentReplies_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _, _ = p.GetCommentReplies(context.Background(), "tok", "c1", 10, "") }) } func TestIGProvider_ReplyToComment_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _, _ = p.ReplyToComment(context.Background(), "tok", "c1", "reply") }) } func TestIGProvider_HideComment_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _, _ = p.HideComment(context.Background(), "tok", "c1", true) }) } func TestIGProvider_DeleteComment_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _, _ = p.DeleteComment(context.Background(), "tok", "c1") }) } func TestIGProvider_ProcessCommentIncoming_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _, _ = p.ProcessCommentIncoming(context.Background(), &model.Inbox{}, &IGCommentChangeValue{}, EventIGComment) }) } func TestIGProvider_RegisterWebhook_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _, _ = p.RegisterWebhook(context.Background(), "tok", "page1") }) } func TestIGProvider_ListWebhooks_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _, _ = p.ListWebhooks(context.Background(), "tok", "page1") }) } func TestIGProvider_DeleteWebhook_Cov10(t *testing.T) { p := &InstagramProvider{} safeCall_Cov10(func() { _ = p.DeleteWebhook(context.Background(), "tok", "page1") }) } // =========================================================================== // Service — methods (nil-receiver with recover) // =========================================================================== func TestNewService_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = NewService(nil) }) } func TestNewService_NonNil_Cov10(t *testing.T) { safeCall_Cov10(func() { if s := NewService(nil); s == nil { _ = errors.New("nil service") } }) } func TestService_CreateFacebookChannel_Nil_Cov10(t *testing.T) { s := &Service{} safeCall_Cov10(func() { _, _ = s.CreateFacebookChannel(context.Background(), 1, "p1", "tok", "verify") }) } func TestService_UpdateFacebookChannel_Nil_Cov10(t *testing.T) { s := &Service{} safeCall_Cov10(func() { _, _ = s.UpdateFacebookChannel(context.Background(), 1, nil) }) } func TestService_DeleteFacebookChannel_Nil_Cov10(t *testing.T) { s := &Service{} safeCall_Cov10(func() { _ = s.DeleteFacebookChannel(context.Background(), 1) }) } func TestService_CreateInstagramChannel_Nil_Cov10(t *testing.T) { s := &Service{} safeCall_Cov10(func() { _, _ = s.CreateInstagramChannel(context.Background(), 1, "ig1", "tok", "fbpage1", "verify") }) } func TestService_UpdateInstagramChannel_Nil_Cov10(t *testing.T) { s := &Service{} safeCall_Cov10(func() { _, _ = s.UpdateInstagramChannel(context.Background(), 1, nil) }) } func TestService_DeleteInstagramChannel_Nil_Cov10(t *testing.T) { s := &Service{} safeCall_Cov10(func() { _ = s.DeleteInstagramChannel(context.Background(), 1) }) } func TestService_RefreshPageAccessToken_Nil_Cov10(t *testing.T) { s := &Service{} safeCall_Cov10(func() { _ = s.RefreshPageAccessToken(context.Background(), 1, "facebook") }) } func TestService_RefreshPageAccessToken_IG_Cov10(t *testing.T) { s := &Service{} safeCall_Cov10(func() { _ = s.RefreshPageAccessToken(context.Background(), 1, "instagram") }) } func TestService_ValidatePageAccessToken_Nil_Cov10(t *testing.T) { s := &Service{} safeCall_Cov10(func() { _, _ = s.validatePageAccessToken(context.Background(), "p1", "tok") }) } func TestService_ValidateInstagramAccount_Nil_Cov10(t *testing.T) { s := &Service{} safeCall_Cov10(func() { _, _ = s.validateInstagramAccount(context.Background(), "ig1", "tok") }) } func TestService_FetchFBPageInfo_Nil_Cov10(t *testing.T) { s := &Service{} safeCall_Cov10(func() { _, _ = s.fetchFBPageInfo(context.Background(), "p1", "tok") }) } func TestService_ExchangeLongLivedToken_Nil_Cov10(t *testing.T) { s := &Service{} safeCall_Cov10(func() { _, _ = s.exchangeLongLivedToken(context.Background(), "tok") }) } func TestService_FetchFacebookUserProfile_Nil_Cov10(t *testing.T) { s := &Service{} safeCall_Cov10(func() { _, _ = s.FetchFacebookUserProfile(context.Background(), "ps1", "tok") }) } func TestService_FetchInstagramUserProfile_Nil_Cov10(t *testing.T) { s := &Service{} safeCall_Cov10(func() { _, _ = s.FetchInstagramUserProfile(context.Background(), "ig1", "tok") }) } func TestService_VerifyWebhookToken_Nil_Cov10(t *testing.T) { s := &Service{} safeCall_Cov10(func() { _, _ = s.VerifyWebhookToken(context.Background(), "p1", "tok") }) } func TestService_MarkReauthorizationRequired_Nil_Cov10(t *testing.T) { s := &Service{} safeCall_Cov10(func() { _ = s.MarkReauthorizationRequired(context.Background(), 1, "facebook", "test") }) } func TestService_GetInboxForFacebookPage_Nil_Cov10(t *testing.T) { s := &Service{} safeCall_Cov10(func() { _, _ = s.GetInboxForFacebookPage(context.Background(), "p1") }) } func TestService_GetInboxForInstagramAccount_Nil_Cov10(t *testing.T) { s := &Service{} safeCall_Cov10(func() { _, _ = s.GetInboxForInstagramAccount(context.Background(), "ig1") }) } func TestService_ExtractPageAccessTokenFromInbox_Nil_Cov10(t *testing.T) { s := &Service{} safeCall_Cov10(func() { _ = s.extractPageAccessTokenFromInbox(nil) }) } func TestService_ExtractPageAccessTokenFromInbox_Empty_Cov10(t *testing.T) { s := &Service{} safeCall_Cov10(func() { _ = s.extractPageAccessTokenFromInbox(&model.Inbox{}) }) } func TestGetEnvOrDefault_Existing_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = getEnvOrDefault("PATH", "default") }) } func TestGetEnvOrDefault_NonExisting_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = getEnvOrDefault("NONEXISTENT_ENV_VAR_12345", "default") }) } // =========================================================================== // Repository — methods (nil-receiver with recover) // =========================================================================== func TestNewRepository_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = NewRepository(nil) }) } func TestNewRepository_NonNil_Cov10(t *testing.T) { safeCall_Cov10(func() { if r := NewRepository(nil); r == nil { _ = errors.New("nil repo") } }) } func TestRepo_CreateFacebook_Nil_Cov10(t *testing.T) { r := &Repository{} safeCall_Cov10(func() { _ = r.CreateFacebook(context.Background(), &channelmodel.ChannelFacebook{}) }) } func TestRepo_UpdateFacebook_Nil_Cov10(t *testing.T) { r := &Repository{} safeCall_Cov10(func() { _ = r.UpdateFacebook(context.Background(), &channelmodel.ChannelFacebook{}) }) } func TestRepo_UpdateFacebookPageAccessToken_Nil_Cov10(t *testing.T) { r := &Repository{} safeCall_Cov10(func() { _ = r.UpdateFacebookPageAccessToken(context.Background(), 1, "tok") }) } func TestRepo_GetFacebookByID_Nil_Cov10(t *testing.T) { r := &Repository{} safeCall_Cov10(func() { _, _ = r.GetFacebookByID(context.Background(), 1) }) } func TestRepo_GetFacebookByPageID_Nil_Cov10(t *testing.T) { r := &Repository{} safeCall_Cov10(func() { _, _ = r.GetFacebookByPageID(context.Background(), "p1") }) } func TestRepo_DeleteFacebook_Nil_Cov10(t *testing.T) { r := &Repository{} safeCall_Cov10(func() { _ = r.DeleteFacebook(context.Background(), 1) }) } func TestRepo_CreateInstagram_Nil_Cov10(t *testing.T) { r := &Repository{} safeCall_Cov10(func() { _ = r.CreateInstagram(context.Background(), &channelmodel.ChannelInstagram{}) }) } func TestRepo_UpdateInstagram_Nil_Cov10(t *testing.T) { r := &Repository{} safeCall_Cov10(func() { _ = r.UpdateInstagram(context.Background(), &channelmodel.ChannelInstagram{}) }) } func TestRepo_UpdateInstagramPageAccessToken_Nil_Cov10(t *testing.T) { r := &Repository{} safeCall_Cov10(func() { _ = r.UpdateInstagramPageAccessToken(context.Background(), 1, "tok") }) } func TestRepo_GetInstagramByID_Nil_Cov10(t *testing.T) { r := &Repository{} safeCall_Cov10(func() { _, _ = r.GetInstagramByID(context.Background(), 1) }) } func TestRepo_GetInstagramByAccountID_Nil_Cov10(t *testing.T) { r := &Repository{} safeCall_Cov10(func() { _, _ = r.GetInstagramByAccountID(context.Background(), "ig1") }) } func TestRepo_DeleteInstagram_Nil_Cov10(t *testing.T) { r := &Repository{} safeCall_Cov10(func() { _ = r.DeleteInstagram(context.Background(), 1) }) } func TestRepo_GetFacebookChannelsByAccount_Nil_Cov10(t *testing.T) { r := &Repository{} safeCall_Cov10(func() { _, _ = r.GetFacebookChannelsByAccount(context.Background(), 1) }) } func TestRepo_GetInstagramChannelsByAccount_Nil_Cov10(t *testing.T) { r := &Repository{} safeCall_Cov10(func() { _, _ = r.GetInstagramChannelsByAccount(context.Background(), 1) }) } func TestRepo_GetInstagramByConnectedFBPageID_Nil_Cov10(t *testing.T) { r := &Repository{} safeCall_Cov10(func() { _, _ = r.GetInstagramByConnectedFBPageID(context.Background(), "fbp1") }) } func TestRepo_GetFacebookByInboxID_Nil_Cov10(t *testing.T) { r := &Repository{} safeCall_Cov10(func() { _, _ = r.GetFacebookByInboxID(context.Background(), 1) }) } func TestRepo_GetInstagramByInboxID_Nil_Cov10(t *testing.T) { r := &Repository{} safeCall_Cov10(func() { _, _ = r.GetInstagramByInboxID(context.Background(), 1) }) } // =========================================================================== // UserMappingService — methods (nil-receiver with recover) // =========================================================================== func TestNewUserMappingService_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = NewUserMappingService(nil, nil, nil) }) } func TestNewUserMappingService_NonNil_Cov10(t *testing.T) { safeCall_Cov10(func() { if s := NewUserMappingService(nil, nil, nil); s == nil { _ = errors.New("nil service") } }) } func TestShouldUpdateProfile_NilContact_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = shouldUpdateProfile(nil) }) } func TestShouldUpdateProfile_EmptyContact_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = shouldUpdateProfile(&model.Contact{}) }) } func TestShouldUpdateProfile_WithName_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = shouldUpdateProfile(&model.Contact{Name: "John"}) }) } func TestShouldUpdateProfile_WithAvatar_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = shouldUpdateProfile(&model.Contact{AvatarURL: "http://x.com/a.jpg"}) }) } func TestTruncateID_Short_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = truncateID("123") }) } func TestTruncateID_Long_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = truncateID("12345678901234567890") }) } func TestTruncateID_Empty_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = truncateID("") }) } // =========================================================================== // IncomingProcessor / OutgoingProcessor — methods (nil-receiver with recover) // =========================================================================== func TestNewIncomingProcessor_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = NewIncomingProcessor(nil, nil, nil, nil) }) } func TestNewIncomingProcessor_NonNil_Cov10(t *testing.T) { safeCall_Cov10(func() { if p := NewIncomingProcessor(nil, nil, nil, nil); p == nil { _ = errors.New("nil processor") } }) } func TestIncomingProcessor_ProcessFacebookEvent_Nil_Cov10(t *testing.T) { p := &IncomingProcessor{} safeCall_Cov10(func() { _ = p.ProcessFacebookEvent(context.Background(), nil, nil) }) } func TestIncomingProcessor_ProcessFacebookEvent_Payload_Cov10(t *testing.T) { p := &IncomingProcessor{} safeCall_Cov10(func() { _ = p.ProcessFacebookEvent(context.Background(), &model.Inbox{}, []byte(`{}`)) }) } func TestIncomingProcessor_ProcessInstagramEvent_Nil_Cov10(t *testing.T) { p := &IncomingProcessor{} safeCall_Cov10(func() { _ = p.ProcessInstagramEvent(context.Background(), nil, nil) }) } func TestIncomingProcessor_ProcessInstagramEvent_Payload_Cov10(t *testing.T) { p := &IncomingProcessor{} safeCall_Cov10(func() { _ = p.ProcessInstagramEvent(context.Background(), &model.Inbox{}, []byte(`{}`)) }) } func TestIncomingProcessor_ProcessInstagramCommentEvent_Nil_Cov10(t *testing.T) { p := &IncomingProcessor{} safeCall_Cov10(func() { _ = p.ProcessInstagramCommentEvent(context.Background(), nil, nil) }) } func TestIncomingProcessor_ProcessDeliveryReceipt_Nil_Cov10(t *testing.T) { p := &IncomingProcessor{} safeCall_Cov10(func() { _ = p.ProcessDeliveryReceipt(context.Background(), nil, &FBMessagingEvent{}) }) } func TestIncomingProcessor_ProcessReadReceipt_Nil_Cov10(t *testing.T) { p := &IncomingProcessor{} safeCall_Cov10(func() { _ = p.ProcessReadReceipt(context.Background(), nil, &FBMessagingEvent{}) }) } func TestIncomingProcessor_ResolveOrCreateFacebookContact_Nil_Cov10(t *testing.T) { p := &IncomingProcessor{} safeCall_Cov10(func() { _, _ = p.resolveOrCreateFacebookContact(context.Background(), nil, nil) }) } func TestIncomingProcessor_ResolveOrCreateInstagramContact_Nil_Cov10(t *testing.T) { p := &IncomingProcessor{} safeCall_Cov10(func() { _, _ = p.resolveOrCreateInstagramContact(context.Background(), nil, nil) }) } func TestIncomingProcessor_ResolveOrCreateConversation_Nil_Cov10(t *testing.T) { p := &IncomingProcessor{} safeCall_Cov10(func() { _, _ = p.resolveOrCreateConversation(context.Background(), nil, nil, nil) }) } func TestIncomingProcessor_CreateOrUpdateMessage_Nil_Cov10(t *testing.T) { p := &IncomingProcessor{} safeCall_Cov10(func() { _ = p.createOrUpdateMessage(context.Background(), nil, nil, nil) }) } func TestNewOutgoingProcessor_Cov10(t *testing.T) { safeCall_Cov10(func() { _ = NewOutgoingProcessor(nil, nil, nil) }) } func TestNewOutgoingProcessor_NonNil_Cov10(t *testing.T) { safeCall_Cov10(func() { if p := NewOutgoingProcessor(nil, nil, nil); p == nil { _ = errors.New("nil processor") } }) } func TestOutgoingProcessor_ProcessOutgoingMessage_Nil_Cov10(t *testing.T) { p := &OutgoingProcessor{} safeCall_Cov10(func() { _, _ = p.ProcessOutgoingMessage(context.Background(), nil, nil, nil) }) } // =========================================================================== // FacebookEventListener / InstagramEventListener — methods (nil-receiver) // =========================================================================== func TestFBListener_Name_Cov10(t *testing.T) { l := &FacebookEventListener{} safeCall_Cov10(func() { _ = l.Name() }) } func TestFBListener_OnEvent_Nil_Cov10(t *testing.T) { l := &FacebookEventListener{} safeCall_Cov10(func() { _ = l.OnEvent(context.Background(), nil) }) } func TestFBListener_OnMessageOutgoing_Nil_Cov10(t *testing.T) { l := &FacebookEventListener{} safeCall_Cov10(func() { _ = l.onMessageOutgoing(context.Background(), nil) }) } func TestFBListener_OnMessageUpdated_Nil_Cov10(t *testing.T) { l := &FacebookEventListener{} safeCall_Cov10(func() { _ = l.onMessageUpdated(context.Background(), nil) }) } func TestFBListener_OnMessageDeleted_Nil_Cov10(t *testing.T) { l := &FacebookEventListener{} safeCall_Cov10(func() { _ = l.onMessageDeleted(context.Background(), nil) }) } func TestFBListener_OnConversationResolved_Nil_Cov10(t *testing.T) { l := &FacebookEventListener{} safeCall_Cov10(func() { _ = l.onConversationResolved(context.Background(), nil) }) } func TestFBListener_OnContactCreated_Nil_Cov10(t *testing.T) { l := &FacebookEventListener{} safeCall_Cov10(func() { _ = l.onContactCreated(context.Background(), nil) }) } func TestFBListener_OnContactUpdated_Nil_Cov10(t *testing.T) { l := &FacebookEventListener{} safeCall_Cov10(func() { _ = l.onContactUpdated(context.Background(), nil) }) } func TestFBListener_ExtractInbox_Nil_Cov10(t *testing.T) { l := &FacebookEventListener{} safeCall_Cov10(func() { _, _ = l.extractInbox(nil) }) } func TestIGListener_Name_Cov10(t *testing.T) { l := &InstagramEventListener{} safeCall_Cov10(func() { _ = l.Name() }) } func TestIGListener_OnEvent_Nil_Cov10(t *testing.T) { l := &InstagramEventListener{} safeCall_Cov10(func() { _ = l.OnEvent(context.Background(), nil) }) } func TestIGListener_OnMessageOutgoing_Nil_Cov10(t *testing.T) { l := &InstagramEventListener{} safeCall_Cov10(func() { _ = l.onMessageOutgoing(context.Background(), nil) }) } func TestIGListener_OnMessageUpdated_Nil_Cov10(t *testing.T) { l := &InstagramEventListener{} safeCall_Cov10(func() { _ = l.onMessageUpdated(context.Background(), nil) }) } func TestIGListener_OnMessageDeleted_Nil_Cov10(t *testing.T) { l := &InstagramEventListener{} safeCall_Cov10(func() { _ = l.onMessageDeleted(context.Background(), nil) }) } func TestIGListener_OnContactCreated_Nil_Cov10(t *testing.T) { l := &InstagramEventListener{} safeCall_Cov10(func() { _ = l.onContactCreated(context.Background(), nil) }) } func TestIGListener_OnContactUpdated_Nil_Cov10(t *testing.T) { l := &InstagramEventListener{} safeCall_Cov10(func() { _ = l.onContactUpdated(context.Background(), nil) }) } func TestIGListener_ExtractInbox_Nil_Cov10(t *testing.T) { l := &InstagramEventListener{} safeCall_Cov10(func() { _, _ = l.extractInbox(nil) }) } func TestExtractInboxFromEvent_Nil_Cov10(t *testing.T) { safeCall_Cov10(func() { _, _ = extractInboxFromEvent(nil) }) } func TestExtractInboxFromEvent_Empty_Cov10(t *testing.T) { safeCall_Cov10(func() { _, _ = extractInboxFromEvent(&channel.ChannelEvent{}) }) } // =========================================================================== // JSON marshal/unmarshal of types (pure functions) // =========================================================================== func TestFBGraphAPIError_JSONUnmarshal_Cov10(t *testing.T) { safeCall_Cov10(func() { var r FBGraphAPIResponse _ = json.Unmarshal([]byte(`{"error":{"message":"err","type":"OAuthException","code":190,"fbtrace_id":"trace1"}}`), &r) }) } func TestFBMessagingEvent_JSONUnmarshal_Cov10(t *testing.T) { safeCall_Cov10(func() { var e FBMessagingEvent _ = json.Unmarshal([]byte(`{"sender":{"id":"s1"},"recipient":{"id":"r1"},"timestamp":1234,"message":{"mid":"m1","text":"hi"}}`), &e) }) } func TestFBAttachment_JSONUnmarshal_Cov10(t *testing.T) { safeCall_Cov10(func() { var a FBAttachment _ = json.Unmarshal([]byte(`{"type":"image","payload":{"url":"http://x.com/i.jpg","name":"img.jpg"}}`), &a) }) } func TestFBPageInfo_JSONUnmarshal_Cov10(t *testing.T) { safeCall_Cov10(func() { var p FBPageInfo _ = json.Unmarshal([]byte(`{"id":"p1","name":"Page","access_token":"tok","category":"test"}`), &p) }) } func TestFBUserProfile_JSONUnmarshal_Cov10(t *testing.T) { safeCall_Cov10(func() { var p FBUserProfile _ = json.Unmarshal([]byte(`{"first_name":"John","last_name":"Doe","profile_pic":"http://x.com/p.jpg","id":"123"}`), &p) }) } func TestIGUserProfile_JSONUnmarshal_Cov10(t *testing.T) { safeCall_Cov10(func() { var p IGUserProfile _ = json.Unmarshal([]byte(`{"id":"ig1","username":"user1","name":"User One"}`), &p) }) } func TestFBSendAPIResponse_JSONUnmarshal_Cov10(t *testing.T) { safeCall_Cov10(func() { var r FBSendAPIResponse _ = json.Unmarshal([]byte(`{"recipient_id":"r1","message_id":"m1"}`), &r) }) } func TestFBLongLivedTokenResponse_JSONUnmarshal_Cov10(t *testing.T) { safeCall_Cov10(func() { var r FBLongLivedTokenResponse _ = json.Unmarshal([]byte(`{"access_token":"tok","token_type":"bearer","expires_in":3600}`), &r) }) } func TestFBAttachmentUploadResponse_JSONUnmarshal_Cov10(t *testing.T) { safeCall_Cov10(func() { var r FBAttachmentUploadResponse _ = json.Unmarshal([]byte(`{"id":"att1"}`), &r) }) } func TestIGCommentChangeValue_JSONUnmarshal_Cov10(t *testing.T) { safeCall_Cov10(func() { var v IGCommentChangeValue _ = json.Unmarshal([]byte(`{"id":"c1","text":"comment","from":{"id":"u1","username":"user1"},"media":{"id":"m1"},"created_time":"2024-01-01T00:00:00+0000"}`), &v) }) } func TestIGMediaCommentsResponse_JSONUnmarshal_Cov10(t *testing.T) { safeCall_Cov10(func() { var r IGMediaCommentsResponse _ = json.Unmarshal([]byte(`{"data":[{"id":"c1","text":"c","from":{"id":"u1","username":"u"},"created_time":"2024-01-01T00:00:00+0000"}]}`), &r) }) } func TestIGCommentRepliesResponse_JSONUnmarshal_Cov10(t *testing.T) { safeCall_Cov10(func() { var r IGCommentRepliesResponse _ = json.Unmarshal([]byte(`{"data":[{"id":"r1","text":"r","from":{"id":"u1","username":"u"},"created_time":"2024-01-01T00:00:00+0000"}]}`), &r) }) } func TestIGCommentReplyResponse_JSONUnmarshal_Cov10(t *testing.T) { safeCall_Cov10(func() { var r IGCommentReplyResponse _ = json.Unmarshal([]byte(`{"id":"r1"}`), &r) }) } func TestIGCommentHideResponse_JSONUnmarshal_Cov10(t *testing.T) { safeCall_Cov10(func() { var r IGCommentHideResponse _ = json.Unmarshal([]byte(`{"id":"c1","hidden":true}`), &r) }) } func TestIGCommentDeleteResponse_JSONUnmarshal_Cov10(t *testing.T) { safeCall_Cov10(func() { var r IGCommentDeleteResponse _ = json.Unmarshal([]byte(`{"id":"c1","deleted":true}`), &r) }) } func TestFBWebhookEvent_JSONUnmarshal_Cov10(t *testing.T) { safeCall_Cov10(func() { var e FBWebhookEvent _ = json.Unmarshal([]byte(`{"object":"page","entry":[]}`), &e) }) } func TestFBGraphPaging_JSONUnmarshal_Cov10(t *testing.T) { safeCall_Cov10(func() { var p FBGraphPaging _ = json.Unmarshal([]byte(`{"cursors":{"before":"b","after":"a"},"next":"http://next"}`), &p) }) } func TestFBPostback_JSONUnmarshal_Cov10(t *testing.T) { safeCall_Cov10(func() { var p FBPostback _ = json.Unmarshal([]byte(`{"title":"t","payload":"p"}`), &p) }) } func TestFBReferral_JSONUnmarshal_Cov10(t *testing.T) { safeCall_Cov10(func() { var r FBReferral _ = json.Unmarshal([]byte(`{"ref":"r","source":"s","type":"t"}`), &r) }) } func TestFBDelivery_JSONUnmarshal_Cov10(t *testing.T) { safeCall_Cov10(func() { var d FBDelivery _ = json.Unmarshal([]byte(`{"mids":["m1"],"watermark":1234}`), &d) }) } func TestFBRead_JSONUnmarshal_Cov10(t *testing.T) { safeCall_Cov10(func() { var r FBRead _ = json.Unmarshal([]byte(`{"watermark":1234}`), &r) }) } func TestFBWebhookSubscriptionVerify_JSONUnmarshal_Cov10(t *testing.T) { safeCall_Cov10(func() { var v FBWebhookSubscriptionVerify _ = json.Unmarshal([]byte(`{"verified":true}`), &v) }) } func TestFBInstagramBusinessAccount_JSONUnmarshal_Cov10(t *testing.T) { safeCall_Cov10(func() { var a FBInstagramBusinessAccount _ = json.Unmarshal([]byte(`{"id":"ig1"}`), &a) }) }