channel_websearch_test.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package service
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/require"
  5. )
  6. func TestChannel_IsWebSearchEmulationEnabled_Enabled(t *testing.T) {
  7. c := &Channel{
  8. FeaturesConfig: map[string]any{
  9. featureKeyWebSearchEmulation: map[string]any{"anthropic": true},
  10. },
  11. }
  12. require.True(t, c.IsWebSearchEmulationEnabled("anthropic"))
  13. }
  14. func TestChannel_IsWebSearchEmulationEnabled_DifferentPlatform(t *testing.T) {
  15. c := &Channel{
  16. FeaturesConfig: map[string]any{
  17. featureKeyWebSearchEmulation: map[string]any{"anthropic": true},
  18. },
  19. }
  20. require.False(t, c.IsWebSearchEmulationEnabled("openai"))
  21. }
  22. func TestChannel_IsWebSearchEmulationEnabled_Disabled(t *testing.T) {
  23. c := &Channel{
  24. FeaturesConfig: map[string]any{
  25. featureKeyWebSearchEmulation: map[string]any{"anthropic": false},
  26. },
  27. }
  28. require.False(t, c.IsWebSearchEmulationEnabled("anthropic"))
  29. }
  30. func TestChannel_IsWebSearchEmulationEnabled_NilFeaturesConfig(t *testing.T) {
  31. c := &Channel{FeaturesConfig: nil}
  32. require.False(t, c.IsWebSearchEmulationEnabled("anthropic"))
  33. }
  34. func TestChannel_IsWebSearchEmulationEnabled_NilChannel(t *testing.T) {
  35. var c *Channel
  36. require.False(t, c.IsWebSearchEmulationEnabled("anthropic"))
  37. }
  38. func TestChannel_IsWebSearchEmulationEnabled_WrongStructure(t *testing.T) {
  39. c := &Channel{
  40. FeaturesConfig: map[string]any{
  41. featureKeyWebSearchEmulation: true, // not a map
  42. },
  43. }
  44. require.False(t, c.IsWebSearchEmulationEnabled("anthropic"))
  45. }
  46. func TestChannel_IsWebSearchEmulationEnabled_PlatformValueNotBool(t *testing.T) {
  47. c := &Channel{
  48. FeaturesConfig: map[string]any{
  49. featureKeyWebSearchEmulation: map[string]any{"anthropic": "yes"},
  50. },
  51. }
  52. require.False(t, c.IsWebSearchEmulationEnabled("anthropic"))
  53. }