Skip to content

Commit eb5d5ca

Browse files
Fix default value of targeting.hb_pb (#4186)
1 parent 2204043 commit eb5d5ca

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

src/main/java/org/prebid/server/auction/CpmRange.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.prebid.server.auction;
22

33
import org.apache.commons.lang3.ObjectUtils;
4-
import org.apache.commons.lang3.StringUtils;
54
import org.prebid.server.proto.openrtb.ext.request.ExtGranularityRange;
65
import org.prebid.server.settings.model.Account;
76
import org.prebid.server.settings.model.AccountAuctionConfig;
@@ -19,6 +18,8 @@
1918
*/
2019
public class CpmRange {
2120

21+
public static final String DEFAULT_CPM = "0.0";
22+
2223
private static final Locale LOCALE = Locale.US;
2324
private static final int DEFAULT_PRECISION = 2;
2425

@@ -30,7 +31,7 @@ private CpmRange() {
3031
*/
3132
public static String fromCpm(BigDecimal cpm, PriceGranularity priceGranularity, Account account) {
3233
final BigDecimal value = fromCpmAsNumber(cpm, priceGranularity, account);
33-
return value != null ? format(value, priceGranularity.getPrecision()) : StringUtils.EMPTY;
34+
return value != null ? format(value, priceGranularity.getPrecision()) : DEFAULT_CPM;
3435
}
3536

3637
/**

src/main/java/org/prebid/server/auction/TargetingKeywordsCreator.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ public class TargetingKeywordsCreator {
7878
*/
7979
private static final String FORMAT_KEY = "_format";
8080

81-
private static final String DEFAULT_CPM = "0.0";
82-
8381
private final PriceGranularity priceGranularity;
8482
private final boolean includeWinners;
8583
private final boolean includeBidderKeys;
@@ -206,7 +204,7 @@ private Map<String, String> makeFor(String bidder,
206204

207205
final String roundedCpm = isPriceGranularityValid()
208206
? CpmRange.fromCpm(price, priceGranularity, account)
209-
: DEFAULT_CPM;
207+
: CpmRange.DEFAULT_CPM;
210208

211209
keywordMap.put(this.keyPrefix + PB_KEY, roundedCpm);
212210

src/test/groovy/org/prebid/server/functional/tests/TargetingSpec.groovy

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class TargetingSpec extends BaseSpec {
6262
private static final String HB_ENV_AMP = "amp"
6363
private static final Integer MAIN_RANK = 1
6464
private static final Integer SUBORDINATE_RANK = 2
65+
private static final String EMPTY_CPM = "0.0"
6566
private static final Integer DEFAULT_TRUNCATE_CHARS = 20
6667
private static final Integer EXTENDED_TRUNCATE_CHARS = PbsConfig.targetingConfig.get('settings.targeting.truncate-attr-chars').toInteger()
6768
private static final Map<String, String> EMPTY_TARGETING_CONFIG = ['settings.targeting.truncate-attr-chars': null] as Map
@@ -564,6 +565,30 @@ class TargetingSpec extends BaseSpec {
564565
assert targetingKeyMap["hb_pb"] == String.format("%,.2f", max.setScale(precision, RoundingMode.DOWN))
565566
}
566567

568+
def "PBS auction shouldn't delete bid and update targeting if price equal zero and dealId present"() {
569+
given: "Default bid request with stored response"
570+
def bidRequest = BidRequest.defaultBidRequest.tap {
571+
ext.prebid.targeting = Targeting.createWithAllValuesSetTo(true)
572+
}
573+
574+
and: "Bid response with zero price"
575+
def bidResponse = BidResponse.getDefaultBidResponse(bidRequest).tap {
576+
seatbid[0].bid[0].price = 0
577+
seatbid[0].bid[0].dealid = PBSUtils.randomString
578+
}
579+
580+
and: "Set bidder response"
581+
bidder.setResponse(bidRequest.id, bidResponse)
582+
583+
when: "PBS processes auction request"
584+
def response = defaultPbsService.sendAuctionRequest(bidRequest)
585+
586+
then: "Response should contain proper targeting hb_pb"
587+
def targetingKeyMap = response.seatbid?.first()?.bid?.first()?.ext?.prebid?.targeting
588+
assert targetingKeyMap["hb_pb"] == EMPTY_CPM
589+
assert targetingKeyMap["hb_pb_generic"] == EMPTY_CPM
590+
}
591+
567592
def "PBS auction should use default targeting prefix when ext.prebid.targeting.prefix is biggest that twenty"() {
568593
given: "Bid request with long targeting prefix"
569594
def prefix = PBSUtils.getRandomString(30)

src/test/java/org/prebid/server/auction/CpmRangeTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@
2121

2222
public class CpmRangeTest {
2323

24+
@Test
25+
public void fromCpmShouldReturnZeroValueIfPriceDoesNotFitToRange() {
26+
// given
27+
final PriceGranularity priceGranularity = createFromExtPriceGranularity(
28+
ExtPriceGranularity.of(null, singletonList(ExtGranularityRange.of(BigDecimal.valueOf(3),
29+
BigDecimal.valueOf(0.01)))));
30+
31+
// when
32+
final String result = CpmRange.fromCpm(BigDecimal.valueOf(-2.0), priceGranularity, givenAccount());
33+
34+
// then
35+
assertThat(result).isEqualTo("0.0");
36+
}
37+
2438
@Test
2539
public void fromCpmShouldReturnMaxRangeIfCpmExceedsIt() {
2640
assertThat(CpmRange.fromCpm(BigDecimal.valueOf(21), createFromString("auto"), givenAccount()))

0 commit comments

Comments
 (0)