github.com/prebid/prebid-server/v2@v2.18.0/endpoints/getuids_test.go (about) 1 package endpoints 2 3 import ( 4 "net/http" 5 "net/http/httptest" 6 "testing" 7 8 "github.com/prebid/prebid-server/v2/config" 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func TestGetUIDs(t *testing.T) { 13 req := makeRequest("/getuids", map[string]string{"adnxs": "123", "audienceNetwork": "456"}) 14 endpoint := NewGetUIDsEndpoint(config.HostCookie{}) 15 res := httptest.NewRecorder() 16 endpoint(res, req, nil) 17 18 assert.Equal(t, http.StatusOK, res.Code) 19 assert.JSONEq(t, `{"buyeruids": {"adnxs": "123", "audienceNetwork": "456"}}`, 20 res.Body.String(), "GetUIDs endpoint should return the correct user ID for each bidder") 21 } 22 23 func TestGetUIDsWithNoSyncs(t *testing.T) { 24 req := makeRequest("/getuids", map[string]string{}) 25 endpoint := NewGetUIDsEndpoint(config.HostCookie{}) 26 res := httptest.NewRecorder() 27 endpoint(res, req, nil) 28 29 assert.Equal(t, http.StatusOK, res.Code) 30 assert.JSONEq(t, `{}`, res.Body.String(), "GetUIDs endpoint shouldn't return anything if there don't exist any user syncs") 31 } 32 33 func TestGetUIDWIthNoCookie(t *testing.T) { 34 req := httptest.NewRequest("GET", "/getuids", nil) 35 endpoint := NewGetUIDsEndpoint(config.HostCookie{}) 36 res := httptest.NewRecorder() 37 endpoint(res, req, nil) 38 39 assert.Equal(t, http.StatusOK, res.Code) 40 assert.JSONEq(t, `{}`, res.Body.String(), "GetUIDs endpoint shouldn't return anything if there doesn't exist a PBS cookie") 41 }