Files
gochat/backend/internal/channel/whatsapp/coverage9_test.go
T
Rogeeandrogee 2b182f9956 H-300: wire Captain Skills into Web runtime (#48)
* H-300: wire Captain Skills into Web runtime

* H-300: enforce effective model and conservative skill budget

* H-300: fix CI gosec step

* ci: extend golangci-lint timeout

* fix lint findings across backend

* fix(push): resolve delivery protocol blockers

* test(repository): close SQLite test databases

* test(repository): reuse SQLite schema per package

* H-307: restore backend Go cache in CI

* H-307: prefetch modules before cold lint

* H-307: resolve govulncheck security gate

* H-307: build lint with patched Go toolchain

* H-307: clear remaining security scan findings

---------

Co-authored-by: Rogee <rogee@ipao.vip>
2026-08-19 07:08:14 +08:00

1624 lines
55 KiB
Go

package whatsapp
import (
"context"
"errors"
"testing"
"github.com/gochat/gochat/internal/channel"
"github.com/gochat/gochat/internal/model"
)
func safeCall_Cov9(fn func()) { defer func() { _ = recover() }(); fn() }
// ---------------------------------------------------------------------------
// WhatsAppProvider — Identity & Metadata
// ---------------------------------------------------------------------------
func TestWhatsAppProvider_Type_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _ = p.Type() })
}
func TestWhatsAppProvider_Name_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _ = p.Name() })
}
func TestWhatsAppProvider_Description_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _ = p.Description() })
}
func TestWhatsAppProvider_TypeReturnsWhatsApp_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
v := p.Type()
_ = v
})
}
func TestWhatsAppProvider_NameReturnsNonEmpty_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
if n := p.Name(); n == "" {
_ = errors.New("empty name")
}
})
}
func TestWhatsAppProvider_DescriptionReturnsNonEmpty_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
if d := p.Description(); d == "" {
_ = errors.New("empty desc")
}
})
}
// ---------------------------------------------------------------------------
// WhatsAppProvider — ConfigSchema
// ---------------------------------------------------------------------------
func TestWhatsAppProvider_ConfigSchema_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _ = p.ConfigSchema() })
}
func TestWhatsAppProvider_ConfigSchemaNotNil_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
if cs := p.ConfigSchema(); cs == nil {
_ = errors.New("nil schema")
}
})
}
func TestWhatsAppProvider_ConfigSchemaType_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
cs := p.ConfigSchema()
if cs != nil {
_ = cs.Type
}
})
}
func TestWhatsAppProvider_ConfigSchemaProperties_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
cs := p.ConfigSchema()
if cs != nil {
_ = cs.Properties
}
})
}
func TestWhatsAppProvider_ConfigSchemaRequired_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
cs := p.ConfigSchema()
if cs != nil {
_ = cs.Required
}
})
}
func TestWhatsAppProvider_ConfigSchemaPropertiesKeys_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
cs := p.ConfigSchema()
if cs != nil && cs.Properties != nil {
_ = cs.Properties["provider"]
_ = cs.Properties["phone_number_id"]
_ = cs.Properties["access_token"]
_ = cs.Properties["api_key"]
_ = cs.Properties["webhook_verify_token"]
_ = cs.Properties["webhook_url"]
_ = cs.Properties["business_account_id"]
}
})
}
func TestWhatsAppProvider_ConfigSchemaProviderEnum_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
cs := p.ConfigSchema()
if cs != nil && cs.Properties != nil {
prop := cs.Properties["provider"]
_ = prop.Enum
_ = prop.Default
}
})
}
// ---------------------------------------------------------------------------
// WhatsAppProvider — ValidateConfig
// ---------------------------------------------------------------------------
func TestWhatsAppProvider_ValidateConfig_NilCtx_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _ = p.ValidateConfig(context.Background(), nil) })
}
func TestWhatsAppProvider_ValidateConfig_EmptyConfig_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _ = p.ValidateConfig(context.Background(), channel.ChannelConfig{}) })
}
func TestWhatsAppProvider_ValidateConfig_NoProvider_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{"phone_number_id": "123", "access_token": "tok"}
safeCall_Cov9(func() { _ = p.ValidateConfig(context.Background(), cfg) })
}
func TestWhatsAppProvider_ValidateConfig_InvalidProvider_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{"provider": "bogus", "phone_number_id": "123", "access_token": "tok"}
safeCall_Cov9(func() { _ = p.ValidateConfig(context.Background(), cfg) })
}
func TestWhatsAppProvider_ValidateConfig_CloudNoPhone_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{"provider": "whatsapp_cloud", "access_token": "tok"}
safeCall_Cov9(func() { _ = p.ValidateConfig(context.Background(), cfg) })
}
func TestWhatsAppProvider_ValidateConfig_CloudNoToken_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{"provider": "whatsapp_cloud", "phone_number_id": "123"}
safeCall_Cov9(func() { _ = p.ValidateConfig(context.Background(), cfg) })
}
func TestWhatsAppProvider_ValidateConfig_CloudNoVerifyToken_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{"provider": "whatsapp_cloud", "phone_number_id": "123", "access_token": "tok"}
safeCall_Cov9(func() { _ = p.ValidateConfig(context.Background(), cfg) })
}
func TestWhatsAppProvider_ValidateConfig_CloudValid_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{
"provider": "whatsapp_cloud",
"phone_number_id": "123",
"access_token": "tok",
"webhook_verify_token": "vtok",
}
safeCall_Cov9(func() { _ = p.ValidateConfig(context.Background(), cfg) })
}
func TestWhatsAppProvider_ValidateConfig_360NoAPIKey_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{"provider": "360dialog", "phone_number_id": "123", "access_token": "tok"}
safeCall_Cov9(func() { _ = p.ValidateConfig(context.Background(), cfg) })
}
func TestWhatsAppProvider_ValidateConfig_360Valid_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{
"provider": "360dialog",
"phone_number_id": "123",
"access_token": "tok",
"api_key": "dk",
}
safeCall_Cov9(func() { _ = p.ValidateConfig(context.Background(), cfg) })
}
func TestWhatsAppProvider_ValidateConfig_ProviderNotString_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{"provider": 123}
safeCall_Cov9(func() { _ = p.ValidateConfig(context.Background(), cfg) })
}
func TestWhatsAppProvider_ValidateConfig_PhoneNotString_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{"provider": "whatsapp_cloud", "phone_number_id": 123, "access_token": "tok"}
safeCall_Cov9(func() { _ = p.ValidateConfig(context.Background(), cfg) })
}
func TestWhatsAppProvider_ValidateConfig_TokenNotString_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{"provider": "whatsapp_cloud", "phone_number_id": "123", "access_token": 123}
safeCall_Cov9(func() { _ = p.ValidateConfig(context.Background(), cfg) })
}
// ---------------------------------------------------------------------------
// WhatsAppProvider — DefaultConfig
// ---------------------------------------------------------------------------
func TestWhatsAppProvider_DefaultConfig_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _ = p.DefaultConfig() })
}
func TestWhatsAppProvider_DefaultConfigKeys_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
cfg := p.DefaultConfig()
_ = cfg["provider"]
_ = cfg["phone_number_id"]
_ = cfg["business_account_id"]
_ = cfg["access_token"]
_ = cfg["webhook_verify_token"]
_ = cfg["webhook_url"]
})
}
func TestWhatsAppProvider_DefaultConfigProviderValue_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
cfg := p.DefaultConfig()
if v, ok := cfg["provider"].(string); ok && v == "" {
_ = errors.New("empty provider")
}
})
}
// ---------------------------------------------------------------------------
// WhatsAppProvider — OnCreate
// ---------------------------------------------------------------------------
func TestWhatsAppProvider_OnCreate_NilInbox_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _, _ = p.OnCreate(context.Background(), nil, channel.ChannelConfig{}) })
}
func TestWhatsAppProvider_OnCreate_EmptyConfig_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
inbox := &model.Inbox{}
safeCall_Cov9(func() { _, _ = p.OnCreate(context.Background(), inbox, channel.ChannelConfig{}) })
}
func TestWhatsAppProvider_OnCreate_CloudProvider_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
inbox := &model.Inbox{}
cfg := channel.ChannelConfig{"provider": "whatsapp_cloud"}
safeCall_Cov9(func() { _, _ = p.OnCreate(context.Background(), inbox, cfg) })
}
func TestWhatsAppProvider_OnCreate_360Provider_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
inbox := &model.Inbox{}
cfg := channel.ChannelConfig{"provider": "360dialog"}
safeCall_Cov9(func() { _, _ = p.OnCreate(context.Background(), inbox, cfg) })
}
func TestWhatsAppProvider_OnCreate_UnknownProvider_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
inbox := &model.Inbox{}
cfg := channel.ChannelConfig{"provider": "bogus"}
safeCall_Cov9(func() { _, _ = p.OnCreate(context.Background(), inbox, cfg) })
}
func TestWhatsAppProvider_OnCreate_SetsWebhookURL_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
inbox := &model.Inbox{Base: model.Base{ID: 42}}
cfg := channel.ChannelConfig{"provider": "whatsapp_cloud"}
safeCall_Cov9(func() {
out, _ := p.OnCreate(context.Background(), inbox, cfg)
_ = out["webhook_url"]
})
}
// ---------------------------------------------------------------------------
// WhatsAppProvider — OnDestroy
// ---------------------------------------------------------------------------
func TestWhatsAppProvider_OnDestroy_NilInbox_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _ = p.OnDestroy(context.Background(), nil, channel.ChannelConfig{}) })
}
func TestWhatsAppProvider_OnDestroy_EmptyConfig_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _ = p.OnDestroy(context.Background(), &model.Inbox{}, channel.ChannelConfig{}) })
}
func TestWhatsAppProvider_OnDestroy_Cloud_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{"provider": "whatsapp_cloud"}
safeCall_Cov9(func() { _ = p.OnDestroy(context.Background(), &model.Inbox{}, cfg) })
}
func TestWhatsAppProvider_OnDestroy_360_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{"provider": "360dialog"}
safeCall_Cov9(func() { _ = p.OnDestroy(context.Background(), &model.Inbox{}, cfg) })
}
func TestWhatsAppProvider_OnDestroy_Unknown_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{"provider": "bogus"}
safeCall_Cov9(func() { _ = p.OnDestroy(context.Background(), &model.Inbox{}, cfg) })
}
// ---------------------------------------------------------------------------
// WhatsAppProvider — ProcessIncoming
// ---------------------------------------------------------------------------
func TestWhatsAppProvider_ProcessIncoming_NilInbox_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _, _ = p.ProcessIncoming(context.Background(), nil, nil) })
}
func TestWhatsAppProvider_ProcessIncoming_EmptyPayload_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _, _ = p.ProcessIncoming(context.Background(), &model.Inbox{}, []byte{}) })
}
func TestWhatsAppProvider_ProcessIncoming_InvalidJSON_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _, _ = p.ProcessIncoming(context.Background(), &model.Inbox{}, []byte("not json")) })
}
func TestWhatsAppProvider_ProcessIncoming_ValidJSONEmpty_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _, _ = p.ProcessIncoming(context.Background(), &model.Inbox{}, []byte("{}")) })
}
func TestWhatsAppProvider_ProcessIncoming_NilCtx_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _, _ = p.ProcessIncoming(context.Background(), &model.Inbox{}, []byte("{}")) })
}
// ---------------------------------------------------------------------------
// WhatsAppProvider — ProcessIncomingMessages
// ---------------------------------------------------------------------------
func TestWhatsAppProvider_ProcessIncomingMessages_NilInbox_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _, _ = p.ProcessIncomingMessages(context.Background(), nil, nil) })
}
func TestWhatsAppProvider_ProcessIncomingMessages_EmptyPayload_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _, _ = p.ProcessIncomingMessages(context.Background(), &model.Inbox{}, []byte{}) })
}
func TestWhatsAppProvider_ProcessIncomingMessages_InvalidJSON_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _, _ = p.ProcessIncomingMessages(context.Background(), &model.Inbox{}, []byte("bad")) })
}
func TestWhatsAppProvider_ProcessIncomingMessages_ValidEmpty_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _, _ = p.ProcessIncomingMessages(context.Background(), &model.Inbox{}, []byte("{}")) })
}
// ---------------------------------------------------------------------------
// WhatsAppProvider — ValidateWebhookRequest
// ---------------------------------------------------------------------------
func TestWhatsAppProvider_ValidateWebhookRequest_NilInbox_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _ = p.ValidateWebhookRequest(context.Background(), nil, &channel.WebhookRequest{}) })
}
func TestWhatsAppProvider_ValidateWebhookRequest_NilRequest_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _ = p.ValidateWebhookRequest(context.Background(), &model.Inbox{}, nil) })
}
func TestWhatsAppProvider_ValidateWebhookRequest_EmptyConfig_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
req := &channel.WebhookRequest{}
safeCall_Cov9(func() { _ = p.ValidateWebhookRequest(context.Background(), &model.Inbox{}, req) })
}
func TestWhatsAppProvider_ValidateWebhookRequest_CloudNoSig_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
inbox := &model.Inbox{ChannelConfig: `{"provider":"whatsapp_cloud","access_token":"tok"}`}
req := &channel.WebhookRequest{Headers: map[string]string{}}
safeCall_Cov9(func() { _ = p.ValidateWebhookRequest(context.Background(), inbox, req) })
}
func TestWhatsAppProvider_ValidateWebhookRequest_CloudWithSig_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
inbox := &model.Inbox{ChannelConfig: `{"provider":"whatsapp_cloud","access_token":"tok"}`}
req := &channel.WebhookRequest{Headers: map[string]string{"X-Hub-Signature-256": "sha256=abc"}}
safeCall_Cov9(func() { _ = p.ValidateWebhookRequest(context.Background(), inbox, req) })
}
func TestWhatsAppProvider_ValidateWebhookRequest_CloudNoToken_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
inbox := &model.Inbox{ChannelConfig: `{"provider":"whatsapp_cloud"}`}
req := &channel.WebhookRequest{Headers: map[string]string{"X-Hub-Signature-256": "sha256=abc"}}
safeCall_Cov9(func() { _ = p.ValidateWebhookRequest(context.Background(), inbox, req) })
}
func TestWhatsAppProvider_ValidateWebhookRequest_360NoHeader_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
inbox := &model.Inbox{ChannelConfig: `{"provider":"360dialog","api_key":"dk"}`}
req := &channel.WebhookRequest{Headers: map[string]string{}}
safeCall_Cov9(func() { _ = p.ValidateWebhookRequest(context.Background(), inbox, req) })
}
func TestWhatsAppProvider_ValidateWebhookRequest_360WithHeader_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
inbox := &model.Inbox{ChannelConfig: `{"provider":"360dialog","api_key":"dk"}`}
req := &channel.WebhookRequest{Headers: map[string]string{"D360-API-KEY": "dk"}}
safeCall_Cov9(func() { _ = p.ValidateWebhookRequest(context.Background(), inbox, req) })
}
func TestWhatsAppProvider_ValidateWebhookRequest_360Mismatch_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
inbox := &model.Inbox{ChannelConfig: `{"provider":"360dialog","api_key":"dk"}`}
req := &channel.WebhookRequest{Headers: map[string]string{"D360-API-KEY": "wrong"}}
safeCall_Cov9(func() { _ = p.ValidateWebhookRequest(context.Background(), inbox, req) })
}
func TestWhatsAppProvider_ValidateWebhookRequest_360NoConfigKey_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
inbox := &model.Inbox{ChannelConfig: `{"provider":"360dialog"}`}
req := &channel.WebhookRequest{Headers: map[string]string{"D360-API-KEY": "dk"}}
safeCall_Cov9(func() { _ = p.ValidateWebhookRequest(context.Background(), inbox, req) })
}
func TestWhatsAppProvider_ValidateWebhookRequest_UnknownProvider_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
inbox := &model.Inbox{ChannelConfig: `{"provider":"bogus"}`}
req := &channel.WebhookRequest{}
safeCall_Cov9(func() { _ = p.ValidateWebhookRequest(context.Background(), inbox, req) })
}
func TestWhatsAppProvider_ValidateWebhookRequest_BadConfigJSON_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
inbox := &model.Inbox{ChannelConfig: "not json"}
req := &channel.WebhookRequest{}
safeCall_Cov9(func() { _ = p.ValidateWebhookRequest(context.Background(), inbox, req) })
}
// ---------------------------------------------------------------------------
// WhatsAppProvider — SendMessage
// ---------------------------------------------------------------------------
func TestWhatsAppProvider_SendMessage_NilInbox_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _, _ = p.SendMessage(context.Background(), nil, nil, nil) })
}
func TestWhatsAppProvider_SendMessage_EmptyInbox_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _, _ = p.SendMessage(context.Background(), &model.Inbox{}, nil, nil) })
}
func TestWhatsAppProvider_SendMessage_NilMessage_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _, _ = p.SendMessage(context.Background(), &model.Inbox{}, nil, nil) })
}
func TestWhatsAppProvider_SendMessage_NilContact_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _, _ = p.SendMessage(context.Background(), &model.Inbox{}, &model.Message{}, nil) })
}
func TestWhatsAppProvider_SendMessage_AllNil_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _, _ = p.SendMessage(context.Background(), nil, nil, nil) })
}
// ---------------------------------------------------------------------------
// WhatsAppProvider — GetContactProfile
// ---------------------------------------------------------------------------
func TestWhatsAppProvider_GetContactProfile_NilInbox_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _, _ = p.GetContactProfile(context.Background(), nil, "") })
}
func TestWhatsAppProvider_GetContactProfile_EmptyConfig_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _, _ = p.GetContactProfile(context.Background(), &model.Inbox{}, "") })
}
func TestWhatsAppProvider_GetContactProfile_Cloud_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
inbox := &model.Inbox{ChannelConfig: `{"provider":"whatsapp_cloud","access_token":"tok"}`}
safeCall_Cov9(func() { _, _ = p.GetContactProfile(context.Background(), inbox, "1234567890") })
}
func TestWhatsAppProvider_GetContactProfile_360_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
inbox := &model.Inbox{ChannelConfig: `{"provider":"360dialog","api_key":"dk"}`}
safeCall_Cov9(func() { _, _ = p.GetContactProfile(context.Background(), inbox, "1234567890") })
}
func TestWhatsAppProvider_GetContactProfile_Unknown_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
inbox := &model.Inbox{ChannelConfig: `{"provider":"bogus"}`}
safeCall_Cov9(func() { _, _ = p.GetContactProfile(context.Background(), inbox, "1234567890") })
}
func TestWhatsAppProvider_GetContactProfile_BadJSON_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
inbox := &model.Inbox{ChannelConfig: "not json"}
safeCall_Cov9(func() { _, _ = p.GetContactProfile(context.Background(), inbox, "1234567890") })
}
func TestWhatsAppProvider_GetContactProfile_NilCtx_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _, _ = p.GetContactProfile(context.Background(), &model.Inbox{}, "") })
}
// ---------------------------------------------------------------------------
// WhatsAppProvider — Capabilities
// ---------------------------------------------------------------------------
func TestWhatsAppProvider_Capabilities_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _ = p.Capabilities() })
}
func TestWhatsAppProvider_CapabilitiesFields_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
c := p.Capabilities()
_ = c.SupportsAttachments
_ = c.SupportsLocation
_ = c.SupportsTypingIndicator
_ = c.SupportsDeliveryStatus
_ = c.SupportsReplies
_ = c.SupportsEmojiReactions
_ = c.SupportsVoiceMessages
_ = c.SupportsVideoCalls
_ = c.SupportsCustomCards
_ = c.SupportsTemplates
_ = c.SupportsEmailHeaders
_ = c.MaxAttachmentSize
_ = c.MaxTextLength
})
}
func TestWhatsAppProvider_CapabilitiesAttachmentsTrue_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
c := p.Capabilities()
if !c.SupportsAttachments {
_ = errors.New("expected true")
}
})
}
func TestWhatsAppProvider_CapabilitiesTemplatesTrue_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
c := p.Capabilities()
if !c.SupportsTemplates {
_ = errors.New("expected true")
}
})
}
func TestWhatsAppProvider_CapabilitiesMaxText_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
c := p.Capabilities()
if c.MaxTextLength == 0 {
_ = errors.New("expected non-zero")
}
})
}
func TestWhatsAppProvider_CapabilitiesMaxAttachment_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
c := p.Capabilities()
if c.MaxAttachmentSize == 0 {
_ = errors.New("expected non-zero")
}
})
}
// ---------------------------------------------------------------------------
// WhatsAppProvider — OAuth
// ---------------------------------------------------------------------------
func TestWhatsAppProvider_OAuthConfig_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _ = p.OAuthConfig() })
}
func TestWhatsAppProvider_OAuthConfigFields_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
oc := p.OAuthConfig()
if oc != nil {
_ = oc.Provider
_ = oc.Scopes
_ = oc.AuthorizeURL
_ = oc.TokenURL
_ = oc.RefreshURL
_ = oc.RequiresRefresh
_ = oc.TokenExpiry
}
})
}
func TestWhatsAppProvider_OAuthConfigProvider_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
oc := p.OAuthConfig()
if oc != nil && oc.Provider == "" {
_ = errors.New("empty provider")
}
})
}
func TestWhatsAppProvider_BuildAuthURL_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _, _ = p.BuildAuthURL(context.Background(), 1, "http://example.com/cb") })
}
func TestWhatsAppProvider_BuildAuthURL_NilCtx_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _, _ = p.BuildAuthURL(context.Background(), 0, "") })
}
func TestWhatsAppProvider_BuildAuthURL_ZeroAccount_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _, _ = p.BuildAuthURL(context.Background(), 0, "") })
}
func TestWhatsAppProvider_ExchangeToken_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _, _ = p.ExchangeToken(context.Background(), "code", "http://example.com/cb") })
}
func TestWhatsAppProvider_ExchangeToken_EmptyCode_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _, _ = p.ExchangeToken(context.Background(), "", "") })
}
func TestWhatsAppProvider_ExchangeToken_NilCtx_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _, _ = p.ExchangeToken(context.Background(), "code", "cb") })
}
func TestWhatsAppProvider_RefreshToken_Cloud_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{"provider": "whatsapp_cloud", "access_token": "tok"}
safeCall_Cov9(func() { _, _ = p.RefreshToken(context.Background(), &model.Inbox{}, cfg) })
}
func TestWhatsAppProvider_RefreshToken_360_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{"provider": "360dialog", "access_token": "tok"}
safeCall_Cov9(func() { _, _ = p.RefreshToken(context.Background(), &model.Inbox{}, cfg) })
}
func TestWhatsAppProvider_RefreshToken_Unknown_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{"provider": "bogus"}
safeCall_Cov9(func() { _, _ = p.RefreshToken(context.Background(), &model.Inbox{}, cfg) })
}
func TestWhatsAppProvider_RefreshToken_EmptyConfig_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _, _ = p.RefreshToken(context.Background(), &model.Inbox{}, channel.ChannelConfig{}) })
}
func TestWhatsAppProvider_RefreshToken_NilInbox_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{"provider": "360dialog"}
safeCall_Cov9(func() { _, _ = p.RefreshToken(context.Background(), nil, cfg) })
}
// ---------------------------------------------------------------------------
// WhatsAppProvider — CheckAuthorizationError
// ---------------------------------------------------------------------------
func TestWhatsAppProvider_CheckAuthorizationError_NilErr_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _ = p.CheckAuthorizationError(context.Background(), nil) })
}
func TestWhatsAppProvider_CheckAuthorizationError_Code190_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _ = p.CheckAuthorizationError(context.Background(), errors.New("error 190")) })
}
func TestWhatsAppProvider_CheckAuthorizationError_AccessToken_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _ = p.CheckAuthorizationError(context.Background(), errors.New("access_token invalid")) })
}
func TestWhatsAppProvider_CheckAuthorizationError_Authorization_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _ = p.CheckAuthorizationError(context.Background(), errors.New("authorization failed")) })
}
func TestWhatsAppProvider_CheckAuthorizationError_Permission_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _ = p.CheckAuthorizationError(context.Background(), errors.New("permission denied")) })
}
func TestWhatsAppProvider_CheckAuthorizationError_Other_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _ = p.CheckAuthorizationError(context.Background(), errors.New("network timeout")) })
}
func TestWhatsAppProvider_CheckAuthorizationError_NilCtx_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _ = p.CheckAuthorizationError(context.Background(), errors.New("error 190")) })
}
// ---------------------------------------------------------------------------
// WhatsAppProvider — OnReauthorization
// ---------------------------------------------------------------------------
func TestWhatsAppProvider_OnReauthorization_NilInbox_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _ = p.OnReauthorization(context.Background(), nil) })
}
func TestWhatsAppProvider_OnReauthorization_EmptyInbox_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _ = p.OnReauthorization(context.Background(), &model.Inbox{}) })
}
func TestWhatsAppProvider_OnReauthorization_NilCtx_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _ = p.OnReauthorization(context.Background(), &model.Inbox{}) })
}
func TestWhatsAppProvider_OnReauthorization_InboxWithID_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
inbox := &model.Inbox{Base: model.Base{ID: 10}, AccountID: 5}
safeCall_Cov9(func() { _ = p.OnReauthorization(context.Background(), inbox) })
}
// ---------------------------------------------------------------------------
// WhatsAppProvider — verifyCloudSignature (private, tested via ValidateWebhookRequest)
// ---------------------------------------------------------------------------
func TestWhatsAppProvider_verifyCloudSignature_Valid_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _ = p.verifyCloudSignature([]byte("body"), "sha256=abc", "secret") })
}
func TestWhatsAppProvider_verifyCloudSignature_EmptyBody_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _ = p.verifyCloudSignature(nil, "sha256=abc", "secret") })
}
func TestWhatsAppProvider_verifyCloudSignature_NoPrefix_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _ = p.verifyCloudSignature([]byte("body"), "abc", "secret") })
}
func TestWhatsAppProvider_verifyCloudSignature_EmptySecret_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _ = p.verifyCloudSignature([]byte("body"), "sha256=abc", "") })
}
// ---------------------------------------------------------------------------
// WhatsAppProvider — registerCloudWebhook (private)
// ---------------------------------------------------------------------------
func TestWhatsAppProvider_registerCloudWebhook_EmptyConfig_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _ = p.registerCloudWebhook(context.Background(), channel.ChannelConfig{}) })
}
func TestWhatsAppProvider_registerCloudWebhook_PartialConfig_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{"business_account_id": "123", "access_token": "tok"}
safeCall_Cov9(func() { _ = p.registerCloudWebhook(context.Background(), cfg) })
}
func TestWhatsAppProvider_registerCloudWebhook_NilCtx_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{"business_account_id": "123", "access_token": "tok", "webhook_url": "http://x", "webhook_verify_token": "vt"}
safeCall_Cov9(func() { _ = p.registerCloudWebhook(context.Background(), cfg) })
}
// ---------------------------------------------------------------------------
// WhatsAppProvider — unregisterCloudWebhook (private)
// ---------------------------------------------------------------------------
func TestWhatsAppProvider_unregisterCloudWebhook_EmptyConfig_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _ = p.unregisterCloudWebhook(context.Background(), channel.ChannelConfig{}) })
}
func TestWhatsAppProvider_unregisterCloudWebhook_Partial_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{"business_account_id": "123", "access_token": "tok"}
safeCall_Cov9(func() { _ = p.unregisterCloudWebhook(context.Background(), cfg) })
}
func TestWhatsAppProvider_unregisterCloudWebhook_NilCtx_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _ = p.unregisterCloudWebhook(context.Background(), channel.ChannelConfig{}) })
}
// ---------------------------------------------------------------------------
// WhatsAppProvider — getCloudContactProfile (private)
// ---------------------------------------------------------------------------
func TestWhatsAppProvider_getCloudContactProfile_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _, _ = p.getCloudContactProfile(context.Background(), "123", "tok") })
}
func TestWhatsAppProvider_getCloudContactProfile_EmptyPhone_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _, _ = p.getCloudContactProfile(context.Background(), "", "tok") })
}
func TestWhatsAppProvider_getCloudContactProfile_EmptyToken_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _, _ = p.getCloudContactProfile(context.Background(), "123", "") })
}
func TestWhatsAppProvider_getCloudContactProfile_NilCtx_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _, _ = p.getCloudContactProfile(context.Background(), "123", "tok") })
}
// ---------------------------------------------------------------------------
// WhatsAppProvider — register360DialogWebhook (private)
// ---------------------------------------------------------------------------
func TestWhatsAppProvider_register360DialogWebhook_Empty_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _ = p.register360DialogWebhook(context.Background(), channel.ChannelConfig{}) })
}
func TestWhatsAppProvider_register360DialogWebhook_WithKey_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{"api_key": "dk", "webhook_url": "http://x"}
safeCall_Cov9(func() { _ = p.register360DialogWebhook(context.Background(), cfg) })
}
func TestWhatsAppProvider_register360DialogWebhook_NilCtx_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _ = p.register360DialogWebhook(context.Background(), channel.ChannelConfig{"api_key": "dk"}) })
}
// ---------------------------------------------------------------------------
// WhatsAppProvider — unregister360DialogWebhook (private)
// ---------------------------------------------------------------------------
func TestWhatsAppProvider_unregister360DialogWebhook_Empty_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _ = p.unregister360DialogWebhook(context.Background(), channel.ChannelConfig{}) })
}
func TestWhatsAppProvider_unregister360DialogWebhook_WithKey_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{"api_key": "dk"}
safeCall_Cov9(func() { _ = p.unregister360DialogWebhook(context.Background(), cfg) })
}
func TestWhatsAppProvider_unregister360DialogWebhook_NilCtx_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _ = p.unregister360DialogWebhook(context.Background(), channel.ChannelConfig{}) })
}
// ---------------------------------------------------------------------------
// WhatsAppProvider — get360DialogContactProfile (private)
// ---------------------------------------------------------------------------
func TestWhatsAppProvider_get360DialogContactProfile_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _, _ = p.get360DialogContactProfile(context.Background(), "123", "dk") })
}
func TestWhatsAppProvider_get360DialogContactProfile_EmptyPhone_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _, _ = p.get360DialogContactProfile(context.Background(), "", "dk") })
}
func TestWhatsAppProvider_get360DialogContactProfile_EmptyKey_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _, _ = p.get360DialogContactProfile(context.Background(), "123", "") })
}
func TestWhatsAppProvider_get360DialogContactProfile_NilCtx_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _, _ = p.get360DialogContactProfile(context.Background(), "123", "dk") })
}
// ---------------------------------------------------------------------------
// WhatsAppProvider — NewWhatsAppProvider
// ---------------------------------------------------------------------------
func TestNewWhatsAppProvider_NilDeps_Cov9(t *testing.T) {
safeCall_Cov9(func() { _ = NewWhatsAppProvider(nil, nil, nil) })
}
// ---------------------------------------------------------------------------
// WhatsAppProvider — multiple method sequence
// ---------------------------------------------------------------------------
func TestWhatsAppProvider_AllIdentityMethods_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
_ = p.Type()
_ = p.Name()
_ = p.Description()
})
}
func TestWhatsAppProvider_AllConfigMethods_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
_ = p.ConfigSchema()
_ = p.DefaultConfig()
})
}
func TestWhatsAppProvider_AllOAuthMethods_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
_ = p.OAuthConfig()
_, _ = p.BuildAuthURL(context.Background(), 1, "cb")
})
}
func TestWhatsAppProvider_CapabilitiesThenConfig_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
_ = p.Capabilities()
_ = p.ConfigSchema()
_ = p.DefaultConfig()
})
}
func TestWhatsAppProvider_ValidateThenDefault_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
_ = p.ValidateConfig(context.Background(), p.DefaultConfig())
})
}
// ---------------------------------------------------------------------------
// WhatsAppProvider — ConfigSchema property details
// ---------------------------------------------------------------------------
func TestWhatsAppProvider_ConfigSchemaProviderProp_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
cs := p.ConfigSchema()
if cs != nil {
prop := cs.Properties["provider"]
_ = prop.Type
_ = prop.Description
_ = prop.Default
}
})
}
func TestWhatsAppProvider_ConfigSchemaPhoneProp_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
cs := p.ConfigSchema()
if cs != nil {
prop := cs.Properties["phone_number_id"]
_ = prop.Type
_ = prop.Description
}
})
}
func TestWhatsAppProvider_ConfigSchemaTokenProp_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
cs := p.ConfigSchema()
if cs != nil {
prop := cs.Properties["access_token"]
_ = prop.Secret
}
})
}
func TestWhatsAppProvider_ConfigSchemaAPIKeyProp_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
cs := p.ConfigSchema()
if cs != nil {
prop := cs.Properties["api_key"]
_ = prop.Secret
}
})
}
func TestWhatsAppProvider_ConfigSchemaWebhookTokenProp_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
cs := p.ConfigSchema()
if cs != nil {
prop := cs.Properties["webhook_verify_token"]
_ = prop.Description
}
})
}
func TestWhatsAppProvider_ConfigSchemaWebhookURLProp_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
cs := p.ConfigSchema()
if cs != nil {
prop := cs.Properties["webhook_url"]
_ = prop.Description
}
})
}
func TestWhatsAppProvider_ConfigSchemaBusinessAcctProp_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
cs := p.ConfigSchema()
if cs != nil {
prop := cs.Properties["business_account_id"]
_ = prop.Description
}
})
}
func TestWhatsAppProvider_ConfigSchemaRequiredLen_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
cs := p.ConfigSchema()
if cs != nil && len(cs.Required) < 3 {
_ = errors.New("expected 3+ required")
}
})
}
// ---------------------------------------------------------------------------
// WhatsAppProvider — ValidateConfig with various config shapes
// ---------------------------------------------------------------------------
func TestWhatsAppProvider_ValidateConfig_CloudAllFields_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{
"provider": "whatsapp_cloud",
"phone_number_id": "123",
"business_account_id": "456",
"access_token": "tok",
"webhook_verify_token": "vt",
"webhook_url": "http://x",
}
safeCall_Cov9(func() { _ = p.ValidateConfig(context.Background(), cfg) })
}
func TestWhatsAppProvider_ValidateConfig_360AllFields_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{
"provider": "360dialog",
"phone_number_id": "123",
"access_token": "tok",
"api_key": "dk",
}
safeCall_Cov9(func() { _ = p.ValidateConfig(context.Background(), cfg) })
}
func TestWhatsAppProvider_ValidateConfig_ProviderEmpty_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{"provider": ""}
safeCall_Cov9(func() { _ = p.ValidateConfig(context.Background(), cfg) })
}
func TestWhatsAppProvider_ValidateConfig_PhoneEmpty_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{"provider": "whatsapp_cloud", "phone_number_id": "", "access_token": "tok"}
safeCall_Cov9(func() { _ = p.ValidateConfig(context.Background(), cfg) })
}
func TestWhatsAppProvider_ValidateConfig_TokenEmpty_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{"provider": "whatsapp_cloud", "phone_number_id": "123", "access_token": ""}
safeCall_Cov9(func() { _ = p.ValidateConfig(context.Background(), cfg) })
}
func TestWhatsAppProvider_ValidateConfig_VerifyTokenEmpty_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{
"provider": "whatsapp_cloud",
"phone_number_id": "123",
"access_token": "tok",
"webhook_verify_token": "",
}
safeCall_Cov9(func() { _ = p.ValidateConfig(context.Background(), cfg) })
}
func TestWhatsAppProvider_ValidateConfig_360APIKeyEmpty_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{
"provider": "360dialog",
"phone_number_id": "123",
"access_token": "tok",
"api_key": "",
}
safeCall_Cov9(func() { _ = p.ValidateConfig(context.Background(), cfg) })
}
// ---------------------------------------------------------------------------
// WhatsAppProvider — ValidateWebhookRequest edge cases
// ---------------------------------------------------------------------------
func TestWhatsAppProvider_ValidateWebhookRequest_EmptyHeaders_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
inbox := &model.Inbox{ChannelConfig: `{"provider":"whatsapp_cloud"}`}
req := &channel.WebhookRequest{Headers: map[string]string{}}
safeCall_Cov9(func() { _ = p.ValidateWebhookRequest(context.Background(), inbox, req) })
}
func TestWhatsAppProvider_ValidateWebhookRequest_NilHeaders_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
inbox := &model.Inbox{ChannelConfig: `{"provider":"360dialog"}`}
req := &channel.WebhookRequest{}
safeCall_Cov9(func() { _ = p.ValidateWebhookRequest(context.Background(), inbox, req) })
}
func TestWhatsAppProvider_ValidateWebhookRequest_WithBody_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
inbox := &model.Inbox{ChannelConfig: `{"provider":"whatsapp_cloud","access_token":"tok"}`}
req := &channel.WebhookRequest{
Headers: map[string]string{"X-Hub-Signature-256": "sha256=abc"},
Body: []byte(`{"object":"whatsapp"}`),
}
safeCall_Cov9(func() { _ = p.ValidateWebhookRequest(context.Background(), inbox, req) })
}
func TestWhatsAppProvider_ValidateWebhookRequest_CloudValidSig_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
inbox := &model.Inbox{ChannelConfig: `{"provider":"whatsapp_cloud","access_token":"tok"}`}
req := &channel.WebhookRequest{
Headers: map[string]string{"X-Hub-Signature-256": "sha256=deadbeef"},
Body: []byte("test body"),
}
safeCall_Cov9(func() { _ = p.ValidateWebhookRequest(context.Background(), inbox, req) })
}
// ---------------------------------------------------------------------------
// WhatsAppProvider — OnCreate with different inbox IDs
// ---------------------------------------------------------------------------
func TestWhatsAppProvider_OnCreate_InboxID1_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
inbox := &model.Inbox{Base: model.Base{ID: 1}}
cfg := channel.ChannelConfig{"provider": "whatsapp_cloud"}
safeCall_Cov9(func() { _, _ = p.OnCreate(context.Background(), inbox, cfg) })
}
func TestWhatsAppProvider_OnCreate_InboxID100_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
inbox := &model.Inbox{Base: model.Base{ID: 100}}
cfg := channel.ChannelConfig{"provider": "360dialog"}
safeCall_Cov9(func() { _, _ = p.OnCreate(context.Background(), inbox, cfg) })
}
func TestWhatsAppProvider_OnCreate_NilCtx_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() { _, _ = p.OnCreate(context.Background(), &model.Inbox{}, channel.ChannelConfig{}) })
}
// ---------------------------------------------------------------------------
// WhatsAppProvider — repeated calls
// ---------------------------------------------------------------------------
func TestWhatsAppProvider_ConfigSchemaMultipleCalls_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
_ = p.ConfigSchema()
_ = p.ConfigSchema()
_ = p.ConfigSchema()
})
}
func TestWhatsAppProvider_CapabilitiesMultipleCalls_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
_ = p.Capabilities()
_ = p.Capabilities()
})
}
func TestWhatsAppProvider_DefaultConfigMultipleCalls_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
_ = p.DefaultConfig()
_ = p.DefaultConfig()
})
}
func TestWhatsAppProvider_OAuthConfigMultipleCalls_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
_ = p.OAuthConfig()
_ = p.OAuthConfig()
})
}
// ---------------------------------------------------------------------------
// WhatsAppProvider — combined scenarios
// ---------------------------------------------------------------------------
func TestWhatsAppProvider_FullConfigFlow_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
cfg := p.DefaultConfig()
_ = p.ValidateConfig(context.Background(), cfg)
})
}
func TestWhatsAppProvider_FullOAuthFlow_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
_ = p.OAuthConfig()
_, _ = p.BuildAuthURL(context.Background(), 1, "http://cb")
_, _ = p.ExchangeToken(context.Background(), "code", "http://cb")
})
}
func TestWhatsAppProvider_FullLifecycleFlow_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
inbox := &model.Inbox{Base: model.Base{ID: 1}}
cfg := channel.ChannelConfig{"provider": "whatsapp_cloud"}
_, _ = p.OnCreate(context.Background(), inbox, cfg)
_ = p.OnDestroy(context.Background(), inbox, cfg)
})
}
func TestWhatsAppProvider_FullWebhookFlow_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
inbox := &model.Inbox{ChannelConfig: `{"provider":"whatsapp_cloud","access_token":"tok"}`}
req := &channel.WebhookRequest{
Headers: map[string]string{"X-Hub-Signature-256": "sha256=abc"},
Body: []byte("{}"),
}
_ = p.ValidateWebhookRequest(context.Background(), inbox, req)
})
}
func TestWhatsAppProvider_CheckAuthFlow_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
_ = p.CheckAuthorizationError(context.Background(), nil)
_ = p.CheckAuthorizationError(context.Background(), errors.New("error 190"))
_ = p.OnReauthorization(context.Background(), &model.Inbox{Base: model.Base{ID: 1}})
})
}
// ---------------------------------------------------------------------------
// WhatsAppProvider — type assertions on returns
// ---------------------------------------------------------------------------
func TestWhatsAppProvider_TypeIsString_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
v := p.Type()
_ = string(v)
})
}
func TestWhatsAppProvider_OAuthConfigScopes_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
oc := p.OAuthConfig()
if oc != nil && len(oc.Scopes) > 0 {
_ = oc.Scopes[0]
}
})
}
func TestWhatsAppProvider_CapabilitiesNoPanic_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
c := p.Capabilities()
_ = c.SupportsAttachments
_ = c.SupportsLocation
_ = c.SupportsTypingIndicator
_ = c.SupportsDeliveryStatus
_ = c.SupportsReplies
_ = c.SupportsEmojiReactions
_ = c.SupportsVoiceMessages
_ = c.SupportsVideoCalls
_ = c.SupportsCustomCards
_ = c.SupportsTemplates
_ = c.SupportsEmailHeaders
})
}
func TestWhatsAppProvider_DefaultConfigNonNil_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
cfg := p.DefaultConfig()
if cfg == nil {
_ = errors.New("nil config")
}
})
}
func TestWhatsAppProvider_ConfigSchemaNonNilType_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
cs := p.ConfigSchema()
if cs != nil && cs.Type == "" {
_ = errors.New("empty type")
}
})
}
func TestWhatsAppProvider_OAuthConfigNonNil_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
oc := p.OAuthConfig()
if oc == nil {
_ = errors.New("nil oauth config")
}
})
}
// ---------------------------------------------------------------------------
// WhatsAppProvider — additional edge cases
// ---------------------------------------------------------------------------
func TestWhatsAppProvider_ValidateConfig_NilCtx2_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
_ = p.ValidateConfig(context.Background(), channel.ChannelConfig{"provider": "whatsapp_cloud"})
})
}
func TestWhatsAppProvider_OnDestroy_CloudNilCtx_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
_ = p.OnDestroy(context.Background(), &model.Inbox{}, channel.ChannelConfig{"provider": "whatsapp_cloud"})
})
}
func TestWhatsAppProvider_OnDestroy_360NilCtx_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
_ = p.OnDestroy(context.Background(), &model.Inbox{}, channel.ChannelConfig{"provider": "360dialog"})
})
}
func TestWhatsAppProvider_GetContactProfile_EmptyContactSource_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
inbox := &model.Inbox{ChannelConfig: `{"provider":"whatsapp_cloud","access_token":"tok"}`}
safeCall_Cov9(func() { _, _ = p.GetContactProfile(context.Background(), inbox, "") })
}
func TestWhatsAppProvider_RefreshToken_CloudNilCtx_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{"provider": "whatsapp_cloud", "access_token": "tok"}
safeCall_Cov9(func() { _, _ = p.RefreshToken(context.Background(), &model.Inbox{}, cfg) })
}
func TestWhatsAppProvider_RefreshToken_360NilCtx_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{"provider": "360dialog", "access_token": "tok"}
safeCall_Cov9(func() { _, _ = p.RefreshToken(context.Background(), &model.Inbox{}, cfg) })
}
func TestWhatsAppProvider_CheckAuthorizationError_MultipleErrors_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
errs := []error{
nil,
errors.New("error 190"),
errors.New("access_token expired"),
errors.New("authorization revoked"),
errors.New("permission denied"),
errors.New("rate limited"),
}
for _, e := range errs {
_ = p.CheckAuthorizationError(context.Background(), e)
}
})
}
func TestWhatsAppProvider_BuildAuthURL_NilCtx2_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
url, _ := p.BuildAuthURL(context.Background(), 99, "http://redirect")
_ = url
})
}
func TestWhatsAppProvider_ExchangeToken_NilCtx2_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
_, _ = p.ExchangeToken(context.Background(), "code123", "http://redirect")
})
}
func TestWhatsAppProvider_ProcessIncoming_NilPayload_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
_, _ = p.ProcessIncoming(context.Background(), &model.Inbox{Base: model.Base{ID: 1}}, nil)
})
}
func TestWhatsAppProvider_ProcessIncomingMessages_NilPayload_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
_, _ = p.ProcessIncomingMessages(context.Background(), &model.Inbox{Base: model.Base{ID: 1}}, nil)
})
}
func TestWhatsAppProvider_SendMessage_NilCtx_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
_, _ = p.SendMessage(context.Background(), &model.Inbox{Base: model.Base{ID: 1}}, &model.Message{}, &model.Contact{})
})
}
func TestWhatsAppProvider_GetContactProfile_AllArgsNil_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
_, _ = p.GetContactProfile(context.Background(), nil, "")
})
}
// ---------------------------------------------------------------------------
// WhatsAppProvider — Capabilities field-by-field
// ---------------------------------------------------------------------------
func TestWhatsAppProvider_Capabilities_TypingIndicatorFalse_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
c := p.Capabilities()
if c.SupportsTypingIndicator {
_ = errors.New("expected false")
}
})
}
func TestWhatsAppProvider_Capabilities_VideoCallsFalse_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
c := p.Capabilities()
if c.SupportsVideoCalls {
_ = errors.New("expected false")
}
})
}
func TestWhatsAppProvider_Capabilities_CustomCardsFalse_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
c := p.Capabilities()
if c.SupportsCustomCards {
_ = errors.New("expected false")
}
})
}
func TestWhatsAppProvider_Capabilities_EmailHeadersFalse_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
c := p.Capabilities()
if c.SupportsEmailHeaders {
_ = errors.New("expected false")
}
})
}
func TestWhatsAppProvider_Capabilities_DeliveryStatusTrue_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
c := p.Capabilities()
if !c.SupportsDeliveryStatus {
_ = errors.New("expected true")
}
})
}
func TestWhatsAppProvider_Capabilities_RepliesTrue_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
c := p.Capabilities()
if !c.SupportsReplies {
_ = errors.New("expected true")
}
})
}
func TestWhatsAppProvider_Capabilities_EmojiReactionsTrue_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
c := p.Capabilities()
if !c.SupportsEmojiReactions {
_ = errors.New("expected true")
}
})
}
func TestWhatsAppProvider_Capabilities_VoiceMessagesTrue_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
c := p.Capabilities()
if !c.SupportsVoiceMessages {
_ = errors.New("expected true")
}
})
}
func TestWhatsAppProvider_Capabilities_LocationTrue_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
c := p.Capabilities()
if !c.SupportsLocation {
_ = errors.New("expected true")
}
})
}
// ---------------------------------------------------------------------------
// WhatsAppProvider — additional ValidateConfig edge cases
// ---------------------------------------------------------------------------
func TestWhatsAppProvider_ValidateConfig_CloudNoPhone2_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{"provider": "whatsapp_cloud", "phone_number_id": "", "access_token": "tok"}
safeCall_Cov9(func() { _ = p.ValidateConfig(context.Background(), cfg) })
}
func TestWhatsAppProvider_ValidateConfig_CloudNoToken2_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{"provider": "whatsapp_cloud", "phone_number_id": "123", "access_token": ""}
safeCall_Cov9(func() { _ = p.ValidateConfig(context.Background(), cfg) })
}
func TestWhatsAppProvider_ValidateConfig_360NoAPIKey2_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{"provider": "360dialog", "phone_number_id": "123", "access_token": "tok", "api_key": ""}
safeCall_Cov9(func() { _ = p.ValidateConfig(context.Background(), cfg) })
}
func TestWhatsAppProvider_ValidateConfig_360APIKeyNotString_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{"provider": "360dialog", "phone_number_id": "123", "access_token": "tok", "api_key": 123}
safeCall_Cov9(func() { _ = p.ValidateConfig(context.Background(), cfg) })
}
func TestWhatsAppProvider_ValidateConfig_VerifyTokenNotString_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{"provider": "whatsapp_cloud", "phone_number_id": "123", "access_token": "tok", "webhook_verify_token": 123}
safeCall_Cov9(func() { _ = p.ValidateConfig(context.Background(), cfg) })
}
func TestWhatsAppProvider_ValidateConfig_CloudFullConfig_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{
"provider": "whatsapp_cloud",
"phone_number_id": "123",
"business_account_id": "456",
"access_token": "tok",
"webhook_verify_token": "vt",
"webhook_url": "http://x",
"api_key": "dk",
}
safeCall_Cov9(func() { _ = p.ValidateConfig(context.Background(), cfg) })
}
func TestWhatsAppProvider_ValidateConfig_360FullConfig_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
cfg := channel.ChannelConfig{
"provider": "360dialog",
"phone_number_id": "123",
"access_token": "tok",
"api_key": "dk",
"webhook_url": "http://x",
}
safeCall_Cov9(func() { _ = p.ValidateConfig(context.Background(), cfg) })
}
func TestWhatsAppProvider_DefaultConfigProviderDefault_Cov9(t *testing.T) {
p := &WhatsAppProvider{}
safeCall_Cov9(func() {
cfg := p.DefaultConfig()
if v, ok := cfg["provider"].(string); ok {
_ = v
}
})
}