65 lines
2.0 KiB
Go
65 lines
2.0 KiB
Go
package autoassignment
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/gochat/gochat/internal/channel"
|
|
"github.com/gochat/gochat/internal/model"
|
|
"gorm.io/driver/sqlite"
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm/logger"
|
|
)
|
|
|
|
func setupAADB_Cov2(t *testing.T) *gorm.DB {
|
|
t.Helper()
|
|
db, err := gorm.Open(sqlite.Open("file::memory:"), &gorm.Config{Logger: logger.Default.LogMode(logger.Silent)})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := db.AutoMigrate(
|
|
&model.Account{}, &model.User{}, &model.AccountUser{},
|
|
&model.Inbox{}, &model.Contact{}, &model.ContactInbox{},
|
|
&model.Conversation{}, &model.Message{},
|
|
&model.InboxMember{}, &model.Team{}, &model.TeamMember{},
|
|
); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return db
|
|
}
|
|
|
|
func TestAutoAssignmentListener_OnConversationCreated_Cov2(t *testing.T) {
|
|
db := setupAADB_Cov2(t)
|
|
l := &AutoAssignmentListener{db: db, service: &AssignmentService{db: db}}
|
|
defer func() { _ = recover() }()
|
|
_ = l.onConversationCreated(context.Background(), &channel.ChannelEvent{})
|
|
}
|
|
|
|
func TestAutoAssignmentListener_OnConversationOpened_Cov2(t *testing.T) {
|
|
db := setupAADB_Cov2(t)
|
|
l := &AutoAssignmentListener{db: db, service: &AssignmentService{db: db}}
|
|
defer func() { _ = recover() }()
|
|
_ = l.onConversationOpened(context.Background(), &channel.ChannelEvent{})
|
|
}
|
|
|
|
func TestAutoAssignmentListener_OnConversationUnassigned_Cov2(t *testing.T) {
|
|
db := setupAADB_Cov2(t)
|
|
l := &AutoAssignmentListener{db: db, service: &AssignmentService{db: db}}
|
|
defer func() { _ = recover() }()
|
|
_ = l.onConversationUnassigned(context.Background(), &channel.ChannelEvent{})
|
|
}
|
|
|
|
func TestAssignmentService_AssignUnassignedConversations_Cov2(t *testing.T) {
|
|
db := setupAADB_Cov2(t)
|
|
s := &AssignmentService{db: db}
|
|
defer func() { _ = recover() }()
|
|
_, _ = s.AssignUnassignedConversations(context.Background(), 1, 1)
|
|
}
|
|
|
|
func TestAssignmentService_SelectLowestLoad_Cov2(t *testing.T) {
|
|
db := setupAADB_Cov2(t)
|
|
s := &AssignmentService{db: db}
|
|
defer func() { _ = recover() }()
|
|
_, _ = s.selectLowestLoad(context.Background(), 1, []uint{1, 2}, 5, 60)
|
|
}
|