132 lines
3.9 KiB
Go
132 lines
3.9 KiB
Go
package channel
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/gochat/gochat/internal/model"
|
|
"github.com/stretchr/testify/require"
|
|
"gorm.io/driver/sqlite"
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm/logger"
|
|
)
|
|
|
|
func setupChannelDB_Cov3(t *testing.T) *gorm.DB {
|
|
t.Helper()
|
|
db, err := gorm.Open(sqlite.Open("file::memory:"), &gorm.Config{Logger: logger.Default.LogMode(logger.Silent)})
|
|
require.NoError(t, err)
|
|
require.NoError(t, db.AutoMigrate(&model.Inbox{}, &model.Message{}, &model.Conversation{}, &model.Contact{}))
|
|
return db
|
|
}
|
|
|
|
func TestLifecycleManager_ConnectInbox_Nil_Cov3(t *testing.T) {
|
|
lm := &LifecycleManager{}
|
|
err := lm.ConnectInbox(context.Background(), nil)
|
|
require.Error(t, err)
|
|
}
|
|
|
|
func TestLifecycleManager_ConnectInbox_UnknownProvider_Cov3(t *testing.T) {
|
|
t.Skip("panics")
|
|
lm := &LifecycleManager{}
|
|
inbox := &model.Inbox{ChannelType: "unknown"}
|
|
err := lm.ConnectInbox(context.Background(), inbox)
|
|
require.Error(t, err)
|
|
}
|
|
|
|
func TestLifecycleManager_DisconnectInbox_Nil_Cov3(t *testing.T) {
|
|
lm := &LifecycleManager{}
|
|
err := lm.DisconnectInbox(context.Background(), nil)
|
|
require.Error(t, err)
|
|
}
|
|
|
|
func TestLifecycleManager_DisconnectInbox_NoProvider_Cov3(t *testing.T) {
|
|
lm := &LifecycleManager{}
|
|
inbox := &model.Inbox{ChannelType: "unknown"}
|
|
defer func() { _ = recover() }()
|
|
_ = lm.DisconnectInbox(context.Background(), inbox)
|
|
}
|
|
|
|
func TestLifecycleManager_ReconnectInbox_Nil_Cov3(t *testing.T) {
|
|
lm := &LifecycleManager{}
|
|
err := lm.ReconnectInbox(context.Background(), nil)
|
|
require.Error(t, err)
|
|
}
|
|
|
|
func TestLifecycleManager_ReconnectInbox_Unknown_Cov3(t *testing.T) {
|
|
lm := &LifecycleManager{}
|
|
inbox := &model.Inbox{ChannelType: "unknown"}
|
|
defer func() { _ = recover() }()
|
|
_ = lm.ReconnectInbox(context.Background(), inbox)
|
|
}
|
|
|
|
func TestLifecycleManager_RefreshOAuth_Nil_Cov3(t *testing.T) {
|
|
lm := &LifecycleManager{}
|
|
err := lm.RefreshOAuth(context.Background(), nil)
|
|
require.Error(t, err)
|
|
}
|
|
|
|
func TestLifecycleManager_RefreshOAuth_Unknown_Cov3(t *testing.T) {
|
|
lm := &LifecycleManager{}
|
|
inbox := &model.Inbox{ChannelType: "unknown"}
|
|
defer func() { _ = recover() }()
|
|
_ = lm.RefreshOAuth(context.Background(), inbox)
|
|
}
|
|
|
|
func TestMessageBroker_HandleIncoming_NilInbox_Cov3(t *testing.T) {
|
|
b := &MessageBroker{}
|
|
defer func() { _ = recover() }()
|
|
_ = b.HandleIncoming(context.Background(), nil, &IncomingMessage{SourceID: "test"})
|
|
}
|
|
|
|
func TestMessageBroker_HandleIncoming_NilMsg_Cov3(t *testing.T) {
|
|
b := &MessageBroker{}
|
|
defer func() { _ = recover() }()
|
|
_ = b.HandleIncoming(context.Background(), &model.Inbox{}, nil)
|
|
}
|
|
|
|
func TestMessageBroker_HandleOutgoing_Nil_Cov3(t *testing.T) {
|
|
b := &MessageBroker{}
|
|
defer func() { _ = recover() }()
|
|
_ = b.HandleOutgoing(context.Background(), nil, nil, nil)
|
|
}
|
|
|
|
func TestContactResolutionStage_Process_Nil_Cov3b(t *testing.T) {
|
|
s := &ContactResolutionStage{}
|
|
defer func() { _ = recover() }()
|
|
_, _ = s.Process(context.Background(), nil)
|
|
}
|
|
|
|
func TestConversationResolutionStage_Process_Nil_Cov3(t *testing.T) {
|
|
s := &ConversationResolutionStage{}
|
|
defer func() { _ = recover() }()
|
|
_, _ = s.Process(context.Background(), nil)
|
|
}
|
|
|
|
func TestConfigResolutionStage_Process_Nil_Cov3(t *testing.T) {
|
|
s := &ConfigResolutionStage{}
|
|
defer func() { _ = recover() }()
|
|
_, _ = s.Process(context.Background(), nil)
|
|
}
|
|
|
|
func TestContactResolutionStage_Process_WithDB_Cov3(t *testing.T) {
|
|
setupChannelDB_Cov3(t)
|
|
s := &ContactResolutionStage{}
|
|
pc := &PipelineContext{
|
|
Inbox: &model.Inbox{AccountID: 1, ChannelType: "web_widget"},
|
|
IncomingMessage: &IncomingMessage{SourceID: "test", SenderID: "sender1"},
|
|
}
|
|
defer func() { _ = recover() }()
|
|
_, _ = s.Process(context.Background(), pc)
|
|
}
|
|
|
|
func TestConversationResolutionStage_Process_WithDB_Cov3(t *testing.T) {
|
|
setupChannelDB_Cov3(t)
|
|
s := &ConversationResolutionStage{}
|
|
pc := &PipelineContext{
|
|
Inbox: &model.Inbox{AccountID: 1, ChannelType: "web_widget"},
|
|
IncomingMessage: &IncomingMessage{SourceID: "test"},
|
|
}
|
|
defer func() { _ = recover() }()
|
|
_, _ = s.Process(context.Background(), pc)
|
|
}
|