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

Tests: Rework of calculation custom price granularity #2842

Merged
merged 6 commits into from
Dec 20, 2023
Merged
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 @@ -20,8 +20,9 @@ import org.prebid.server.functional.model.response.auction.BidResponse
import org.prebid.server.functional.service.PrebidServerService
import org.prebid.server.functional.util.PBSUtils

import java.nio.charset.StandardCharsets
import java.math.RoundingMode

import java.nio.charset.StandardCharsets
import static org.prebid.server.functional.model.bidder.BidderName.GENERIC
import static org.prebid.server.functional.testcontainers.Dependencies.getNetworkServiceContainer

Expand Down Expand Up @@ -441,19 +442,20 @@ class TargetingSpec extends BaseSpec {
assert response.targeting.isEmpty()
}

def "PBS amp should make right calculation for hb_pb targeting"() {
def "PBS amp should use ranges.max value for hb_pb targeting when bid.price is greater than ranges.max"() {
given: "Default amp request"
def ampRequest = AmpRequest.defaultAmpRequest

and: "Default bid request with targeting and stored bid response"
def storedBidResponseId = PBSUtils.randomString
def max = PBSUtils.randomDecimal
def precision = 2
def ampStoredRequest = BidRequest.defaultBidRequest.tap {
imp[0].ext.prebid.storedBidResponse = [new StoredBidResponse(id: storedBidResponseId, bidder: GENERIC)]
ext.prebid.targeting = Targeting.createWithAllValuesSetTo(true).tap {
priceGranularity = new PriceGranularity().tap {
precision = 2
ranges = [new Range(max: 1.50,increment: 1.0),
new Range(max: 2.50,increment: 1.2)]}
it.precision = precision
ranges = [new Range(max: max, increment: PBSUtils.randomDecimal)]}
osulzhenko marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand All @@ -463,7 +465,7 @@ class TargetingSpec extends BaseSpec {

and: "Create and save stored response into DB"
def storedBidResponse = BidResponse.getDefaultBidResponse(ampStoredRequest).tap {
seatbid[0].bid[0].price = BigDecimal.valueOf(2)
seatbid[0].bid[0].price = max.plus(1)
}
def storedResponse = new StoredResponse(responseId: storedBidResponseId, storedBidResponse: storedBidResponse)
storedResponseDao.save(storedResponse)
Expand All @@ -476,26 +478,27 @@ class TargetingSpec extends BaseSpec {
def response = defaultPbsService.sendAmpRequest(ampRequest)

then: "Response should contain targeting hb_pb"
assert response.targeting["hb_pb"] == getRoundedTargetingValueWithDefaultPrecision(1.50)
assert response.targeting["hb_pb"] == String.format("%,.2f", max.setScale(precision, RoundingMode.DOWN))
}

def "PBS auction should make right calculation for hb_pb targeting"() {
def "PBS auction should use ranges.max value for hb_pb targeting when bid.price is greater that ranges.max"() {
given: "Default bid request"
def storedBidResponseId = PBSUtils.randomString
def max = PBSUtils.randomDecimal
def precision = 2
def bidRequest = BidRequest.defaultBidRequest.tap {
imp[0].ext.prebid.storedBidResponse = [new StoredBidResponse(id: storedBidResponseId, bidder: GENERIC)]
ext.prebid.targeting = Targeting.createWithAllValuesSetTo(true).tap {
priceGranularity = new PriceGranularity().tap {
precision = 2
ranges = [new Range(max: 1.50, increment: 1.0),
new Range(max: 2.50, increment: 1.2)]
it.precision = precision
it.ranges = [new Range(max: max, increment: PBSUtils.randomDecimal)]
}
}
}

and: "Create and save stored response into DB"
def storedBidResponse = BidResponse.getDefaultBidResponse(bidRequest).tap {
seatbid[0].bid[0].price = BigDecimal.valueOf(2)
seatbid[0].bid[0].price = max.plus(1)
}
def storedResponse = new StoredResponse(responseId: storedBidResponseId, storedBidResponse: storedBidResponse)
storedResponseDao.save(storedResponse)
Expand All @@ -505,7 +508,7 @@ class TargetingSpec extends BaseSpec {

then: "Response should contain targeting hb_pb"
def targetingKeyMap = response.seatbid?.first()?.bid?.first()?.ext?.prebid?.targeting
assert targetingKeyMap["hb_pb"] == getRoundedTargetingValueWithDefaultPrecision(1.50)
assert targetingKeyMap["hb_pb"] == String.format("%,.2f", max.setScale(precision, RoundingMode.DOWN))
}

def "PBS auction should use default targeting prefix when ext.prebid.targeting.prefix is biggest that twenty"() {
Expand Down
Loading