Skip to content

Commit

Permalink
AppNexus: reform bid floor handling (#1261)
Browse files Browse the repository at this point in the history
  • Loading branch information
RodionOrets authored and nickluck8 committed Aug 10, 2021
1 parent bd7feaa commit 93209ed
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ private ImpWithMemberId makeImpWithMemberId(Imp imp, String defaultDisplayManage
}

final BigDecimal reserve = appnexusExt.getReserve();
if (reserve != null && reserve.compareTo(BigDecimal.ZERO) > 0) {
if (!bidFloorIsValid(imp.getBidfloor()) && bidFloorIsValid(reserve)) {
impBuilder.bidfloor(reserve); // This will be broken for non-USD currency.
}

Expand All @@ -324,6 +324,10 @@ private ImpWithMemberId makeImpWithMemberId(Imp imp, String defaultDisplayManage
return ImpWithMemberId.of(impBuilder.build(), appnexusExt.getMember());
}

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

private static AppnexusImpExt makeAppnexusImpExt(ExtImpAppnexus appnexusExt) {
return AppnexusImpExt.of(
AppnexusImpExtAppnexus.of(appnexusExt.getPlacementId(), makeKeywords(appnexusExt.getKeywords()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,69 @@ public void makeHttpRequestsShouldSetImpTagidAndImpBidFloorIfExtImpAppnexusHasIn
.build()));
}

@Test
public void makeHttpRequestsShouldSetReserveIfImpBidFloorIsNotSet() {
// given
final BidRequest bidRequest = givenBidRequest(
identity(),
identity(),
extImpAppnexusBuilder -> extImpAppnexusBuilder
.placementId(20)
.reserve(BigDecimal.valueOf(123)));

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

// then
assertThat(result.getValue()).hasSize(1)
.extracting(HttpRequest::getPayload)
.flatExtracting(BidRequest::getImp)
.extracting(Imp::getBidfloor)
.containsExactly(BigDecimal.valueOf(123));
}

@Test
public void makeHttpRequestsShouldSetReserveIfImpBidFloorIsZero() {
// given
final BidRequest bidRequest = givenBidRequest(
identity(),
impBuilder -> impBuilder.bidfloor(BigDecimal.ZERO),
extImpAppnexusBuilder -> extImpAppnexusBuilder
.placementId(20)
.reserve(BigDecimal.valueOf(123)));

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

// then
assertThat(result.getValue()).hasSize(1)
.extracting(HttpRequest::getPayload)
.flatExtracting(BidRequest::getImp)
.extracting(Imp::getBidfloor)
.containsExactly(BigDecimal.valueOf(123));
}

@Test
public void makeHttpRequestsShouldSetReserveIfImpBidFloorIsNegative() {
// given
final BidRequest bidRequest = givenBidRequest(
identity(),
impBuilder -> impBuilder.bidfloor(BigDecimal.ZERO.subtract(BigDecimal.ONE)),
extImpAppnexusBuilder -> extImpAppnexusBuilder
.placementId(20)
.reserve(BigDecimal.valueOf(123)));

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

// then
assertThat(result.getValue()).hasSize(1)
.extracting(HttpRequest::getPayload)
.flatExtracting(BidRequest::getImp)
.extracting(Imp::getBidfloor)
.containsExactly(BigDecimal.valueOf(123));
}

@Test
public void makeHttpRequestsShouldSetNativeIfRequestImpIsNative() {
// given
Expand Down

0 comments on commit 93209ed

Please sign in to comment.