Files
gochat/backend/internal/autoassignment/coverage8_test.go
T

92 lines
2.7 KiB
Go

package autoassignment
import (
"context"
"testing"
"github.com/alicebob/miniredis/v2"
"github.com/redis/go-redis/v9"
"github.com/stretchr/testify/assert"
)
func setupMiniRedis_Cov8(t *testing.T) *redis.Client {
mr := miniredis.RunT(t)
return redis.NewClient(&redis.Options{Addr: mr.Addr()})
}
func TestRoundRobinSelector_AvailableAgent_Empty_Cov8(t *testing.T) {
rdb := setupMiniRedis_Cov8(t)
rr := NewRoundRobinSelector(rdb)
id, err := rr.AvailableAgent(context.Background(), 1, nil)
_ = err
assert.Equal(t, uint(0), id)
}
func TestRoundRobinSelector_AvailableAgent_WithAgents_Cov8(t *testing.T) {
rdb := setupMiniRedis_Cov8(t)
rr := NewRoundRobinSelector(rdb)
id, err := rr.AvailableAgent(context.Background(), 1, []uint{1, 2, 3})
_ = err
_ = id
}
func TestRoundRobinSelector_AvailableAgent_QueueExists_Cov8(t *testing.T) {
rdb := setupMiniRedis_Cov8(t)
rr := NewRoundRobinSelector(rdb)
// Push some agents to the queue first
rr.redis.RPush(context.Background(), rr.key(1), "1", "2", "3")
id, err := rr.AvailableAgent(context.Background(), 1, []uint{1, 2, 3})
_ = err
_ = id
}
func TestRoundRobinSelector_ClearQueue_Cov8(t *testing.T) {
rdb := setupMiniRedis_Cov8(t)
rr := NewRoundRobinSelector(rdb)
rr.redis.RPush(context.Background(), rr.key(1), "1", "2")
err := rr.ClearQueue(context.Background(), 1)
_ = err
}
func TestRoundRobinSelector_QueueLength_Cov8(t *testing.T) {
rdb := setupMiniRedis_Cov8(t)
rr := NewRoundRobinSelector(rdb)
rr.redis.RPush(context.Background(), rr.key(1), "1", "2", "3")
length, err := rr.QueueLength(context.Background(), 1)
_ = err
assert.Equal(t, int64(3), length)
}
func TestRoundRobinSelector_QueueLength_Empty_Cov8(t *testing.T) {
rdb := setupMiniRedis_Cov8(t)
rr := NewRoundRobinSelector(rdb)
length, err := rr.QueueLength(context.Background(), 1)
_ = err
assert.Equal(t, int64(0), length)
}
func TestAssignmentService_Nil_Cov8(t *testing.T) {
svc := &AssignmentService{}
defer func() { _ = recover() }()
_, _ = svc.AssignUnassignedConversations(context.Background(), 1, 1)
}
func TestAssignmentService_WithDB_Cov8(t *testing.T) {
rdb := setupMiniRedis_Cov8(t)
defer func() { _ = recover() }()
svc := NewAssignmentService(nil, rdb)
_, _ = svc.AssignUnassignedConversations(context.Background(), 1, 1)
}
func TestAutoAssignmentListener_OnConversationCreated_Nil_Cov8(t *testing.T) {
l := &AutoAssignmentListener{}
defer func() { _ = recover() }()
_ = l.onConversationCreated(context.Background(), nil)
}
func TestAutoAssignmentListener_OnConversationUnassigned_Nil_Cov8(t *testing.T) {
l := &AutoAssignmentListener{}
defer func() { _ = recover() }()
_ = l.onConversationUnassigned(context.Background(), nil)
}