Skip to content

Commit

Permalink
Conversant: fix bid floor (#1291)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickluck8 committed Aug 9, 2021
1 parent 7d02a0b commit aa12184
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.prebid.server.proto.openrtb.ext.response.BidType;
import org.prebid.server.util.HttpUtil;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -138,14 +139,29 @@ private static Imp modifyImp(Imp imp, ExtImpConversant impExt) {
return imp.toBuilder()
.displaymanager(DISPLAY_MANAGER)
.displaymanagerver(DISPLAY_MANAGER_VER)
.bidfloor(impExt.getBidfloor())
.tagid(impExt.getTagId())
.bidfloor(getBidFloor(imp.getBidfloor(), impExt.getBidfloor()))
.tagid(getTagId(imp.getTagid(), impExt.getTagId()))
.secure(getSecure(imp, impExt))
.banner(modifyBanner(banner, impExt.getPosition()))
.video(video != null && banner == null ? modifyVideo(video, impExt) : video)
.build();
}

private static String getTagId(String tagId, String impExtTagId) {
return StringUtils.isNotEmpty(impExtTagId) ? impExtTagId : tagId;
}

private static BigDecimal getBidFloor(BigDecimal impBidFloor, BigDecimal impExtBidFloor) {

return isValidBidFloor(impExtBidFloor) && !isValidBidFloor(impBidFloor)
? impExtBidFloor
: impBidFloor;
}

private static boolean isValidBidFloor(BigDecimal bidFloor) {
return bidFloor != null && bidFloor.compareTo(BigDecimal.ZERO) > 0;
}

private static Integer getSecure(Imp imp, ExtImpConversant impExt) {
final Integer extSecure = impExt.getSecure();
final Integer impSecure = imp.getSecure();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,44 @@ public void makeBidsShouldUpdateBidWithUUIDIfGenerateBidIdIsTrue() throws JsonPr
.matches(id -> id.matches(UUID_REGEX), "matches UUID format");
}

@Test
public void makeHttpRequestsShouldSetImpBidFloorFromImpExtIfPresentAndImpBidFloorIsInvalid() {
// given
final BidRequest bidRequest = givenBidRequest(
impBuilder -> impBuilder.bidfloor(new BigDecimal(-1.00)),
extBuilder -> extBuilder.bidfloor(BigDecimal.ONE));

// when
final Result<List<HttpRequest<BidRequest>>> result = conversantBidder.makeHttpRequests(bidRequest);

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue()).hasSize(1)
.extracting(httpRequest -> mapper.readValue(httpRequest.getBody(), BidRequest.class))
.flatExtracting(BidRequest::getImp)
.extracting(Imp::getBidfloor)
.containsExactly(BigDecimal.ONE);
}

@Test
public void makeHttpRequestsShouldNotSetImpBidFloorFromImpExt() {
// given
final BidRequest bidRequest = givenBidRequest(
impBuilder -> impBuilder.bidfloor(new BigDecimal(-1.00)),
extBuilder -> extBuilder.bidfloor(new BigDecimal(-2.00)));

// when
final Result<List<HttpRequest<BidRequest>>> result = conversantBidder.makeHttpRequests(bidRequest);

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue()).hasSize(1)
.extracting(httpRequest -> mapper.readValue(httpRequest.getBody(), BidRequest.class))
.flatExtracting(BidRequest::getImp)
.extracting(Imp::getBidfloor)
.containsExactly(new BigDecimal(-1.00));
}

private static BidRequest givenBidRequest(
Function<BidRequest.BidRequestBuilder, BidRequest.BidRequestBuilder> bidRequestCustomizer,
Function<Imp.ImpBuilder, Imp.ImpBuilder> impCustomizer,
Expand Down

0 comments on commit aa12184

Please sign in to comment.