github.com/prebid/prebid-server/v2@v2.18.0/adapters/appnexus/appnexus_test.go (about) 1 package appnexus 2 3 import ( 4 "net/url" 5 "testing" 6 7 "github.com/prebid/prebid-server/v2/adapters/adapterstest" 8 "github.com/prebid/prebid-server/v2/config" 9 "github.com/prebid/prebid-server/v2/openrtb_ext" 10 "github.com/stretchr/testify/assert" 11 "github.com/stretchr/testify/require" 12 ) 13 14 func TestJsonSamples(t *testing.T) { 15 bidder, buildErr := Builder(openrtb_ext.BidderAppnexus, config.Adapter{ 16 Endpoint: "http://ib.adnxs.com/openrtb2"}, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"}) 17 18 if buildErr != nil { 19 t.Fatalf("Builder returned unexpected error %v", buildErr) 20 } 21 22 bidderAppNexus, _ := bidder.(*adapter) 23 bidderAppNexus.randomGenerator = FakeRandomNumberGenerator{Number: 10} 24 25 adapterstest.RunJSONBidderTest(t, "appnexustest", bidder) 26 } 27 28 func TestAppendMemberID(t *testing.T) { 29 uri, err := url.Parse("http://ib.adnxs.com/openrtb2?query_param=true") 30 require.NoError(t, err, "Failed to parse URI with query string") 31 32 uriWithMember := appendMemberId(*uri, "102") 33 expected := "http://ib.adnxs.com/openrtb2?member_id=102&query_param=true" 34 assert.Equal(t, expected, uriWithMember.String(), "Failed to append member id to URI with query string") 35 } 36 37 func TestBuilderWithPlatformID(t *testing.T) { 38 bidder, buildErr := Builder(openrtb_ext.BidderAppnexus, config.Adapter{ 39 Endpoint: "http://ib.adnxs.com/openrtb2", PlatformID: "3"}, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"}) 40 41 assert.NoError(t, buildErr) 42 require.NotNil(t, bidder) 43 assert.Equal(t, 3, (*bidder.(*adapter)).hbSource) 44 } 45 46 type FakeRandomNumberGenerator struct { 47 Number int64 48 } 49 50 func (f FakeRandomNumberGenerator) GenerateInt63() int64 { 51 return f.Number 52 }