1717import org .prebid .server .bidder .model .HttpRequest ;
1818import org .prebid .server .bidder .model .HttpResponse ;
1919import org .prebid .server .bidder .model .Result ;
20+ import org .prebid .server .proto .openrtb .ext .ExtPrebid ;
21+ import org .prebid .server .proto .openrtb .ext .request .smilewanted .ExtImpSmilewanted ;
2022import org .prebid .server .util .HttpUtil ;
2123
24+ import java .math .BigDecimal ;
25+ import java .util .Arrays ;
2226import java .util .List ;
2327import java .util .Map ;
2428import java .util .function .Function ;
3236
3337public class SmileWantedBidderTest extends VertxTest {
3438
35- private static final String ENDPOINT_URL = "https://{{Host}}/test?param={{PublisherId }}" ;
39+ private static final String ENDPOINT_URL = "https://prebid-server.smilewanted.com/java/{{ZoneId }}" ;
3640
3741 private final SmileWantedBidder target = new SmileWantedBidder (ENDPOINT_URL , jacksonMapper );
3842
@@ -41,10 +45,76 @@ public void creationShouldFailOnInvalidEndpointUrl() {
4145 assertThatIllegalArgumentException ().isThrownBy (() -> new SmileWantedBidder ("invalid_url" , jacksonMapper ));
4246 }
4347
48+ @ Test
49+ public void makeHttpRequestsShouldReturnErrorIfImpExtCouldNotBeParsed () {
50+ // given
51+ final BidRequest bidRequest = BidRequest .builder ()
52+ .imp (singletonList (Imp .builder ()
53+ .id ("123" )
54+ .ext (mapper .valueToTree (ExtPrebid .of (null , mapper .createArrayNode ())))
55+ .build ()))
56+ .build ();
57+
58+ // when
59+ final Result <List <HttpRequest <BidRequest >>> result = target .makeHttpRequests (bidRequest );
60+
61+ // then
62+ assertThat (result .getValue ()).isEmpty ();
63+ assertThat (result .getErrors ()).hasSize (1 )
64+ .allSatisfy (error -> {
65+ assertThat (error .getType ()).isEqualTo (BidderError .Type .bad_input );
66+ assertThat (error .getMessage ()).startsWith ("Missing bidder ext in impression with id: 123" );
67+ });
68+ }
69+
70+ @ Test
71+ public void makeHttpRequestsShouldReturnSingleRequest () {
72+ // given
73+ final BidRequest bidRequest = BidRequest .builder ()
74+ .imp (List .of (
75+ givenImp ("zone123" ),
76+ Imp .builder ()
77+ .id ("456" )
78+ .ext (mapper .valueToTree (ExtPrebid .of (null , ExtImpSmilewanted .of ("zone123" ))))
79+ .build ()))
80+ .build ();
81+
82+ // when
83+ final Result <List <HttpRequest <BidRequest >>> result = target .makeHttpRequests (bidRequest );
84+
85+ // then
86+ assertThat (result .getErrors ()).isEmpty ();
87+ assertThat (result .getValue ()).hasSize (1 );
88+ final HttpRequest <BidRequest > httpRequest = result .getValue ().get (0 );
89+ assertThat (httpRequest .getPayload ()).isNotNull ();
90+ assertThat (httpRequest .getPayload ().getImp ()).hasSize (2 );
91+ assertThat (httpRequest .getPayload ().getAt ()).isEqualTo (1 );
92+ assertThat (httpRequest .getImpIds ()).containsExactlyInAnyOrder ("123" , "456" );
93+ }
94+
95+ @ Test
96+ public void makeHttpRequestsShouldBuildCorrectEndpointUrlWithZoneId () {
97+ // given
98+ final BidRequest bidRequest = BidRequest .builder ()
99+ .imp (singletonList (givenImp ("zone456" )))
100+ .build ();
101+
102+ // when
103+ final Result <List <HttpRequest <BidRequest >>> result = target .makeHttpRequests (bidRequest );
104+
105+ // then
106+ assertThat (result .getErrors ()).isEmpty ();
107+ assertThat (result .getValue ())
108+ .extracting (HttpRequest ::getUri )
109+ .containsExactly ("https://prebid-server.smilewanted.com/java/zone456" );
110+ }
111+
44112 @ Test
45113 public void makeHttpRequestsShouldCorrectlyAddHeaders () {
46114 // given
47- final BidRequest bidRequest = BidRequest .builder ().build ();
115+ final BidRequest bidRequest = BidRequest .builder ()
116+ .imp (singletonList (givenImp ("zone123" )))
117+ .build ();
48118
49119 // when
50120 final Result <List <HttpRequest <BidRequest >>> result = target .makeHttpRequests (bidRequest );
@@ -65,7 +135,9 @@ public void makeHttpRequestsShouldCorrectlyAddHeaders() {
65135 @ Test
66136 public void makeHttpRequestsShouldSetAtToOne () {
67137 // given
68- final BidRequest bidRequest = BidRequest .builder ().build ();
138+ final BidRequest bidRequest = BidRequest .builder ()
139+ .imp (singletonList (givenImp ("zone123" )))
140+ .build ();
69141
70142 // when
71143 final Result <List <HttpRequest <BidRequest >>> result = target .makeHttpRequests (bidRequest );
@@ -160,6 +232,105 @@ public void makeBidsShouldReturnBannerBidIfVideoIsAbsentInRequestImp() throws Js
160232 .containsOnly (BidderBid .of (Bid .builder ().impid ("123" ).build (), banner , null ));
161233 }
162234
235+ @ Test
236+ public void makeBidsShouldReturnMultipleBidsFromSingleSeatBid () throws JsonProcessingException {
237+ // given
238+ final BidderCall <BidRequest > httpCall = givenHttpCall (
239+ BidRequest .builder ()
240+ .imp (List .of (
241+ Imp .builder ().id ("123" ).build (),
242+ Imp .builder ().id ("456" ).video (Video .builder ().build ()).build ()))
243+ .build (),
244+ mapper .writeValueAsString (
245+ BidResponse .builder ()
246+ .cur ("USD" )
247+ .seatbid (singletonList (SeatBid .builder ()
248+ .bid (List .of (
249+ Bid .builder ().impid ("123" ).price (BigDecimal .valueOf (1.0 )).build (),
250+ Bid .builder ().impid ("456" ).price (BigDecimal .valueOf (2.0 )).build ()))
251+ .build ()))
252+ .build ()));
253+
254+ // when
255+ final Result <List <BidderBid >> result = target .makeBids (httpCall , null );
256+
257+ // then
258+ assertThat (result .getErrors ()).isEmpty ();
259+ assertThat (result .getValue ()).hasSize (2 )
260+ .containsExactlyInAnyOrder (
261+ BidderBid .of (Bid .builder ().impid ("123" ).price (BigDecimal .valueOf (1.0 )).build (), banner , "USD" ),
262+ BidderBid .of (Bid .builder ().impid ("456" ).price (BigDecimal .valueOf (2.0 )).build (), video , "USD" ));
263+ }
264+
265+ @ Test
266+ public void makeBidsShouldFilterNullBids () throws JsonProcessingException {
267+ // given
268+ final BidderCall <BidRequest > httpCall = givenHttpCall (
269+ BidRequest .builder ()
270+ .imp (singletonList (Imp .builder ().id ("123" ).build ()))
271+ .build (),
272+ mapper .writeValueAsString (
273+ BidResponse .builder ()
274+ .seatbid (singletonList (SeatBid .builder ()
275+ .bid (Arrays .asList (
276+ Bid .builder ().impid ("123" ).build (),
277+ null ,
278+ Bid .builder ().impid ("456" ).build ()))
279+ .build ()))
280+ .build ()));
281+
282+ // when
283+ final Result <List <BidderBid >> result = target .makeBids (httpCall , null );
284+
285+ // then
286+ assertThat (result .getErrors ()).isEmpty ();
287+ assertThat (result .getValue ()).hasSize (2 )
288+ .extracting (BidderBid ::getBid )
289+ .extracting (Bid ::getImpid )
290+ .containsExactlyInAnyOrder ("123" , "456" );
291+ }
292+
293+ @ Test
294+ public void makeBidsShouldReturnBidWithCurrency () throws JsonProcessingException {
295+ // given
296+ final BidderCall <BidRequest > httpCall = givenHttpCall (
297+ BidRequest .builder ()
298+ .imp (singletonList (Imp .builder ().id ("123" ).build ()))
299+ .build (),
300+ mapper .writeValueAsString (
301+ BidResponse .builder ()
302+ .cur ("EUR" )
303+ .seatbid (singletonList (SeatBid .builder ()
304+ .bid (singletonList (Bid .builder ().impid ("123" ).build ()))
305+ .build ()))
306+ .build ()));
307+
308+ // when
309+ final Result <List <BidderBid >> result = target .makeBids (httpCall , null );
310+
311+ // then
312+ assertThat (result .getErrors ()).isEmpty ();
313+ assertThat (result .getValue ())
314+ .extracting (BidderBid ::getBidCurrency )
315+ .containsExactly ("EUR" );
316+ }
317+
318+ @ Test
319+ public void makeBidsShouldReturnEmptyListIfSeatBidIsEmpty () throws JsonProcessingException {
320+ // given
321+ final BidderCall <BidRequest > httpCall = givenHttpCall (null ,
322+ mapper .writeValueAsString (BidResponse .builder ()
323+ .seatbid (singletonList (SeatBid .builder ().build ()))
324+ .build ()));
325+
326+ // when
327+ final Result <List <BidderBid >> result = target .makeBids (httpCall , null );
328+
329+ // then
330+ assertThat (result .getErrors ()).isEmpty ();
331+ assertThat (result .getValue ()).isEmpty ();
332+ }
333+
163334 private static BidResponse givenBidResponse (Function <Bid .BidBuilder , Bid .BidBuilder > bidCustomizer ) {
164335 return BidResponse .builder ()
165336 .seatbid (singletonList (SeatBid .builder ().bid (singletonList (bidCustomizer .apply (Bid .builder ()).build ()))
@@ -173,4 +344,11 @@ private static BidderCall<BidRequest> givenHttpCall(BidRequest bidRequest, Strin
173344 HttpResponse .of (200 , null , body ),
174345 null );
175346 }
347+
348+ private static Imp givenImp (String zoneId ) {
349+ return Imp .builder ()
350+ .id ("123" )
351+ .ext (mapper .valueToTree (ExtPrebid .of (null , ExtImpSmilewanted .of (zoneId ))))
352+ .build ();
353+ }
176354}
0 commit comments