github.com/prebid/prebid-server/v2@v2.18.0/adapters/richaudience/richaudience_test.go (about) 1 package richaudience 2 3 import ( 4 "net/http" 5 "testing" 6 7 "github.com/prebid/openrtb/v20/openrtb2" 8 "github.com/prebid/prebid-server/v2/adapters" 9 "github.com/prebid/prebid-server/v2/adapters/adapterstest" 10 "github.com/prebid/prebid-server/v2/config" 11 "github.com/prebid/prebid-server/v2/openrtb_ext" 12 "github.com/stretchr/testify/assert" 13 ) 14 15 type richaudienceRequest struct { 16 ID string `json:"id,omitempty"` 17 Imp []openrtb2.Imp `json:"imp,omitempty"` 18 User richaudienceUser `json:"user,omitempty"` 19 Device richaudienceDevice `json:"device,omitempty"` 20 Site richaudienceSite `json:"site,omitempty"` 21 Test int8 `json:"test,omitempty"` 22 } 23 24 type richaudienceUser struct { 25 BuyerUID string `json:"buyeruid,omitempty"` 26 Ext richaudienceUserExt `json:"ext,omitempty"` 27 } 28 29 type richaudienceUserExt struct { 30 Eids []openrtb2.EID `json:"eids,omitempty"` 31 Consent string `json:"consent,omitempty"` 32 } 33 34 type richaudienceDevice struct { 35 IP string `json:"ip,omitempty"` 36 IPv6 string `json:"ipv6,omitempty"` 37 Lmt int8 `json:"lmt,omitempty"` 38 DNT int8 `json:"dnt,omitempty"` 39 UA string `json:"ua,omitempty"` 40 } 41 42 type richaudienceSite struct { 43 Domain string `json:"domain,omitempty"` 44 Page string `json:"page,omitempty"` 45 } 46 47 func TestJsonSamples(t *testing.T) { 48 bidder, buildErr := Builder(openrtb_ext.BidderRichaudience, config.Adapter{ 49 Endpoint: "http://ortb.richaudience.com/ortb/?bidder=pbs", 50 }, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"}) 51 52 if buildErr != nil { 53 t.Fatalf("Builder returned unexpected error %v", buildErr) 54 } 55 56 adapterstest.RunJSONBidderTest(t, "richaudiencetest", bidder) 57 } 58 59 func TestGetBuilder(t *testing.T) { 60 bidder, buildErr := Builder(openrtb_ext.BidderRichaudience, config.Adapter{ 61 Endpoint: "http://ortb.richaudience.com/ortb/?bidder=pbs"}, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"}) 62 63 if buildErr != nil { 64 t.Errorf("error %s", buildErr) 65 } 66 67 adapterstest.RunJSONBidderTest(t, "richaudiencetest", bidder) 68 } 69 70 func TestGetSite(t *testing.T) { 71 raBidRequest := &openrtb2.BidRequest{ 72 Site: &openrtb2.Site{ 73 Domain: "www.test.com", 74 }, 75 } 76 77 richaudienceRequestTest := &richaudienceRequest{ 78 Site: richaudienceSite{ 79 Domain: "www.test.com", 80 }, 81 } 82 83 getIsUrlSecure(raBidRequest) 84 85 if raBidRequest.Site.Domain != richaudienceRequestTest.Site.Domain { 86 t.Errorf("error %s", richaudienceRequestTest.Site.Domain) 87 } 88 89 raBidRequest = &openrtb2.BidRequest{ 90 Site: &openrtb2.Site{ 91 Page: "http://www.test.com/test", 92 Domain: "", 93 }, 94 } 95 96 richaudienceRequestTest = &richaudienceRequest{ 97 Site: richaudienceSite{ 98 Domain: "", 99 }, 100 } 101 102 getIsUrlSecure(raBidRequest) 103 } 104 105 func TestGetDevice(t *testing.T) { 106 107 raBidRequest := &openrtb2.BidRequest{ 108 Device: &openrtb2.Device{ 109 IP: "11.222.33.44", 110 UA: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36", 111 }, 112 } 113 114 richaudienceRequestTest := &richaudienceRequest{ 115 Device: richaudienceDevice{ 116 IP: "11.222.33.44", 117 Lmt: 0, 118 DNT: 0, 119 UA: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36", 120 }, 121 } 122 123 if raBidRequest.Device.IP != richaudienceRequestTest.Device.IP { 124 t.Errorf("error %s", richaudienceRequestTest.Device.IP) 125 } 126 127 if richaudienceRequestTest.Device.Lmt == 1 { 128 t.Errorf("error %v", richaudienceRequestTest.Device.Lmt) 129 } 130 131 if richaudienceRequestTest.Device.DNT == 1 { 132 t.Errorf("error %v", richaudienceRequestTest.Device.DNT) 133 } 134 135 if raBidRequest.Device.UA != richaudienceRequestTest.Device.UA { 136 t.Errorf("error %s", richaudienceRequestTest.Device.UA) 137 } 138 } 139 140 func TestResponseEmpty(t *testing.T) { 141 httpResp := &adapters.ResponseData{ 142 StatusCode: http.StatusNoContent, 143 } 144 bidder := new(adapter) 145 bidResponse, errs := bidder.MakeBids(nil, nil, httpResp) 146 147 assert.Nil(t, bidResponse, "Expected Nil") 148 assert.Empty(t, errs, "Errors: %d", len(errs)) 149 } 150 151 func TestEmptyConfig(t *testing.T) { 152 bidder, buildErr := Builder(openrtb_ext.BidderRichaudience, config.Adapter{ 153 Endpoint: ``, 154 ExtraAdapterInfo: ``, 155 }, config.Server{}) 156 157 assert.NoError(t, buildErr) 158 assert.Empty(t, bidder) 159 }