Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BeachfrontBidder: fix beachfront bid floor #1334

Merged
merged 3 commits into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ private BeachfrontBannerRequest getBannerRequest(BidRequest bidRequest, List<Imp
final ExtImpBeachfront extImpBeachfront = parseImpExt(imp);
final String appId = getAppId(extImpBeachfront, true);

slots.add(BeachfrontSlot.of(imp.getId(), appId, checkBidFloor(extImpBeachfront.getBidfloor()),
makeBeachfrontSizes(imp.getBanner())));
slots.add(BeachfrontSlot.of(imp.getId(), appId, getBidFloor(
extImpBeachfront.getBidfloor(), imp.getBidfloor()), makeBeachfrontSizes(imp.getBanner())));
} catch (PreBidException e) {
errors.add(BidderError.badInput(e.getMessage()));
}
Expand Down Expand Up @@ -244,8 +244,20 @@ private static String getAppId(ExtImpBeachfront extImpBeachfront, boolean isBann
throw new PreBidException("unable to determine the appId(s) from the supplied extension");
}

private static BigDecimal checkBidFloor(BigDecimal bidFloor) {
return bidFloor != null && bidFloor.compareTo(MIN_BID_FLOOR) > 0 ? bidFloor : BigDecimal.ZERO;
private static BigDecimal getBidFloor(BigDecimal extImpBidfloor, BigDecimal impBidfloor) {
final BigDecimal impNonNullBidfloor = zeroIfNull(impBidfloor);
final BigDecimal extImpNonNullBidfloor = zeroIfNull(extImpBidfloor);
if (impNonNullBidfloor.compareTo(MIN_BID_FLOOR) > 0) {
return impNonNullBidfloor;
} else if (extImpNonNullBidfloor.compareTo(MIN_BID_FLOOR) > 0) {
return extImpNonNullBidfloor;
} else {
return BigDecimal.ZERO;
}
}

private static BigDecimal zeroIfNull(BigDecimal bigDecimal) {
return bigDecimal == null ? BigDecimal.ZERO : bigDecimal;
}

/**
Expand Down Expand Up @@ -370,7 +382,7 @@ private List<BeachfrontVideoRequest> getVideoRequests(BidRequest bidRequest, Lis
.banner(null)
.ext(null)
.secure(secure)
.bidfloor(checkBidFloor(extImpBeachfront.getBidfloor()));
.bidfloor(getBidFloor(extImpBeachfront.getBidfloor(), imp.getBidfloor()));

final Video video = imp.getVideo();
final Integer videoHeight = video.getH();
Expand Down
20 changes: 12 additions & 8 deletions src/main/resources/static/bidder-params/beachfront.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,30 @@
"properties": {
"video": {
"type": "string",
"title": "Video appId",
"description": "An appId string that will be applied to video requests in this imp."
},
"banner": {
"type": "string",
"title": "Banner appId",
"description": "An appId string that will be applied to banner requests in this imp."
}
}
},
"anyOf":[
{"required":["video"]},
{"required":["banner"]}
]
},
"bidfloor": {
"type": "number",
"description": "The price floor for the bid."
},
"description": "The price floor for the bid. Will override the bidfloor set for the impression." },
"videoResponseType": {
"type": "string",
"description": "By default the video response will be an AdM element containing VAST 3.0 markup including tracking, click through, and mediafile elements pointing to mp4, webm or other playable media files or Vpaid media as configured for the exchange at beachfront.io. Optionally, set this to 'nurl' to receive a URI pointing to VAST 3.0 markup which will contain a mediafile pointing to a beachfront neptune javascript video player which will load your video and take care of tracking, etc. Regardless of which format is selected, the id of the returned impression will be the provided impression id (imp[{'id'...},...] in the request) with the format appended. The impression id will be returned unchanged as 'impid'. So if you indicate 'nurl', and an impression id 'someImp', the returned impression will have an 'impid' value of 'someImp', and the 'id' value 'someImpNurlVideo'. This is to differentiate the object in the case that a request includes both video and banner elements. Setting videoResponseType to any other string will have no effect and the default format (AdM) will be returned."
}
},
"required": ["bidfloor"],
"oneOf": [{
"required": ["appId"] }, {
"required": ["appIds"]
}]
"oneOf": [
{"required": ["appId"] },
{"required": ["appIds"]}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,79 @@ public void makeHttpRequestsShouldCreateAdmRequestForEveryUnknownResponseType()
.containsExactly("adm");
}

@Test
public void makeHttpRequestsShouldReturnExpectedBidFloorFromBidRequest() {
// given
final BidRequest bidRequest = givenBidRequest(
impBuilder -> impBuilder
.video(Video.builder().w(1).h(1).build())
.bidfloor(BigDecimal.ONE)
.secure(1));

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

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

@Test
public void makeHttpRequestsShouldUseDefaultBidFloorIfNoInRequest() {
// given
final BidRequest bidRequest = givenBidRequest(
impBuilder -> impBuilder
.ext(mapper.valueToTree(ExtPrebid.of(null,
ExtImpBeachfront.of("appId",
ExtImpBeachfrontAppIds.of("videoIds", "bannerIds"),
null, "adm"))))
.video(Video.builder().w(1).h(1).build())
.secure(1));

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

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

@Test
public void makeHttpRequestsShouldUseImpBidFloor() {
// given
final BidRequest bidRequest = givenBidRequest(
impBuilder -> impBuilder
.ext(mapper.valueToTree(ExtPrebid.of(null,
ExtImpBeachfront.of("appId",
ExtImpBeachfrontAppIds.of("videoIds", "bannerIds"),
BigDecimal.TEN, "adm"))))
.video(Video.builder().w(1).h(1).build())
.bidfloor(BigDecimal.ONE)
.secure(1));

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

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

@Test
public void makeBidsShouldReturnEmptyResultWhenResponseBodyHasEmptyArray() {
// given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ public void validateShouldReturnValidationMessagesWhenBeachfrontExtNotValid() {
final Set<String> messages = bidderParamValidator.validate(BEACHFRONT, node);

// then
assertThat(messages.size()).isEqualTo(3);
assertThat(messages.size()).isEqualTo(2);
}

@Test
Expand Down