Files
explorer-monorepo/backend/api/rest/routes_proxy_test.go
defiQUG bdae5a9f6e feat: explorer API, wallet, CCIP scripts, and config refresh
- Backend REST/gateway/track routes, analytics, Blockscout proxy paths.
- Frontend wallet and liquidity surfaces; MetaMask token list alignment.
- Deployment docs, verification scripts, address inventory updates.

Check: go build ./... under backend/ (pass).
Made-with: Cursor
2026-04-07 23:22:12 -07:00

55 lines
1.5 KiB
Go

package rest
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/require"
)
func TestRouteProxyPreservesTargetBasePath(t *testing.T) {
var gotPath string
var gotQuery string
upstream := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
gotPath = r.URL.Path
gotQuery = r.URL.RawQuery
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"ok":true}`))
}))
defer upstream.Close()
t.Setenv("TOKEN_AGGREGATION_API_BASE", upstream.URL+"/token-aggregation")
server := NewServer(nil, 138)
req := httptest.NewRequest(http.MethodGet, "/api/v1/routes/tree?chainId=138&amountIn=1000000", nil)
w := httptest.NewRecorder()
server.handleRouteDecisionTree(w, req)
require.Equal(t, http.StatusOK, w.Code)
require.Equal(t, "/token-aggregation/api/v1/routes/tree", gotPath)
require.Equal(t, "chainId=138&amountIn=1000000", gotQuery)
}
func TestRouteProxyHandlesBaseURLWithoutPath(t *testing.T) {
var gotPath string
upstream := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
gotPath = r.URL.Path
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"ok":true}`))
}))
defer upstream.Close()
t.Setenv("TOKEN_AGGREGATION_API_BASE", upstream.URL)
server := NewServer(nil, 138)
req := httptest.NewRequest(http.MethodGet, "/api/v1/routes/depth?chainId=138", nil)
w := httptest.NewRecorder()
server.handleRouteDepth(w, req)
require.Equal(t, http.StatusOK, w.Code)
require.Equal(t, "/api/v1/routes/depth", gotPath)
}