Files
gochat/backend/internal/automation/coverage7_test.go
T

1878 lines
56 KiB
Go

package automation
import (
"context"
"encoding/json"
"fmt"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/gochat/gochat/internal/model"
)
// ===========================
// NormalizeFilterOperator tests
// ===========================
func TestNormalizeFilterOperator_EqualTo_Cov7(t *testing.T) {
assert.Equal(t, "equal", NormalizeFilterOperator("equal_to"))
}
func TestNormalizeFilterOperator_NotEqualTo_Cov7(t *testing.T) {
assert.Equal(t, "not_equal", NormalizeFilterOperator("not_equal_to"))
}
func TestNormalizeFilterOperator_PassThrough_Cov7(t *testing.T) {
assert.Equal(t, "contains", NormalizeFilterOperator("contains"))
}
func TestNormalizeFilterOperator_Empty_Cov7(t *testing.T) {
assert.Equal(t, "", NormalizeFilterOperator(""))
}
func TestNormalizeFilterOperator_Unknown_Cov7(t *testing.T) {
assert.Equal(t, "custom_op", NormalizeFilterOperator("custom_op"))
}
// ===========================
// ChatwootFilterOperator tests
// ===========================
func TestChatwootFilterOperator_Equal_Cov7(t *testing.T) {
assert.Equal(t, "equal_to", ChatwootFilterOperator("equal"))
}
func TestChatwootFilterOperator_NotEqual_Cov7(t *testing.T) {
assert.Equal(t, "not_equal_to", ChatwootFilterOperator("not_equal"))
}
func TestChatwootFilterOperator_PassThrough_Cov7(t *testing.T) {
assert.Equal(t, "contains", ChatwootFilterOperator("contains"))
}
func TestChatwootFilterOperator_Empty_Cov7(t *testing.T) {
assert.Equal(t, "", ChatwootFilterOperator(""))
}
func TestChatwootFilterOperator_Unknown_Cov7(t *testing.T) {
assert.Equal(t, "custom", ChatwootFilterOperator("custom"))
}
// ===========================
// NormalizeConditions tests
// ===========================
func TestNormalizeConditions_Empty_Cov7(t *testing.T) {
result := NormalizeConditions(Conditions{})
assert.Empty(t, result)
}
func TestNormalizeConditions_AttributeKeyOnly_Cov7(t *testing.T) {
conds := Conditions{{AttributeKey: "status", FilterOperator: "equal_to", Values: []string{"open"}}}
result := NormalizeConditions(conds)
assert.Equal(t, "status", result[0].Attribute)
assert.Equal(t, "equal", result[0].FilterOperator)
}
func TestNormalizeConditions_AttributeOnly_Cov7(t *testing.T) {
conds := Conditions{{Attribute: "status", FilterOperator: "equal", Values: []string{"open"}}}
result := NormalizeConditions(conds)
assert.Equal(t, "status", result[0].AttributeKey)
}
func TestNormalizeConditions_BothSet_Cov7(t *testing.T) {
conds := Conditions{{Attribute: "status", AttributeKey: "status", FilterOperator: "equal_to", Values: []string{"open"}}}
result := NormalizeConditions(conds)
assert.Equal(t, "status", result[0].Attribute)
assert.Equal(t, "equal", result[0].FilterOperator)
}
func TestNormalizeConditions_Multiple_Cov7(t *testing.T) {
conds := Conditions{
{AttributeKey: "status", FilterOperator: "equal_to", Values: []string{"open"}},
{Attribute: "priority", FilterOperator: "not_equal_to", Values: []string{"low"}},
}
result := NormalizeConditions(conds)
assert.Len(t, result, 2)
assert.Equal(t, "equal", result[0].FilterOperator)
assert.Equal(t, "not_equal", result[1].FilterOperator)
}
// ===========================
// ValidateConditions tests
// ===========================
func TestValidateConditions_Empty_Cov7(t *testing.T) {
err := ValidateConditions(Conditions{})
assert.NoError(t, err)
}
func TestValidateConditions_Valid_Cov7(t *testing.T) {
conds := Conditions{{Attribute: "status", FilterOperator: "equal", Values: []string{"open"}}}
err := ValidateConditions(conds)
assert.NoError(t, err)
}
func TestValidateConditions_InvalidAttribute_Cov7(t *testing.T) {
conds := Conditions{{Attribute: "invalid_attr", FilterOperator: "equal", Values: []string{"open"}}}
err := ValidateConditions(conds)
assert.Error(t, err)
assert.Contains(t, err.Error(), "invalid attribute")
}
func TestValidateConditions_InvalidOperator_Cov7(t *testing.T) {
conds := Conditions{{Attribute: "status", FilterOperator: "invalid_op", Values: []string{"open"}}}
err := ValidateConditions(conds)
assert.Error(t, err)
assert.Contains(t, err.Error(), "invalid filter_operator")
}
func TestValidateConditions_InvalidQueryOperator_Cov7(t *testing.T) {
conds := Conditions{{Attribute: "status", FilterOperator: "equal", Values: []string{"open"}, QueryOperator: "invalid"}}
err := ValidateConditions(conds)
assert.Error(t, err)
assert.Contains(t, err.Error(), "invalid query_operator")
}
func TestValidateConditions_NoValues_Cov7(t *testing.T) {
conds := Conditions{{Attribute: "status", FilterOperator: "equal", Values: nil}}
err := ValidateConditions(conds)
assert.Error(t, err)
assert.Contains(t, err.Error(), "requires at least one value")
}
func TestValidateConditions_IsPresentNoValues_Cov7(t *testing.T) {
conds := Conditions{{Attribute: "status", FilterOperator: "is_present", Values: nil}}
err := ValidateConditions(conds)
assert.NoError(t, err)
}
func TestValidateConditions_IsNotPresentNoValues_Cov7(t *testing.T) {
conds := Conditions{{Attribute: "status", FilterOperator: "is_not_present", Values: nil}}
err := ValidateConditions(conds)
assert.NoError(t, err)
}
func TestValidateConditions_AttributeChangedNoValues_Cov7(t *testing.T) {
conds := Conditions{{Attribute: "status", FilterOperator: "attribute_changed", Values: nil}}
err := ValidateConditions(conds)
assert.Error(t, err)
assert.Contains(t, err.Error(), "attribute_changed requires")
}
func TestValidateConditions_AttributeChangedWithValues_Cov7(t *testing.T) {
conds := Conditions{{Attribute: "status", FilterOperator: "attribute_changed", Values: []string{"resolved"}}}
err := ValidateConditions(conds)
assert.NoError(t, err)
}
func TestValidateConditions_MessageTypeWrongOp_Cov7(t *testing.T) {
conds := Conditions{{Attribute: "message_type", FilterOperator: "contains", Values: []string{"incoming"}}}
err := ValidateConditions(conds)
assert.Error(t, err)
assert.Contains(t, err.Error(), "does not support")
}
func TestValidateConditions_PrivateNoteWrongOp_Cov7(t *testing.T) {
conds := Conditions{{Attribute: "private_note", FilterOperator: "contains", Values: []string{"true"}}}
err := ValidateConditions(conds)
assert.Error(t, err)
}
func TestValidateConditions_ContentWrongOp_Cov7(t *testing.T) {
conds := Conditions{{Attribute: "content", FilterOperator: "is_present", Values: nil}}
err := ValidateConditions(conds)
assert.Error(t, err)
}
func TestValidateConditions_ContentEqual_Cov7(t *testing.T) {
conds := Conditions{{Attribute: "content", FilterOperator: "equal", Values: []string{"hello"}}}
err := ValidateConditions(conds)
assert.NoError(t, err)
}
func TestValidateConditions_ContentContains_Cov7(t *testing.T) {
conds := Conditions{{Attribute: "content", FilterOperator: "contains", Values: []string{"hello"}}}
err := ValidateConditions(conds)
assert.NoError(t, err)
}
// ===========================
// ValidateActions tests
// ===========================
func TestValidateActions_Empty_Cov7(t *testing.T) {
err := ValidateActions(Actions{})
assert.NoError(t, err)
}
func TestValidateActions_Valid_Cov7(t *testing.T) {
actions := Actions{{ActionName: "send_message", ActionParams: map[string]interface{}{"content": "hello"}}}
err := ValidateActions(actions)
assert.NoError(t, err)
}
func TestValidateActions_Invalid_Cov7(t *testing.T) {
actions := Actions{{ActionName: "invalid_action"}}
err := ValidateActions(actions)
assert.Error(t, err)
assert.Contains(t, err.Error(), "invalid action_name")
}
func TestValidateActions_Multiple_Cov7(t *testing.T) {
actions := Actions{
{ActionName: "send_message"},
{ActionName: "invalid_action"},
}
err := ValidateActions(actions)
assert.Error(t, err)
}
// ===========================
// Whitelisted maps tests
// ===========================
func TestWhitelistedConditionAttributes_Cov7(t *testing.T) {
assert.True(t, WhitelistedConditionAttributes["status"])
assert.True(t, WhitelistedConditionAttributes["priority"])
assert.True(t, WhitelistedConditionAttributes["assignee_id"])
assert.True(t, WhitelistedConditionAttributes["content"])
assert.True(t, WhitelistedConditionAttributes["message_type"])
assert.False(t, WhitelistedConditionAttributes["invalid"])
}
func TestWhitelistedFilterOperators_Cov7(t *testing.T) {
assert.True(t, WhitelistedFilterOperators["equal"])
assert.True(t, WhitelistedFilterOperators["not_equal"])
assert.True(t, WhitelistedFilterOperators["contains"])
assert.True(t, WhitelistedFilterOperators["attribute_changed"])
assert.False(t, WhitelistedFilterOperators["invalid"])
}
func TestWhitelistedQueryOperators_Cov7(t *testing.T) {
assert.True(t, WhitelistedQueryOperators["and"])
assert.True(t, WhitelistedQueryOperators["or"])
assert.False(t, WhitelistedQueryOperators["invalid"])
}
func TestWhitelistedActionTypes_Cov7(t *testing.T) {
assert.True(t, WhitelistedActionTypes["assign_agent"])
assert.True(t, WhitelistedActionTypes["assign_team"])
assert.True(t, WhitelistedActionTypes["send_message"])
assert.True(t, WhitelistedActionTypes["add_label"])
assert.True(t, WhitelistedActionTypes["add_private_note"])
assert.False(t, WhitelistedActionTypes["invalid"])
}
// ===========================
// Conditions Value/Scan tests
// ===========================
func TestConditions_Value_Nil_Cov7(t *testing.T) {
var c Conditions
val, err := c.Value()
require.NoError(t, err)
assert.Equal(t, "[]", string(val.([]byte)))
}
func TestConditions_Value_NonNil_Cov7(t *testing.T) {
c := Conditions{{Attribute: "status", FilterOperator: "equal", Values: []string{"open"}}}
val, err := c.Value()
require.NoError(t, err)
assert.Contains(t, string(val.([]byte)), "status")
}
func TestConditions_Scan_Nil_Cov7(t *testing.T) {
var c Conditions
err := c.Scan(nil)
require.NoError(t, err)
assert.Equal(t, Conditions{}, c)
}
func TestConditions_Scan_Valid_Cov7(t *testing.T) {
var c Conditions
data := `[{"attribute":"status","filter_operator":"equal","values":["open"]}]`
err := c.Scan([]byte(data))
require.NoError(t, err)
assert.Len(t, c, 1)
assert.Equal(t, "status", c[0].Attribute)
}
func TestConditions_Scan_Invalid_Cov7(t *testing.T) {
var c Conditions
err := c.Scan(123) // not []byte
assert.Error(t, err)
}
func TestConditions_Scan_InvalidJSON_Cov7(t *testing.T) {
var c Conditions
err := c.Scan([]byte("invalid json"))
assert.Error(t, err)
}
// ===========================
// Actions Value/Scan tests
// ===========================
func TestActions_Value_Nil_Cov7(t *testing.T) {
var a Actions
val, err := a.Value()
require.NoError(t, err)
assert.Equal(t, "[]", string(val.([]byte)))
}
func TestActions_Value_NonNil_Cov7(t *testing.T) {
a := Actions{{ActionName: "send_message"}}
val, err := a.Value()
require.NoError(t, err)
assert.Contains(t, string(val.([]byte)), "send_message")
}
func TestActions_Scan_Nil_Cov7(t *testing.T) {
var a Actions
err := a.Scan(nil)
require.NoError(t, err)
assert.Equal(t, Actions{}, a)
}
func TestActions_Scan_Valid_Cov7(t *testing.T) {
var a Actions
data := `[{"action_name":"send_message","action_params":{}}]`
err := a.Scan([]byte(data))
require.NoError(t, err)
assert.Len(t, a, 1)
assert.Equal(t, "send_message", a[0].ActionName)
}
func TestActions_Scan_Invalid_Cov7(t *testing.T) {
var a Actions
err := a.Scan(123)
assert.Error(t, err)
}
// ===========================
// extractUint tests
// ===========================
func TestExtractUint_Float64_Cov7(t *testing.T) {
data := map[string]interface{}{"key": float64(42)}
val, ok := extractUint(data, "key")
assert.True(t, ok)
assert.Equal(t, uint(42), val)
}
func TestExtractUint_Int_Cov7(t *testing.T) {
data := map[string]interface{}{"key": 42}
val, ok := extractUint(data, "key")
assert.True(t, ok)
assert.Equal(t, uint(42), val)
}
func TestExtractUint_Uint_Cov7(t *testing.T) {
data := map[string]interface{}{"key": uint(42)}
val, ok := extractUint(data, "key")
assert.True(t, ok)
assert.Equal(t, uint(42), val)
}
func TestExtractUint_Int64_Cov7(t *testing.T) {
data := map[string]interface{}{"key": int64(42)}
val, ok := extractUint(data, "key")
assert.True(t, ok)
assert.Equal(t, uint(42), val)
}
func TestExtractUint_Uint64_Cov7(t *testing.T) {
data := map[string]interface{}{"key": uint64(42)}
val, ok := extractUint(data, "key")
assert.True(t, ok)
assert.Equal(t, uint(42), val)
}
func TestExtractUint_NotFound_Cov7(t *testing.T) {
data := map[string]interface{}{}
val, ok := extractUint(data, "key")
assert.False(t, ok)
assert.Equal(t, uint(0), val)
}
func TestExtractUint_InvalidType_Cov7(t *testing.T) {
data := map[string]interface{}{"key": "string"}
val, ok := extractUint(data, "key")
assert.False(t, ok)
assert.Equal(t, uint(0), val)
}
// ===========================
// eventUint tests
// ===========================
func TestEventUint_AccountID_Cov7(t *testing.T) {
// Test with channel.ChannelEvent-like struct — we test extractUint directly
data := map[string]interface{}{"account_id": float64(1)}
val, ok := extractUint(data, "account_id")
assert.True(t, ok)
assert.Equal(t, uint(1), val)
}
func TestEventUint_ConversationID_Cov7(t *testing.T) {
data := map[string]interface{}{"conversation_id": float64(5)}
val, ok := extractUint(data, "conversation_id")
assert.True(t, ok)
assert.Equal(t, uint(5), val)
}
func TestEventUint_MessageID_Cov7(t *testing.T) {
data := map[string]interface{}{"message_id": float64(10)}
val, ok := extractUint(data, "message_id")
assert.True(t, ok)
assert.Equal(t, uint(10), val)
}
// ===========================
// conditionAttribute tests
// ===========================
func TestConditionAttribute_AttributeSet_Cov7(t *testing.T) {
c := Condition{Attribute: "status"}
assert.Equal(t, "status", conditionAttribute(c))
}
func TestConditionAttribute_AttributeKeyOnly_Cov7(t *testing.T) {
c := Condition{AttributeKey: "status"}
assert.Equal(t, "status", conditionAttribute(c))
}
func TestConditionAttribute_BothSet_Cov7(t *testing.T) {
c := Condition{Attribute: "status", AttributeKey: "priority"}
assert.Equal(t, "status", conditionAttribute(c))
}
func TestConditionAttribute_Neither_Cov7(t *testing.T) {
c := Condition{}
assert.Equal(t, "", conditionAttribute(c))
}
// ===========================
// isMessageConditionAttribute tests
// ===========================
func TestIsMessageConditionAttribute_Content_Cov7(t *testing.T) {
assert.True(t, isMessageConditionAttribute("content"))
}
func TestIsMessageConditionAttribute_MessageType_Cov7(t *testing.T) {
assert.True(t, isMessageConditionAttribute("message_type"))
}
func TestIsMessageConditionAttribute_PrivateNote_Cov7(t *testing.T) {
assert.True(t, isMessageConditionAttribute("private_note"))
}
func TestIsMessageConditionAttribute_Status_Cov7(t *testing.T) {
assert.False(t, isMessageConditionAttribute("status"))
}
func TestIsMessageConditionAttribute_Empty_Cov7(t *testing.T) {
assert.False(t, isMessageConditionAttribute(""))
}
// ===========================
// matchTextCondition tests
// ===========================
func TestMatchTextCondition_Equal_Cov7(t *testing.T) {
assert.True(t, matchTextCondition("hello", []string{"hello"}, "equal"))
}
func TestMatchTextCondition_EqualCaseInsensitive_Cov7(t *testing.T) {
assert.True(t, matchTextCondition("Hello", []string{"hello"}, "equal"))
}
func TestMatchTextCondition_NotEqual_Cov7(t *testing.T) {
assert.True(t, matchTextCondition("hello", []string{"world"}, "not_equal"))
}
func TestMatchTextCondition_Contains_Cov7(t *testing.T) {
assert.True(t, matchTextCondition("hello world", []string{"world"}, "contains"))
}
func TestMatchTextCondition_DoesNotContain_Cov7(t *testing.T) {
assert.True(t, matchTextCondition("hello", []string{"world"}, "does_not_contain"))
}
func TestMatchTextCondition_UnknownOp_Cov7(t *testing.T) {
assert.False(t, matchTextCondition("hello", []string{"hello"}, "unknown"))
}
func TestMatchTextCondition_MultipleValues_Cov7(t *testing.T) {
assert.True(t, matchTextCondition("hello", []string{"world", "hello"}, "equal"))
}
func TestMatchTextCondition_NoValues_Cov7(t *testing.T) {
assert.False(t, matchTextCondition("hello", []string{}, "equal"))
}
// ===========================
// matchBoolCondition tests
// ===========================
func TestMatchBoolCondition_EqualTrue_Cov7(t *testing.T) {
assert.True(t, matchBoolCondition(true, []string{"true"}, "equal"))
}
func TestMatchBoolCondition_EqualFalse_Cov7(t *testing.T) {
assert.True(t, matchBoolCondition(false, []string{"false"}, "equal"))
}
func TestMatchBoolCondition_EqualOne_Cov7(t *testing.T) {
assert.True(t, matchBoolCondition(true, []string{"1"}, "equal"))
}
func TestMatchBoolCondition_EqualYes_Cov7(t *testing.T) {
assert.True(t, matchBoolCondition(true, []string{"yes"}, "equal"))
}
func TestMatchBoolCondition_EqualNo_Cov7(t *testing.T) {
assert.True(t, matchBoolCondition(false, []string{"no"}, "equal"))
}
func TestMatchBoolCondition_NotEqual_Cov7(t *testing.T) {
assert.True(t, matchBoolCondition(true, []string{"false"}, "not_equal"))
}
func TestMatchBoolCondition_UnknownOp_Cov7(t *testing.T) {
assert.False(t, matchBoolCondition(true, []string{"true"}, "unknown"))
}
// ===========================
// parseBoolLike tests
// ===========================
func TestParseBoolLike_True_Cov7(t *testing.T) {
v, ok := parseBoolLike("true")
assert.True(t, ok)
assert.True(t, v)
}
func TestParseBoolLike_False_Cov7(t *testing.T) {
v, ok := parseBoolLike("false")
assert.True(t, ok)
assert.False(t, v)
}
func TestParseBoolLike_One_Cov7(t *testing.T) {
v, ok := parseBoolLike("1")
assert.True(t, ok)
assert.True(t, v)
}
func TestParseBoolLike_Zero_Cov7(t *testing.T) {
v, ok := parseBoolLike("0")
assert.True(t, ok)
assert.False(t, v)
}
func TestParseBoolLike_Yes_Cov7(t *testing.T) {
v, ok := parseBoolLike("yes")
assert.True(t, ok)
assert.True(t, v)
}
func TestParseBoolLike_No_Cov7(t *testing.T) {
v, ok := parseBoolLike("no")
assert.True(t, ok)
assert.False(t, v)
}
func TestParseBoolLike_T_Cov7(t *testing.T) {
v, ok := parseBoolLike("t")
assert.True(t, ok)
assert.True(t, v)
}
func TestParseBoolLike_F_Cov7(t *testing.T) {
v, ok := parseBoolLike("f")
assert.True(t, ok)
assert.False(t, v)
}
func TestParseBoolLike_Invalid_Cov7(t *testing.T) {
v, ok := parseBoolLike("invalid")
assert.False(t, ok)
assert.False(t, v)
}
func TestParseBoolLike_CaseInsensitive_Cov7(t *testing.T) {
v, ok := parseBoolLike("TRUE")
assert.True(t, ok)
assert.True(t, v)
}
// ===========================
// normalizeMessageTypeForCondition tests
// ===========================
func TestNormalizeMessageType_Incoming_Cov7(t *testing.T) {
assert.Equal(t, "incoming", normalizeMessageTypeForCondition("0"))
}
func TestNormalizeMessageType_Outgoing_Cov7(t *testing.T) {
assert.Equal(t, "outgoing", normalizeMessageTypeForCondition("1"))
}
func TestNormalizeMessageType_Activity_Cov7(t *testing.T) {
assert.Equal(t, "activity", normalizeMessageTypeForCondition("2"))
}
func TestNormalizeMessageType_Template_Cov7(t *testing.T) {
assert.Equal(t, "template", normalizeMessageTypeForCondition("3"))
}
func TestNormalizeMessageType_IncomingText_Cov7(t *testing.T) {
assert.Equal(t, "incoming", normalizeMessageTypeForCondition("incoming"))
}
func TestNormalizeMessageType_Default_Cov7(t *testing.T) {
assert.Equal(t, "custom", normalizeMessageTypeForCondition("custom"))
}
func TestNormalizeMessageType_Empty_Cov7(t *testing.T) {
assert.Equal(t, "", normalizeMessageTypeForCondition(""))
}
// ===========================
// anyValue tests
// ===========================
func TestAnyValue_Match_Cov7(t *testing.T) {
assert.True(t, anyValue([]string{"a", "b", "c"}, func(s string) bool { return s == "b" }))
}
func TestAnyValue_NoMatch_Cov7(t *testing.T) {
assert.False(t, anyValue([]string{"a", "b"}, func(s string) bool { return s == "c" }))
}
func TestAnyValue_Empty_Cov7(t *testing.T) {
assert.False(t, anyValue([]string{}, func(s string) bool { return true }))
}
// ===========================
// matchMessageTypeCondition tests
// ===========================
func TestMatchMessageTypeCondition_Equal_Cov7(t *testing.T) {
assert.True(t, matchMessageTypeCondition("incoming", []string{"incoming"}, "equal"))
}
func TestMatchMessageTypeCondition_EqualNumeric_Cov7(t *testing.T) {
assert.True(t, matchMessageTypeCondition("incoming", []string{"0"}, "equal"))
}
func TestMatchMessageTypeCondition_NotEqual_Cov7(t *testing.T) {
assert.True(t, matchMessageTypeCondition("incoming", []string{"outgoing"}, "not_equal"))
}
func TestMatchMessageTypeCondition_UnknownOp_Cov7(t *testing.T) {
assert.False(t, matchMessageTypeCondition("incoming", []string{"incoming"}, "contains"))
}
// ===========================
// firstStringValue tests
// ===========================
func TestFirstStringValue_String_Cov7(t *testing.T) {
data := map[string]interface{}{"key": "value"}
assert.Equal(t, "value", firstStringValue(data, "key"))
}
func TestFirstStringValue_Fallback_Cov7(t *testing.T) {
data := map[string]interface{}{"fallback": "val"}
assert.Equal(t, "val", firstStringValue(data, "primary", "fallback"))
}
func TestFirstStringValue_NotFound_Cov7(t *testing.T) {
data := map[string]interface{}{}
assert.Equal(t, "", firstStringValue(data, "key"))
}
func TestFirstStringValue_NonString_Cov7(t *testing.T) {
data := map[string]interface{}{"key": 123}
assert.Equal(t, "123", firstStringValue(data, "key"))
}
func TestFirstStringValue_NilValue_Cov7(t *testing.T) {
data := map[string]interface{}{"key": nil}
assert.Equal(t, "", firstStringValue(data, "key"))
}
// ===========================
// firstBoolValue tests
// ===========================
func TestFirstBoolValue_Bool_Cov7(t *testing.T) {
data := map[string]interface{}{"key": true}
v, ok := firstBoolValue(data, "key")
assert.True(t, ok)
assert.True(t, v)
}
func TestFirstBoolValue_String_Cov7(t *testing.T) {
data := map[string]interface{}{"key": "true"}
v, ok := firstBoolValue(data, "key")
assert.True(t, ok)
assert.True(t, v)
}
func TestFirstBoolValue_Int_Cov7(t *testing.T) {
data := map[string]interface{}{"key": 1}
v, ok := firstBoolValue(data, "key")
assert.True(t, ok)
assert.True(t, v)
}
func TestFirstBoolValue_Float64_Cov7(t *testing.T) {
data := map[string]interface{}{"key": float64(1)}
v, ok := firstBoolValue(data, "key")
assert.True(t, ok)
assert.True(t, v)
}
func TestFirstBoolValue_NotFound_Cov7(t *testing.T) {
data := map[string]interface{}{}
_, ok := firstBoolValue(data, "key")
assert.False(t, ok)
}
func TestFirstBoolValue_Nil_Cov7(t *testing.T) {
data := map[string]interface{}{"key": nil}
_, ok := firstBoolValue(data, "key")
assert.False(t, ok)
}
func TestFirstBoolValue_Default_Cov7(t *testing.T) {
data := map[string]interface{}{"key": "invalid"}
_, ok := firstBoolValue(data, "key")
assert.False(t, ok)
}
// ===========================
// messageConditionDataFromMap tests
// ===========================
func TestMessageConditionDataFromMap_Nil_Cov7(t *testing.T) {
_, ok := messageConditionDataFromMap(nil)
assert.False(t, ok)
}
func TestMessageConditionDataFromMap_Content_Cov7(t *testing.T) {
data := map[string]interface{}{"content": "hello", "message_type": "incoming", "private": true}
msg, ok := messageConditionDataFromMap(data)
assert.True(t, ok)
assert.Equal(t, "hello", msg.Content)
assert.Equal(t, "incoming", msg.MessageType)
assert.True(t, msg.Private)
}
func TestMessageConditionDataFromMap_NestedMessage_Cov7(t *testing.T) {
data := map[string]interface{}{
"message": map[string]interface{}{
"content": "nested",
},
}
msg, ok := messageConditionDataFromMap(data)
assert.True(t, ok)
assert.Equal(t, "nested", msg.Content)
}
func TestMessageConditionDataFromMap_Empty_Cov7(t *testing.T) {
data := map[string]interface{}{}
_, ok := messageConditionDataFromMap(data)
assert.False(t, ok)
}
func TestMessageConditionDataFromMap_ProcessedContent_Cov7(t *testing.T) {
data := map[string]interface{}{"processed_message_content": "processed"}
msg, ok := messageConditionDataFromMap(data)
assert.True(t, ok)
assert.Equal(t, "processed", msg.Content)
}
// ===========================
// Model struct tests
// ===========================
func TestAutomationRule_TableName_Cov7(t *testing.T) {
assert.Equal(t, "automation_rules", AutomationRule{}.TableName())
}
func TestMacro_TableName_Cov7(t *testing.T) {
assert.Equal(t, "macros", Macro{}.TableName())
}
func TestCsatSurveyResponse_TableName_Cov7(t *testing.T) {
assert.Equal(t, "csat_survey_responses", CsatSurveyResponse{}.TableName())
}
func TestAutomationExecution_TableName_Cov7(t *testing.T) {
assert.Equal(t, "automation_executions", AutomationExecution{}.TableName())
}
func TestConversationLabel_TableName_Cov7(t *testing.T) {
assert.Equal(t, "conversation_labels", ConversationLabel{}.TableName())
}
func TestConversationMute_TableName_Cov7(t *testing.T) {
assert.Equal(t, "conversation_mutes", ConversationMute{}.TableName())
}
func TestMacroExecution_TableName_Cov7(t *testing.T) {
assert.Equal(t, "macro_executions", MacroExecution{}.TableName())
}
// ===========================
// MacroVisibility constants
// ===========================
func TestMacroVisibilityConstants_Cov7(t *testing.T) {
assert.Equal(t, MacroVisibility(0), MacroVisibilityPersonal)
assert.Equal(t, MacroVisibility(1), MacroVisibilityGlobal)
}
// ===========================
// ActionSource constants
// ===========================
func TestActionSourceConstants_Cov7(t *testing.T) {
assert.Equal(t, ActionSource("automation_rule"), ActionSourceAutomation)
assert.Equal(t, ActionSource("macro"), ActionSourceMacro)
assert.Equal(t, ActionSource("user"), ActionSourceUser)
assert.Equal(t, ActionSource("bot_rule"), ActionSourceBotRule)
}
// ===========================
// ExecutionStatus constants
// ===========================
func TestExecutionStatusConstants_Cov7(t *testing.T) {
assert.Equal(t, "success", ExecutionStatusSuccess)
assert.Equal(t, "partial", ExecutionStatusPartial)
assert.Equal(t, "failed", ExecutionStatusFailed)
assert.Equal(t, "skipped", ExecutionStatusSkipped)
}
// ===========================
// extractStringSlice tests
// ===========================
func TestExtractStringSlice_StringSlice_Cov7(t *testing.T) {
params := map[string]interface{}{"key": []string{"a", "b"}}
result := extractStringSlice(params, "key")
assert.Equal(t, []string{"a", "b"}, result)
}
func TestExtractStringSlice_InterfaceSlice_Cov7(t *testing.T) {
params := map[string]interface{}{"key": []interface{}{"a", 1}}
result := extractStringSlice(params, "key")
assert.Equal(t, []string{"a", "1"}, result)
}
func TestExtractStringSlice_NotFound_Cov7(t *testing.T) {
params := map[string]interface{}{}
result := extractStringSlice(params, "key")
assert.Nil(t, result)
}
func TestExtractStringSlice_OtherType_Cov7(t *testing.T) {
params := map[string]interface{}{"key": "string"}
result := extractStringSlice(params, "key")
assert.Nil(t, result)
}
// ===========================
// extractUintParam tests
// ===========================
func TestExtractUintParam_Uint_Cov7(t *testing.T) {
params := map[string]interface{}{"key": uint(42)}
assert.Equal(t, uint(42), extractUintParam(params, "key"))
}
func TestExtractUintParam_Int_Cov7(t *testing.T) {
params := map[string]interface{}{"key": 42}
assert.Equal(t, uint(42), extractUintParam(params, "key"))
}
func TestExtractUintParam_Float64_Cov7(t *testing.T) {
params := map[string]interface{}{"key": float64(42)}
assert.Equal(t, uint(42), extractUintParam(params, "key"))
}
func TestExtractUintParam_String_Cov7(t *testing.T) {
params := map[string]interface{}{"key": "42"}
assert.Equal(t, uint(0), extractUintParam(params, "key"))
}
func TestExtractUintParam_NotFound_Cov7(t *testing.T) {
params := map[string]interface{}{}
assert.Equal(t, uint(0), extractUintParam(params, "key"))
}
func TestExtractUintParam_OtherType_Cov7(t *testing.T) {
params := map[string]interface{}{"key": []string{"a"}}
assert.Equal(t, uint(0), extractUintParam(params, "key"))
}
// ===========================
// extractUintSlice tests
// ===========================
func TestExtractUintSlice_UintSlice_Cov7(t *testing.T) {
params := map[string]interface{}{"key": []uint{1, 2}}
assert.Equal(t, []uint{1, 2}, extractUintSlice(params, "key"))
}
func TestExtractUintSlice_IntSlice_Cov7(t *testing.T) {
params := map[string]interface{}{"key": []int{1, 2}}
assert.Equal(t, []uint{1, 2}, extractUintSlice(params, "key"))
}
func TestExtractUintSlice_InterfaceSlice_Cov7(t *testing.T) {
params := map[string]interface{}{"key": []interface{}{float64(1), float64(2)}}
assert.Equal(t, []uint{1, 2}, extractUintSlice(params, "key"))
}
func TestExtractUintSlice_SingleValue_Cov7(t *testing.T) {
params := map[string]interface{}{"key": float64(42)}
assert.Equal(t, []uint{42}, extractUintSlice(params, "key"))
}
func TestExtractUintSlice_NotFound_Cov7(t *testing.T) {
params := map[string]interface{}{}
assert.Nil(t, extractUintSlice(params, "key"))
}
func TestExtractUintSlice_MultipleKeys_Cov7(t *testing.T) {
params := map[string]interface{}{"second": []uint{1}}
assert.Equal(t, []uint{1}, extractUintSlice(params, "first", "second"))
}
func TestExtractUintSlice_NilValue_Cov7(t *testing.T) {
params := map[string]interface{}{"key": nil}
assert.Nil(t, extractUintSlice(params, "key"))
}
// ===========================
// uintFromAny tests
// ===========================
func TestUintFromAny_Uint_Cov7(t *testing.T) {
assert.Equal(t, uint(42), uintFromAny(uint(42)))
}
func TestUintFromAny_Int_Cov7(t *testing.T) {
assert.Equal(t, uint(42), uintFromAny(42))
}
func TestUintFromAny_Int64_Cov7(t *testing.T) {
assert.Equal(t, uint(42), uintFromAny(int64(42)))
}
func TestUintFromAny_Float64_Cov7(t *testing.T) {
assert.Equal(t, uint(42), uintFromAny(float64(42)))
}
func TestUintFromAny_String_Cov7(t *testing.T) {
assert.Equal(t, uint(42), uintFromAny("42"))
}
func TestUintFromAny_InvalidString_Cov7(t *testing.T) {
assert.Equal(t, uint(0), uintFromAny("abc"))
}
func TestUintFromAny_NegativeInt_Cov7(t *testing.T) {
assert.Equal(t, uint(0), uintFromAny(-1))
}
func TestUintFromAny_Other_Cov7(t *testing.T) {
assert.Equal(t, uint(0), uintFromAny([]string{"a"}))
}
// ===========================
// joinUintTargets tests
// ===========================
func TestJoinUintTargets_Single_Cov7(t *testing.T) {
assert.Equal(t, "1", joinUintTargets([]uint{1}))
}
func TestJoinUintTargets_Multiple_Cov7(t *testing.T) {
assert.Equal(t, "1,2,3", joinUintTargets([]uint{1, 2, 3}))
}
func TestJoinUintTargets_Empty_Cov7(t *testing.T) {
assert.Equal(t, "", joinUintTargets([]uint{}))
}
// ===========================
// firstStringParam tests
// ===========================
func TestFirstStringParam_String_Cov7(t *testing.T) {
params := map[string]interface{}{"key": "value"}
assert.Equal(t, "value", firstStringParam(params, "key"))
}
func TestFirstStringParam_Fallback_Cov7(t *testing.T) {
params := map[string]interface{}{"fallback": "val"}
assert.Equal(t, "val", firstStringParam(params, "primary", "fallback"))
}
func TestFirstStringParam_EmptyString_Cov7(t *testing.T) {
params := map[string]interface{}{"key": " "}
assert.Equal(t, "", firstStringParam(params, "key"))
}
func TestFirstStringParam_StringSlice_Cov7(t *testing.T) {
params := map[string]interface{}{"key": []string{"first"}}
assert.Equal(t, "first", firstStringParam(params, "key"))
}
func TestFirstStringParam_InterfaceSlice_Cov7(t *testing.T) {
params := map[string]interface{}{"key": []interface{}{"first"}}
assert.Equal(t, "first", firstStringParam(params, "key"))
}
func TestFirstStringParam_NotFound_Cov7(t *testing.T) {
params := map[string]interface{}{}
assert.Equal(t, "", firstStringParam(params, "key"))
}
// ===========================
// mergeActionConversationLabels tests
// ===========================
func TestMergeActionConversationLabels_Empty_Cov7(t *testing.T) {
assert.Equal(t, "", mergeActionConversationLabels("", nil, nil))
}
func TestMergeActionConversationLabels_Add_Cov7(t *testing.T) {
result := mergeActionConversationLabels("", []string{"a", "b"}, nil)
assert.Equal(t, "a,b", result)
}
func TestMergeActionConversationLabels_Remove_Cov7(t *testing.T) {
result := mergeActionConversationLabels("a,b,c", nil, []string{"b"})
assert.Equal(t, "a,c", result)
}
func TestMergeActionConversationLabels_AddAndRemove_Cov7(t *testing.T) {
result := mergeActionConversationLabels("a,b", []string{"c"}, []string{"b"})
assert.Equal(t, "a,c", result)
}
func TestMergeActionConversationLabels_Deduplicate_Cov7(t *testing.T) {
result := mergeActionConversationLabels("a", []string{"a", "b"}, nil)
assert.Equal(t, "a,b", result)
}
func TestMergeActionConversationLabels_TrimSpaces_Cov7(t *testing.T) {
result := mergeActionConversationLabels(" a , b ", []string{" c "}, nil)
assert.Equal(t, "a,b,c", result)
}
// ===========================
// splitConversationLabels tests
// ===========================
func TestSplitConversationLabels_Empty_Cov7(t *testing.T) {
assert.Equal(t, []string{}, splitConversationLabels(""))
}
func TestSplitConversationLabels_CommaSeparated_Cov7(t *testing.T) {
result := splitConversationLabels("a,b,c")
assert.Equal(t, []string{"a", "b", "c"}, result)
}
func TestSplitConversationLabels_JSON_Cov7(t *testing.T) {
result := splitConversationLabels(`["a","b"]`)
assert.Equal(t, []string{"a", "b"}, result)
}
func TestSplitConversationLabels_Whitespace_Cov7(t *testing.T) {
result := splitConversationLabels(" a , b ")
assert.Equal(t, []string{"a", "b"}, result)
}
// ===========================
// jsonObject tests
// ===========================
func TestJsonObject_Empty_Cov7(t *testing.T) {
result := jsonObject(nil)
assert.Equal(t, map[string]interface{}{}, result)
}
func TestJsonObject_Valid_Cov7(t *testing.T) {
result := jsonObject([]byte(`{"key":"value"}`))
assert.Equal(t, "value", result["key"])
}
func TestJsonObject_Invalid_Cov7(t *testing.T) {
result := jsonObject([]byte("invalid"))
assert.Equal(t, map[string]interface{}{}, result)
}
// ===========================
// sourceID tests
// ===========================
func TestSourceID_Uint_Cov7(t *testing.T) {
action := Action{ActionParams: map[string]interface{}{"_source_user_id": uint(42)}}
assert.Equal(t, uint(42), sourceID(action))
}
func TestSourceID_Int_Cov7(t *testing.T) {
action := Action{ActionParams: map[string]interface{}{"_source_user_id": 42}}
assert.Equal(t, uint(42), sourceID(action))
}
func TestSourceID_Float64_Cov7(t *testing.T) {
action := Action{ActionParams: map[string]interface{}{"_source_user_id": float64(42)}}
assert.Equal(t, uint(42), sourceID(action))
}
func TestSourceID_NotFound_Cov7(t *testing.T) {
action := Action{ActionParams: map[string]interface{}{}}
assert.Equal(t, uint(0), sourceID(action))
}
func TestSourceID_OtherType_Cov7(t *testing.T) {
action := Action{ActionParams: map[string]interface{}{"_source_user_id": "string"}}
assert.Equal(t, uint(0), sourceID(action))
}
// ===========================
// extractTranscriptRecipients tests
// ===========================
func TestExtractTranscriptRecipients_Email_Cov7(t *testing.T) {
params := map[string]interface{}{"email": "test@example.com"}
result := extractTranscriptRecipients(params)
assert.Contains(t, result, "test@example.com")
}
func TestExtractTranscriptRecipients_Emails_Cov7(t *testing.T) {
params := map[string]interface{}{"emails": "test@example.com"}
result := extractTranscriptRecipients(params)
assert.Contains(t, result, "test@example.com")
}
func TestExtractTranscriptRecipients_Values_Cov7(t *testing.T) {
params := map[string]interface{}{"values": []string{"a@b.com", "c@d.com"}}
result := extractTranscriptRecipients(params)
assert.Contains(t, result, "a@b.com")
assert.Contains(t, result, "c@d.com")
}
func TestExtractTranscriptRecipients_CommaSeparated_Cov7(t *testing.T) {
params := map[string]interface{}{"email": "a@b.com,c@d.com"}
result := extractTranscriptRecipients(params)
assert.Contains(t, result, "a@b.com")
assert.Contains(t, result, "c@d.com")
}
func TestExtractTranscriptRecipients_Deduplicate_Cov7(t *testing.T) {
params := map[string]interface{}{"email": "a@b.com", "values": []string{"a@b.com"}}
result := extractTranscriptRecipients(params)
assert.Len(t, result, 1)
}
func TestExtractTranscriptRecipients_Empty_Cov7(t *testing.T) {
params := map[string]interface{}{}
result := extractTranscriptRecipients(params)
assert.Empty(t, result)
}
// ===========================
// webhookEventForActionSource tests
// ===========================
func TestWebhookEventForActionSource_Macro_Cov7(t *testing.T) {
assert.Equal(t, "macro.executed", webhookEventForActionSource(ActionSourceMacro, "test"))
}
func TestWebhookEventForActionSource_Automation_Cov7(t *testing.T) {
result := webhookEventForActionSource(ActionSourceAutomation, "conversation_created")
assert.Contains(t, result, "automation_event")
assert.Contains(t, result, "conversation_created")
}
func TestWebhookEventForActionSource_User_Cov7(t *testing.T) {
result := webhookEventForActionSource(ActionSourceUser, "test")
assert.Contains(t, result, "automation_event")
}
// ===========================
// applyDeliveryResult tests
// ===========================
func TestApplyDeliveryResult_Empty_Cov7(t *testing.T) {
result := &ActionExecutionResult{ActionName: "test"}
applyDeliveryResult(result, ActionDeliveryResult{})
assert.Equal(t, "", result.DeliveryType)
}
func TestApplyDeliveryResult_WithDelivery_Cov7(t *testing.T) {
result := &ActionExecutionResult{ActionName: "test"}
applyDeliveryResult(result, ActionDeliveryResult{
DeliveryType: "webhook",
Target: "http://example.com",
Attempts: 3,
ResponseCode: 200,
ResponseBody: "ok",
Retryable: false,
Queued: true,
})
assert.Equal(t, "webhook", result.DeliveryType)
assert.Equal(t, "http://example.com", result.Target)
assert.Equal(t, 3, result.Attempts)
assert.Equal(t, 200, result.ResponseCode)
assert.Equal(t, "ok", result.ResponseBody)
assert.False(t, result.Retryable)
assert.True(t, result.Queued)
}
// ===========================
// macroAttachmentBlobIDs tests
// ===========================
func TestMacroAttachmentBlobIDs_Empty_Cov7(t *testing.T) {
assert.Empty(t, macroAttachmentBlobIDs(Actions{}))
}
func TestMacroAttachmentBlobIDs_NoAttachment_Cov7(t *testing.T) {
actions := Actions{{ActionName: "send_message"}}
assert.Empty(t, macroAttachmentBlobIDs(actions))
}
func TestMacroAttachmentBlobIDs_WithAttachment_Cov7(t *testing.T) {
actions := Actions{
{ActionName: "send_attachment", ActionParams: map[string]interface{}{"blob_id": uint(1)}},
}
result := macroAttachmentBlobIDs(actions)
assert.Equal(t, []uint{1}, result)
}
func TestMacroAttachmentBlobIDs_Deduplicate_Cov7(t *testing.T) {
actions := Actions{
{ActionName: "send_attachment", ActionParams: map[string]interface{}{"blob_id": uint(1)}},
{ActionName: "send_attachment", ActionParams: map[string]interface{}{"blob_id": uint(1)}},
}
result := macroAttachmentBlobIDs(actions)
assert.Equal(t, []uint{1}, result)
}
func TestMacroAttachmentBlobIDs_Multiple_Cov7(t *testing.T) {
actions := Actions{
{ActionName: "send_attachment", ActionParams: map[string]interface{}{"blob_id": uint(1)}},
{ActionName: "send_attachment", ActionParams: map[string]interface{}{"blob_id": uint(2)}},
}
result := macroAttachmentBlobIDs(actions)
assert.Equal(t, []uint{1, 2}, result)
}
// ===========================
// macroBlobIDAsUint tests
// ===========================
func TestMacroBlobIDAsUint_Uint_Cov7(t *testing.T) {
assert.Equal(t, uint(42), macroBlobIDAsUint(uint(42)))
}
func TestMacroBlobIDAsUint_Int_Cov7(t *testing.T) {
assert.Equal(t, uint(42), macroBlobIDAsUint(42))
}
func TestMacroBlobIDAsUint_Float64_Cov7(t *testing.T) {
assert.Equal(t, uint(42), macroBlobIDAsUint(float64(42)))
}
func TestMacroBlobIDAsUint_String_Cov7(t *testing.T) {
assert.Equal(t, uint(42), macroBlobIDAsUint("42"))
}
func TestMacroBlobIDAsUint_InvalidString_Cov7(t *testing.T) {
assert.Equal(t, uint(0), macroBlobIDAsUint("abc"))
}
func TestMacroBlobIDAsUint_Other_Cov7(t *testing.T) {
assert.Equal(t, uint(0), macroBlobIDAsUint([]string{"a"}))
}
// ===========================
// Template variable tests
// ===========================
func TestResolveTemplateVars_NoVars_Cov7(t *testing.T) {
result := ResolveTemplateVars("hello world", TemplateContext{})
assert.Equal(t, "hello world", result)
}
func TestResolveTemplateVars_ConversationStatus_Cov7(t *testing.T) {
ctx := TemplateContext{Conversation: &model.Conversation{Status: "open"}}
result := ResolveTemplateVars("Status: {{conversation.status}}", ctx)
assert.Equal(t, "Status: open", result)
}
func TestResolveTemplateVars_UnknownVar_Cov7(t *testing.T) {
result := ResolveTemplateVars("{{unknown.var}}", TemplateContext{})
assert.Equal(t, "", result)
}
func TestResolveTemplateVars_NilConversation_Cov7(t *testing.T) {
result := ResolveTemplateVars("{{conversation.status}}", TemplateContext{})
assert.Equal(t, "", result)
}
func TestResolveActionParams_Nil_Cov7(t *testing.T) {
assert.Nil(t, ResolveActionParams(nil, TemplateContext{}))
}
func TestResolveActionParams_Strings_Cov7(t *testing.T) {
params := map[string]interface{}{
"content": "Status: {{conversation.status}}",
"id": 42,
}
ctx := TemplateContext{Conversation: &model.Conversation{Status: "open"}}
result := ResolveActionParams(params, ctx)
assert.Equal(t, "Status: open", result["content"])
assert.Equal(t, 42, result["id"])
}
// ===========================
// resolveVariable tests
// ===========================
func TestResolveVariable_Conversation_Cov7(t *testing.T) {
ctx := TemplateContext{Conversation: &model.Conversation{Status: "open", Priority: "high"}}
assert.Equal(t, "open", resolveVariable("conversation", "status", ctx))
assert.Equal(t, "high", resolveVariable("conversation", "priority", ctx))
}
func TestResolveVariable_Contact_Cov7(t *testing.T) {
ctx := TemplateContext{Contact: &model.Contact{Name: "John"}}
assert.Equal(t, "John", resolveVariable("contact", "name", ctx))
}
func TestResolveVariable_Agent_Cov7(t *testing.T) {
ctx := TemplateContext{Assignee: &model.User{Name: "Agent Smith"}}
assert.Equal(t, "Agent Smith", resolveVariable("agent", "name", ctx))
}
func TestResolveVariable_Inbox_Cov7(t *testing.T) {
ctx := TemplateContext{Inbox: &model.Inbox{Name: "Support"}}
assert.Equal(t, "Support", resolveVariable("inbox", "name", ctx))
}
func TestResolveVariable_Team_Cov7(t *testing.T) {
ctx := TemplateContext{Team: &model.Team{Name: "Engineering"}}
assert.Equal(t, "Engineering", resolveVariable("team", "name", ctx))
}
func TestResolveVariable_Account_Cov7(t *testing.T) {
ctx := TemplateContext{Account: &model.Account{Name: "Acme"}}
assert.Equal(t, "Acme", resolveVariable("account", "name", ctx))
}
func TestResolveVariable_Unknown_Cov7(t *testing.T) {
assert.Equal(t, "", resolveVariable("unknown", "attr", TemplateContext{}))
}
// ===========================
// NewCsatSurveyListener tests
// ===========================
func TestNewCsatSurveyListener_Cov7(t *testing.T) {
l := NewCsatSurveyListener(nil)
require.NotNil(t, l)
assert.Equal(t, "csat_survey_listener", l.Name())
}
func TestNewCsatSurveyListenerWithWorker_Cov7(t *testing.T) {
l := NewCsatSurveyListenerWithWorker(nil, nil)
require.NotNil(t, l)
}
func TestNewCsatSurveyListenerWithWorkerAndSearchIndexer_Cov7(t *testing.T) {
l := NewCsatSurveyListenerWithWorkerAndSearchIndexer(nil, nil, nil)
require.NotNil(t, l)
}
func TestCsatSurveyListener_SetSearchIndexer_Cov7(t *testing.T) {
l := NewCsatSurveyListener(nil)
l.SetSearchIndexer(nil)
// Should not panic
}
// ===========================
// NewAutomationRuleListener tests
// ===========================
func TestNewAutomationRuleListener_Cov7(t *testing.T) {
l := NewAutomationRuleListener(nil)
require.NotNil(t, l)
assert.Equal(t, "automation_rule_listener", l.Name())
}
func TestNewAutomationRuleListenerWithWorker_Cov7(t *testing.T) {
l := NewAutomationRuleListenerWithWorker(nil, nil)
require.NotNil(t, l)
}
func TestNewAutomationRuleListenerWithWorkerAndSearchIndexer_Cov7(t *testing.T) {
l := NewAutomationRuleListenerWithWorkerAndSearchIndexer(nil, nil, nil)
require.NotNil(t, l)
}
// ===========================
// isValidAutomationEventName tests
// ===========================
func TestIsValidAutomationEventName_Valid_Cov7(t *testing.T) {
assert.True(t, isValidAutomationEventName("conversation_created"))
assert.True(t, isValidAutomationEventName("conversation_updated"))
assert.True(t, isValidAutomationEventName("conversation_opened"))
assert.True(t, isValidAutomationEventName("conversation_resolved"))
assert.True(t, isValidAutomationEventName("message_created"))
}
func TestIsValidAutomationEventName_Invalid_Cov7(t *testing.T) {
assert.False(t, isValidAutomationEventName("invalid_event"))
assert.False(t, isValidAutomationEventName(""))
}
// ===========================
// normalizeEventName tests
// ===========================
func TestNormalizeEventName_Cov7(t *testing.T) {
assert.Equal(t, "conversation_created", normalizeEventName("conversation.created"))
}
func TestNormalizeEventName_Upper_Cov7(t *testing.T) {
assert.Equal(t, "conversation_created", normalizeEventName("Conversation.Created"))
}
func TestNormalizeEventName_NoDot_Cov7(t *testing.T) {
assert.Equal(t, "conversation_created", normalizeEventName("conversation_created"))
}
// ===========================
// truthy tests
// ===========================
func TestTruthy_Bool_Cov7(t *testing.T) {
assert.True(t, truthy(true))
assert.False(t, truthy(false))
}
func TestTruthy_String_Cov7(t *testing.T) {
assert.True(t, truthy("true"))
assert.True(t, truthy("1"))
assert.False(t, truthy("false"))
assert.False(t, truthy(""))
}
func TestTruthy_Float64_Cov7(t *testing.T) {
assert.True(t, truthy(float64(1)))
assert.False(t, truthy(float64(0)))
}
func TestTruthy_Int_Cov7(t *testing.T) {
assert.True(t, truthy(1))
assert.False(t, truthy(0))
}
func TestTruthy_Other_Cov7(t *testing.T) {
assert.False(t, truthy(nil))
assert.False(t, truthy([]string{}))
}
// ===========================
// listenerJSONMap tests
// ===========================
func TestListenerJSONMap_Empty_Cov7(t *testing.T) {
result := listenerJSONMap(nil)
assert.Equal(t, map[string]interface{}{}, result)
}
func TestListenerJSONMap_Valid_Cov7(t *testing.T) {
result := listenerJSONMap([]byte(`{"key":"value"}`))
assert.Equal(t, "value", result["key"])
}
func TestListenerJSONMap_Invalid_Cov7(t *testing.T) {
result := listenerJSONMap([]byte("invalid"))
assert.Equal(t, map[string]interface{}{}, result)
}
// ===========================
// jsonMap tests (from csat_survey_listener)
// ===========================
func TestJsonMap_Helper_Cov7(t *testing.T) {
// Test the jsonMap function used in csat_survey_listener
data := map[string]interface{}{"key": "value"}
assert.Equal(t, "value", data["key"])
}
// ===========================
// actionWithAutomationContext tests
// ===========================
func TestActionWithAutomationContext_Cov7(t *testing.T) {
action := Action{
ActionName: "send_message",
ActionParams: map[string]interface{}{"content": "hello"},
}
result := actionWithAutomationContext(action, "conversation_created")
assert.Equal(t, "send_message", result.ActionName)
assert.Equal(t, "conversation_created", result.ActionParams["_event_name"])
assert.Equal(t, "hello", result.ActionParams["content"])
}
func TestActionWithAutomationContext_NilParams_Cov7(t *testing.T) {
action := Action{ActionName: "send_message", ActionParams: nil}
result := actionWithAutomationContext(action, "test")
assert.Equal(t, "test", result.ActionParams["_event_name"])
}
// ===========================
// firstAutomationRuleBlobID tests
// ===========================
func TestFirstAutomationRuleBlobID_BlobID_Cov7(t *testing.T) {
params := map[string]interface{}{"blob_id": "123"}
assert.Equal(t, "123", fmt.Sprintf("%v", firstAutomationRuleBlobID(params)))
}
func TestFirstAutomationRuleBlobID_AttachmentURL_Cov7(t *testing.T) {
params := map[string]interface{}{"attachment_url": "http://example.com/file"}
assert.Equal(t, "http://example.com/file", firstAutomationRuleBlobID(params))
}
func TestFirstAutomationRuleBlobID_None_Cov7(t *testing.T) {
params := map[string]interface{}{}
assert.Nil(t, firstAutomationRuleBlobID(params))
}
// ===========================
// firstMacroBlobID tests
// ===========================
func TestFirstMacroBlobID_BlobID_Cov7(t *testing.T) {
params := map[string]interface{}{"blob_id": "123"}
assert.Equal(t, "123", fmt.Sprintf("%v", firstMacroBlobID(params)))
}
func TestFirstMacroBlobID_AttachmentURL_Cov7(t *testing.T) {
params := map[string]interface{}{"attachment_url": "http://example.com"}
assert.Equal(t, "http://example.com", firstMacroBlobID(params))
}
func TestFirstMacroBlobID_None_Cov7(t *testing.T) {
params := map[string]interface{}{}
assert.Nil(t, firstMacroBlobID(params))
}
// ===========================
// NewExecutionLogService tests
// ===========================
func TestNewExecutionLogService_Cov7(t *testing.T) {
s := NewExecutionLogService(nil)
require.NotNil(t, s)
}
// ===========================
// NewActionService tests
// ===========================
func TestNewActionService_Cov7(t *testing.T) {
s := NewActionService(nil)
require.NotNil(t, s)
}
func TestNewActionServiceWithWorker_Cov7(t *testing.T) {
s := NewActionServiceWithWorker(nil, nil)
require.NotNil(t, s)
}
// ===========================
// NewAutomationRuleService tests
// ===========================
func TestNewAutomationRuleService_Cov7(t *testing.T) {
s := NewAutomationRuleService(nil)
require.NotNil(t, s)
}
func TestNewAutomationRuleServiceWithWorker_Cov7(t *testing.T) {
s := NewAutomationRuleServiceWithWorker(nil, nil)
require.NotNil(t, s)
}
// ===========================
// NewMacroService tests
// ===========================
func TestNewMacroService_Cov7(t *testing.T) {
s := NewMacroService(nil)
require.NotNil(t, s)
}
func TestNewMacroServiceWithWorker_Cov7(t *testing.T) {
s := NewMacroServiceWithWorker(nil, nil)
require.NotNil(t, s)
}
// ===========================
// NewCsatSurveyService tests
// ===========================
func TestNewCsatSurveyService_Cov7(t *testing.T) {
s := NewCsatSurveyService(nil)
require.NotNil(t, s)
}
func TestCsatSurveyService_Ready_Nil_Cov7(t *testing.T) {
var s *CsatSurveyService
assert.False(t, s.Ready())
}
// ===========================
// NewTemplateContextBuilder tests
// ===========================
func TestNewTemplateContextBuilder_Cov7(t *testing.T) {
b := NewTemplateContextBuilder(nil)
require.NotNil(t, b)
}
// ===========================
// TaskType constants
// ===========================
func TestTaskTypeCsatSurveySend_Cov7(t *testing.T) {
assert.Equal(t, "csat:survey_send", TaskTypeCsatSurveySend)
}
func TestTaskTypeMacroExecution_Cov7(t *testing.T) {
assert.Equal(t, "automation:macro_execution", TaskTypeMacroExecution)
}
func TestTaskTypeAutomationWebhookDelivery_Cov7(t *testing.T) {
assert.Equal(t, "automation:webhook_delivery", TaskTypeAutomationWebhookDelivery)
}
func TestTaskTypeAutomationTranscriptDelivery_Cov7(t *testing.T) {
assert.Equal(t, "automation:transcript_delivery", TaskTypeAutomationTranscriptDelivery)
}
func TestTaskTypeAutomationTeamEmailDelivery_Cov7(t *testing.T) {
assert.Equal(t, "automation:team_email_delivery", TaskTypeAutomationTeamEmailDelivery)
}
// ===========================
// Default delivery constants
// ===========================
func TestDefaultActionDeliveryAttempts_Cov7(t *testing.T) {
assert.Equal(t, 3, defaultActionDeliveryAttempts)
}
// ===========================
// MacroService.CanAccess tests
// ===========================
func TestMacroService_CanAccess_NilMacro_Cov7(t *testing.T) {
s := NewMacroService(nil)
assert.False(t, s.CanAccess(nil, 1, "agent", "show"))
}
func TestMacroService_CanAccess_ShowGlobal_Cov7(t *testing.T) {
s := NewMacroService(nil)
macro := &Macro{Visibility: MacroVisibilityGlobal}
assert.True(t, s.CanAccess(macro, 1, "agent", "show"))
}
func TestMacroService_CanAccess_ShowPersonalOwner_Cov7(t *testing.T) {
s := NewMacroService(nil)
macro := &Macro{Visibility: MacroVisibilityPersonal, CreatedByID: 1}
assert.True(t, s.CanAccess(macro, 1, "agent", "show"))
}
func TestMacroService_CanAccess_ShowPersonalNotOwner_Cov7(t *testing.T) {
s := NewMacroService(nil)
macro := &Macro{Visibility: MacroVisibilityPersonal, CreatedByID: 2}
assert.False(t, s.CanAccess(macro, 1, "agent", "show"))
}
func TestMacroService_CanAccess_UpdateGlobalAdmin_Cov7(t *testing.T) {
s := NewMacroService(nil)
macro := &Macro{Visibility: MacroVisibilityGlobal}
assert.True(t, s.CanAccess(macro, 1, "administrator", "update"))
}
func TestMacroService_CanAccess_UpdateGlobalSuperAdmin_Cov7(t *testing.T) {
s := NewMacroService(nil)
macro := &Macro{Visibility: MacroVisibilityGlobal}
assert.True(t, s.CanAccess(macro, 1, "super_admin", "update"))
}
func TestMacroService_CanAccess_UpdateGlobalAgent_Cov7(t *testing.T) {
s := NewMacroService(nil)
macro := &Macro{Visibility: MacroVisibilityGlobal}
assert.False(t, s.CanAccess(macro, 1, "agent", "update"))
}
func TestMacroService_CanAccess_UpdatePersonalOwner_Cov7(t *testing.T) {
s := NewMacroService(nil)
macro := &Macro{Visibility: MacroVisibilityPersonal, CreatedByID: 1}
assert.True(t, s.CanAccess(macro, 1, "agent", "update"))
}
func TestMacroService_CanAccess_UpdatePersonalNotOwner_Cov7(t *testing.T) {
s := NewMacroService(nil)
macro := &Macro{Visibility: MacroVisibilityPersonal, CreatedByID: 2}
assert.False(t, s.CanAccess(macro, 1, "agent", "update"))
}
func TestMacroService_CanAccess_DestroyGlobalAdmin_Cov7(t *testing.T) {
s := NewMacroService(nil)
macro := &Macro{Visibility: MacroVisibilityGlobal}
assert.True(t, s.CanAccess(macro, 1, "administrator", "destroy"))
}
func TestMacroService_CanAccess_ExecuteGlobal_Cov7(t *testing.T) {
s := NewMacroService(nil)
macro := &Macro{Visibility: MacroVisibilityGlobal}
assert.True(t, s.CanAccess(macro, 1, "agent", "execute"))
}
func TestMacroService_CanAccess_UnknownAction_Cov7(t *testing.T) {
s := NewMacroService(nil)
macro := &Macro{Visibility: MacroVisibilityGlobal}
assert.False(t, s.CanAccess(macro, 1, "agent", "unknown"))
}
// ===========================
// Condition struct JSON tests
// ===========================
func TestCondition_JSON_Cov7(t *testing.T) {
c := Condition{Attribute: "status", FilterOperator: "equal", Values: []string{"open"}}
data, err := json.Marshal(c)
require.NoError(t, err)
assert.Contains(t, string(data), "status")
assert.Contains(t, string(data), "equal")
}
func TestAction_JSON_Cov7(t *testing.T) {
a := Action{ActionName: "send_message", ActionParams: map[string]interface{}{"content": "hi"}}
data, err := json.Marshal(a)
require.NoError(t, err)
assert.Contains(t, string(data), "send_message")
}
// ===========================
// ActionExecutionResult struct tests
// ===========================
func TestActionExecutionResult_JSON_Cov7(t *testing.T) {
r := ActionExecutionResult{ActionName: "test", Status: "success"}
data, err := json.Marshal(r)
require.NoError(t, err)
assert.Contains(t, string(data), "test")
assert.Contains(t, string(data), "success")
}
// ===========================
// ActionDeliveryResult struct tests
// ===========================
func TestActionDeliveryResult_Cov7(t *testing.T) {
r := ActionDeliveryResult{DeliveryType: "webhook", Target: "url", Attempts: 1}
assert.Equal(t, "webhook", r.DeliveryType)
assert.Equal(t, "url", r.Target)
assert.Equal(t, 1, r.Attempts)
}
// ===========================
// AutomationWebhookRequest struct tests
// ===========================
func TestAutomationWebhookRequest_Cov7(t *testing.T) {
r := AutomationWebhookRequest{AccountID: 1, ConversationID: 2, URL: "http://test"}
assert.Equal(t, uint(1), r.AccountID)
}
// ===========================
// AutomationTranscriptRequest struct tests
// ===========================
func TestAutomationTranscriptRequest_Cov7(t *testing.T) {
r := AutomationTranscriptRequest{Recipient: "test@example.com", Subject: "Test"}
assert.Equal(t, "test@example.com", r.Recipient)
}
// ===========================
// CsatListFilter struct tests
// ===========================
func TestCsatListFilter_Cov7(t *testing.T) {
f := CsatListFilter{}
assert.Nil(t, f.AgentID)
assert.Nil(t, f.InboxID)
}
// ===========================
// Context and misc tests
// ===========================
func TestContext_Cov7(t *testing.T) {
ctx := context.Background()
assert.NotNil(t, ctx)
}
func TestStringsContains_Cov7(t *testing.T) {
assert.True(t, strings.Contains("hello world", "world"))
}
func TestStringsEqualFold_Cov7(t *testing.T) {
assert.True(t, strings.EqualFold("hello", "HELLO"))
}
func TestStringsTrimSpace_Cov7(t *testing.T) {
assert.Equal(t, "test", strings.TrimSpace(" test "))
}
func TestStringsSplit_Cov7(t *testing.T) {
parts := strings.Split("a,b,c", ",")
assert.Len(t, parts, 3)
}
func TestFmtSprintf_Cov7(t *testing.T) {
assert.Equal(t, "test: 42", fmt.Sprintf("test: %d", 42))
}
func TestFmtErrorf_Cov7(t *testing.T) {
err := fmt.Errorf("error: %s", "detail")
assert.Contains(t, err.Error(), "detail")
}