account_websearch_test.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //go:build unit
  2. package service
  3. import (
  4. "testing"
  5. "github.com/stretchr/testify/require"
  6. )
  7. func TestGetWebSearchEmulationMode_Enabled(t *testing.T) {
  8. a := &Account{
  9. Platform: PlatformAnthropic,
  10. Type: AccountTypeAPIKey,
  11. Extra: map[string]any{featureKeyWebSearchEmulation: "enabled"},
  12. }
  13. require.Equal(t, WebSearchModeEnabled, a.GetWebSearchEmulationMode())
  14. }
  15. func TestGetWebSearchEmulationMode_Disabled(t *testing.T) {
  16. a := &Account{
  17. Platform: PlatformAnthropic,
  18. Type: AccountTypeAPIKey,
  19. Extra: map[string]any{featureKeyWebSearchEmulation: "disabled"},
  20. }
  21. require.Equal(t, WebSearchModeDisabled, a.GetWebSearchEmulationMode())
  22. }
  23. func TestGetWebSearchEmulationMode_Default(t *testing.T) {
  24. a := &Account{
  25. Platform: PlatformAnthropic,
  26. Type: AccountTypeAPIKey,
  27. Extra: map[string]any{featureKeyWebSearchEmulation: "default"},
  28. }
  29. require.Equal(t, WebSearchModeDefault, a.GetWebSearchEmulationMode())
  30. }
  31. func TestGetWebSearchEmulationMode_UnknownString(t *testing.T) {
  32. a := &Account{
  33. Platform: PlatformAnthropic,
  34. Type: AccountTypeAPIKey,
  35. Extra: map[string]any{featureKeyWebSearchEmulation: "unknown"},
  36. }
  37. require.Equal(t, WebSearchModeDefault, a.GetWebSearchEmulationMode())
  38. }
  39. func TestGetWebSearchEmulationMode_OldBoolTrue(t *testing.T) {
  40. a := &Account{
  41. Platform: PlatformAnthropic,
  42. Type: AccountTypeAPIKey,
  43. Extra: map[string]any{featureKeyWebSearchEmulation: true},
  44. }
  45. // bool true → tolerant fallback → enabled (not default)
  46. require.Equal(t, WebSearchModeEnabled, a.GetWebSearchEmulationMode())
  47. }
  48. func TestGetWebSearchEmulationMode_OldBoolFalse(t *testing.T) {
  49. a := &Account{
  50. Platform: PlatformAnthropic,
  51. Type: AccountTypeAPIKey,
  52. Extra: map[string]any{featureKeyWebSearchEmulation: false},
  53. }
  54. require.Equal(t, WebSearchModeDefault, a.GetWebSearchEmulationMode())
  55. }
  56. func TestGetWebSearchEmulationMode_NilAccount(t *testing.T) {
  57. var a *Account
  58. require.Equal(t, WebSearchModeDefault, a.GetWebSearchEmulationMode())
  59. }
  60. func TestGetWebSearchEmulationMode_NilExtra(t *testing.T) {
  61. a := &Account{
  62. Platform: PlatformAnthropic,
  63. Type: AccountTypeAPIKey,
  64. Extra: nil,
  65. }
  66. require.Equal(t, WebSearchModeDefault, a.GetWebSearchEmulationMode())
  67. }
  68. func TestGetWebSearchEmulationMode_MissingField(t *testing.T) {
  69. a := &Account{
  70. Platform: PlatformAnthropic,
  71. Type: AccountTypeAPIKey,
  72. Extra: map[string]any{},
  73. }
  74. require.Equal(t, WebSearchModeDefault, a.GetWebSearchEmulationMode())
  75. }
  76. func TestGetWebSearchEmulationMode_NonAnthropicPlatform(t *testing.T) {
  77. a := &Account{
  78. Platform: PlatformOpenAI,
  79. Type: AccountTypeAPIKey,
  80. Extra: map[string]any{featureKeyWebSearchEmulation: "enabled"},
  81. }
  82. require.Equal(t, WebSearchModeDefault, a.GetWebSearchEmulationMode())
  83. }
  84. func TestGetWebSearchEmulationMode_NonAPIKeyType(t *testing.T) {
  85. a := &Account{
  86. Platform: PlatformAnthropic,
  87. Type: AccountTypeOAuth,
  88. Extra: map[string]any{featureKeyWebSearchEmulation: "enabled"},
  89. }
  90. require.Equal(t, WebSearchModeDefault, a.GetWebSearchEmulationMode())
  91. }