@@ -701,6 +701,176 @@ public void makeBidsShouldHandleLargeDecimalPrices() throws JsonProcessingExcept
701701 .containsOnly (tuple ("http://example.com/nurl?price=123456789.123456789" , "<div>Price: 123456789.123456789</div>" ));
702702 }
703703
704+ @ Test
705+ public void makeBidsShouldReplacePriceMacroInBurlWithBidPrice () throws JsonProcessingException {
706+ // given
707+ final BidderCall <BidRequest > httpCall = givenHttpCall (
708+ givenBidResponse (bidBuilder -> bidBuilder
709+ .mtype (1 )
710+ .impid ("123" )
711+ .price (BigDecimal .valueOf (1.23 ))
712+ .burl ("http://example.com/burl?price=${AUCTION_PRICE}" )));
713+
714+ // when
715+ final Result <List <BidderBid >> result = target .makeBids (httpCall , null );
716+
717+ // then
718+ assertThat (result .getErrors ()).isEmpty ();
719+ assertThat (result .getValue ()).hasSize (1 )
720+ .extracting (BidderBid ::getBid )
721+ .extracting (Bid ::getBurl )
722+ .containsOnly ("http://example.com/burl?price=1.23" );
723+ }
724+
725+ @ Test
726+ public void makeBidsShouldReplacePriceMacroInBurlWithZeroWhenBidPriceIsNull () throws JsonProcessingException {
727+ // given
728+ final BidderCall <BidRequest > httpCall = givenHttpCall (
729+ givenBidResponse (bidBuilder -> bidBuilder
730+ .mtype (1 )
731+ .impid ("123" )
732+ .price (null )
733+ .burl ("http://example.com/burl?price=${AUCTION_PRICE}" )));
734+
735+ // when
736+ final Result <List <BidderBid >> result = target .makeBids (httpCall , null );
737+
738+ // then
739+ assertThat (result .getErrors ()).isEmpty ();
740+ assertThat (result .getValue ()).hasSize (1 )
741+ .extracting (BidderBid ::getBid )
742+ .extracting (Bid ::getBurl )
743+ .containsOnly ("http://example.com/burl?price=0" );
744+ }
745+
746+ @ Test
747+ public void makeBidsShouldReplacePriceMacroInBurlWithZeroWhenBidPriceIsZero () throws JsonProcessingException {
748+ // given
749+ final BidderCall <BidRequest > httpCall = givenHttpCall (
750+ givenBidResponse (bidBuilder -> bidBuilder
751+ .mtype (1 )
752+ .impid ("123" )
753+ .price (BigDecimal .ZERO )
754+ .burl ("http://example.com/burl?price=${AUCTION_PRICE}" )));
755+
756+ // when
757+ final Result <List <BidderBid >> result = target .makeBids (httpCall , null );
758+
759+ // then
760+ assertThat (result .getErrors ()).isEmpty ();
761+ assertThat (result .getValue ()).hasSize (1 )
762+ .extracting (BidderBid ::getBid )
763+ .extracting (Bid ::getBurl )
764+ .containsOnly ("http://example.com/burl?price=0" );
765+ }
766+
767+ @ Test
768+ public void makeBidsShouldNotReplacePriceMacroInBurlWhenDoesNotContainMacro () throws JsonProcessingException {
769+ // given
770+ final BidderCall <BidRequest > httpCall = givenHttpCall (
771+ givenBidResponse (bidBuilder -> bidBuilder
772+ .mtype (1 )
773+ .impid ("123" )
774+ .price (BigDecimal .valueOf (5.67 ))
775+ .burl ("http://example.com/burl" )));
776+
777+ // when
778+ final Result <List <BidderBid >> result = target .makeBids (httpCall , null );
779+
780+ // then
781+ assertThat (result .getErrors ()).isEmpty ();
782+ assertThat (result .getValue ()).hasSize (1 )
783+ .extracting (BidderBid ::getBid )
784+ .extracting (Bid ::getBurl )
785+ .containsOnly ("http://example.com/burl" );
786+ }
787+
788+ @ Test
789+ public void makeBidsShouldHandleNullBurl () throws JsonProcessingException {
790+ // given
791+ final BidderCall <BidRequest > httpCall = givenHttpCall (
792+ givenBidResponse (bidBuilder -> bidBuilder
793+ .mtype (1 )
794+ .impid ("123" )
795+ .price (BigDecimal .valueOf (15.00 ))
796+ .burl (null )));
797+
798+ // when
799+ final Result <List <BidderBid >> result = target .makeBids (httpCall , null );
800+
801+ // then
802+ assertThat (result .getErrors ()).isEmpty ();
803+ assertThat (result .getValue ()).hasSize (1 )
804+ .extracting (BidderBid ::getBid )
805+ .extracting (Bid ::getBurl )
806+ .containsOnly ((String ) null );
807+ }
808+
809+ @ Test
810+ public void makeBidsShouldReplaceMultiplePriceMacrosInBurl () throws JsonProcessingException {
811+ // given
812+ final BidderCall <BidRequest > httpCall = givenHttpCall (
813+ givenBidResponse (bidBuilder -> bidBuilder
814+ .mtype (1 )
815+ .impid ("123" )
816+ .price (BigDecimal .valueOf (9.99 ))
817+ .burl ("http://example.com/burl?price=${AUCTION_PRICE}&backup_price=${AUCTION_PRICE}" )));
818+
819+ // when
820+ final Result <List <BidderBid >> result = target .makeBids (httpCall , null );
821+
822+ // then
823+ assertThat (result .getErrors ()).isEmpty ();
824+ assertThat (result .getValue ()).hasSize (1 )
825+ .extracting (BidderBid ::getBid )
826+ .extracting (Bid ::getBurl )
827+ .containsOnly ("http://example.com/burl?price=9.99&backup_price=9.99" );
828+ }
829+
830+ @ Test
831+ public void makeBidsShouldHandleLargeDecimalPricesInBurl () throws JsonProcessingException {
832+ // given
833+ final BidderCall <BidRequest > httpCall = givenHttpCall (
834+ givenBidResponse (bidBuilder -> bidBuilder
835+ .mtype (1 )
836+ .impid ("123" )
837+ .price (new BigDecimal ("123456789.123456789" ))
838+ .burl ("http://example.com/burl?price=${AUCTION_PRICE}" )));
839+
840+ // when
841+ final Result <List <BidderBid >> result = target .makeBids (httpCall , null );
842+
843+ // then
844+ assertThat (result .getErrors ()).isEmpty ();
845+ assertThat (result .getValue ()).hasSize (1 )
846+ .extracting (BidderBid ::getBid )
847+ .extracting (Bid ::getBurl )
848+ .containsOnly ("http://example.com/burl?price=123456789.123456789" );
849+ }
850+
851+ @ Test
852+ public void makeBidsShouldReplacePriceMacroInAllFieldsSimultaneously () throws JsonProcessingException {
853+ // given
854+ final BidderCall <BidRequest > httpCall = givenHttpCall (
855+ givenBidResponse (bidBuilder -> bidBuilder
856+ .mtype (1 )
857+ .impid ("123" )
858+ .price (BigDecimal .valueOf (2.50 ))
859+ .nurl ("http://example.com/nurl?price=${AUCTION_PRICE}" )
860+ .adm ("<div>Price: ${AUCTION_PRICE}</div>" )
861+ .burl ("http://example.com/burl?price=${AUCTION_PRICE}" )));
862+
863+ // when
864+ final Result <List <BidderBid >> result = target .makeBids (httpCall , null );
865+
866+ // then
867+ assertThat (result .getErrors ()).isEmpty ();
868+ assertThat (result .getValue ()).hasSize (1 )
869+ .extracting (BidderBid ::getBid )
870+ .extracting (Bid ::getNurl , Bid ::getAdm , Bid ::getBurl )
871+ .containsOnly (tuple ("http://example.com/nurl?price=2.5" , "<div>Price: 2.5</div>" , "http://example.com/burl?price=2.5" ));
872+ }
873+
704874 private String givenBidResponse (UnaryOperator <Bid .BidBuilder > bidCustomizer ) throws JsonProcessingException {
705875 return mapper .writeValueAsString (BidResponse .builder ()
706876 .cur ("USD" )
0 commit comments