billing_expr_request_test.go 1012 B

1234567891011121314151617181920212223242526272829303132333435
  1. package helper
  2. import (
  3. "bytes"
  4. "io"
  5. "net/http"
  6. "net/http/httptest"
  7. "testing"
  8. "github.com/QuantumNous/new-api/common"
  9. relaycommon "github.com/QuantumNous/new-api/relay/common"
  10. "github.com/gin-gonic/gin"
  11. "github.com/stretchr/testify/require"
  12. )
  13. func TestResolveIncomingBillingExprRequestInput(t *testing.T) {
  14. gin.SetMode(gin.TestMode)
  15. recorder := httptest.NewRecorder()
  16. ctx, _ := gin.CreateTestContext(recorder)
  17. ctx.Request = httptest.NewRequest(http.MethodPost, "/v1/chat/completions", nil)
  18. ctx.Request.Header.Set("Content-Type", "application/json")
  19. body := []byte(`{"service_tier":"fast"}`)
  20. ctx.Request.Body = io.NopCloser(bytes.NewReader(body))
  21. ctx.Set(common.KeyRequestBody, body)
  22. info := &relaycommon.RelayInfo{
  23. RequestHeaders: map[string]string{"Content-Type": "application/json"},
  24. }
  25. input, err := ResolveIncomingBillingExprRequestInput(ctx, info)
  26. require.NoError(t, err)
  27. require.Equal(t, body, input.Body)
  28. require.Equal(t, "application/json", input.Headers["Content-Type"])
  29. }