97 lines
2.6 KiB
Go
97 lines
2.6 KiB
Go
package service
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
// === inbox_service helper function tests ===
|
|
|
|
func TestIsInboxLimitExceeded_Cov19(t *testing.T) {
|
|
assert.False(t, IsInboxLimitExceeded(nil))
|
|
assert.False(t, IsInboxLimitExceeded(assertError("some error")))
|
|
assert.True(t, IsInboxLimitExceeded(ErrInboxLimitExceeded))
|
|
}
|
|
|
|
func TestNormalizeInboxSenderNameType_Cov19(t *testing.T) {
|
|
assert.Equal(t, "friendly", normalizeInboxSenderNameType("friendly"))
|
|
assert.Equal(t, "friendly", normalizeInboxSenderNameType("Friendly"))
|
|
assert.Equal(t, "friendly", normalizeInboxSenderNameType(" friendly "))
|
|
assert.Equal(t, "friendly", normalizeInboxSenderNameType(""))
|
|
assert.Equal(t, "raw", normalizeInboxSenderNameType("raw"))
|
|
}
|
|
|
|
func TestDefaultInboxName_Cov19(t *testing.T) {
|
|
name := defaultInboxName("api", map[string]any{"name": "MyBot"})
|
|
assert.Equal(t, "MyBot", name)
|
|
name2 := defaultInboxName("api", map[string]any{"bot_name": "TestBot"})
|
|
assert.Equal(t, "TestBot", name2)
|
|
name3 := defaultInboxName("api", map[string]any{})
|
|
assert.NotEmpty(t, name3)
|
|
}
|
|
|
|
func TestFormatInboxCsatConfig_Cov19(t *testing.T) {
|
|
config := map[string]any{
|
|
"enabled": true,
|
|
"response_message": "Please rate",
|
|
"thank_message": "Thanks!",
|
|
}
|
|
result := formatInboxCsatConfig(config)
|
|
assert.NotNil(t, result)
|
|
assert.Contains(t, result, "enabled")
|
|
}
|
|
|
|
func TestFormatInboxCsatConfig_Empty_Cov19(t *testing.T) {
|
|
result := formatInboxCsatConfig(map[string]any{})
|
|
assert.NotNil(t, result)
|
|
}
|
|
|
|
func TestFormatInboxCsatConfig_Nil_Cov19(t *testing.T) {
|
|
result := formatInboxCsatConfig(nil)
|
|
assert.NotNil(t, result)
|
|
}
|
|
|
|
// === conversation_service helper function tests ===
|
|
|
|
func TestConversationService_DB_Nil_Cov19(t *testing.T) {
|
|
var svc *ConversationService
|
|
assert.Nil(t, svc.DB())
|
|
}
|
|
|
|
// === widget_service helper function tests ===
|
|
|
|
func TestReverseMessages_NilSafe_Cov19(t *testing.T) {
|
|
reverseMessages(nil) // should not panic
|
|
}
|
|
|
|
// === contact_service helper function tests ===
|
|
|
|
func TestContactService_DB_Nil_Cov19(t *testing.T) {
|
|
var svc *ContactService
|
|
assert.Nil(t, svc.DB())
|
|
}
|
|
|
|
// === account_service helper function tests ===
|
|
|
|
func TestAccountService_DB_Nil_Cov19(t *testing.T) {
|
|
var svc *AccountService
|
|
assert.Nil(t, svc.DB())
|
|
}
|
|
|
|
// === inbox_service DB/Ready tests ===
|
|
|
|
func TestInboxService_DB_Nil_Cov19(t *testing.T) {
|
|
var svc *InboxService
|
|
assert.Nil(t, svc.DB())
|
|
}
|
|
|
|
// Helper to create an error
|
|
type simpleError struct{ msg string }
|
|
|
|
func (e *simpleError) Error() string { return e.msg }
|
|
|
|
func assertError(msg string) error {
|
|
return &simpleError{msg: msg}
|
|
}
|