openai_image_intent_hint_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package handler
  2. import (
  3. "testing"
  4. "github.com/Wei-Shaw/sub2api/internal/service"
  5. "github.com/gin-gonic/gin"
  6. "github.com/stretchr/testify/require"
  7. )
  8. func TestSeedOpenAIForwardImageIntentHint(t *testing.T) {
  9. gin.SetMode(gin.TestMode)
  10. tests := []struct {
  11. name string
  12. channelMapped bool
  13. imageIntent bool
  14. wantHint bool
  15. }{
  16. {name: "seed true", imageIntent: true, wantHint: true},
  17. {name: "seed false", imageIntent: false, wantHint: true},
  18. {name: "mapped body stays unknown", channelMapped: true, imageIntent: true},
  19. }
  20. for _, tt := range tests {
  21. t.Run(tt.name, func(t *testing.T) {
  22. c := &gin.Context{}
  23. service.SetOpenAIClientTransport(c, service.OpenAIClientTransportHTTP)
  24. seedOpenAIForwardImageIntentHint(c, tt.channelMapped, tt.imageIntent)
  25. var hintValues []bool
  26. for _, value := range c.Keys {
  27. if hint, ok := value.(bool); ok {
  28. hintValues = append(hintValues, hint)
  29. }
  30. }
  31. if !tt.wantHint {
  32. require.Empty(t, hintValues)
  33. return
  34. }
  35. require.Equal(t, []bool{tt.imageIntent}, hintValues)
  36. })
  37. }
  38. }