|
| 1 | +package org.prebid.server.functional.tests |
| 2 | + |
| 3 | +import org.prebid.server.functional.model.config.AccountAuctionConfig |
| 4 | +import org.prebid.server.functional.model.config.AccountConfig |
| 5 | +import org.prebid.server.functional.model.db.Account |
| 6 | +import org.prebid.server.functional.model.request.auction.BidRequest |
| 7 | +import org.prebid.server.functional.model.response.auction.BidResponse |
| 8 | +import org.prebid.server.functional.util.PBSUtils |
| 9 | + |
| 10 | +import static org.prebid.server.functional.model.AccountStatus.ACTIVE |
| 11 | +import static org.prebid.server.functional.model.request.auction.BidRounding.DOWN |
| 12 | +import static org.prebid.server.functional.model.request.auction.BidRounding.TRUE |
| 13 | +import static org.prebid.server.functional.model.request.auction.BidRounding.UNKNOWN |
| 14 | +import static org.prebid.server.functional.model.request.auction.BidRounding.UP |
| 15 | + |
| 16 | +class BidRoundingSpec extends BaseSpec { |
| 17 | + |
| 18 | + def "PBS should round bid value to the down when account bid rounding setting is #bidRoundingValue"() { |
| 19 | + given: "Default bid request" |
| 20 | + def bidRequest = BidRequest.getDefaultBidRequest().tap { |
| 21 | + enableCache() |
| 22 | + } |
| 23 | + |
| 24 | + and: "Account in the DB" |
| 25 | + def account = getAccountWithBidRounding(bidRequest.accountId, bidRoundingValue) |
| 26 | + accountDao.save(account) |
| 27 | + |
| 28 | + and: "Default bid response" |
| 29 | + def bidPrice = PBSUtils.randomFloorValue |
| 30 | + def bidResponse = BidResponse.getDefaultBidResponse(bidRequest).tap { |
| 31 | + seatbid[0].bid[0].price = bidPrice |
| 32 | + } |
| 33 | + bidder.setResponse(bidRequest.id, bidResponse) |
| 34 | + |
| 35 | + when: "PBS processes auction request" |
| 36 | + def response = defaultPbsService.sendAuctionRequest(bidRequest) |
| 37 | + |
| 38 | + then: "Targeting hb_pb should be round" |
| 39 | + def targeting = response.seatbid[0].bid[0].ext.prebid.targeting |
| 40 | + assert targeting["hb_pb"] == getRoundedTargetingValueWithDownPrecision(bidPrice) |
| 41 | + |
| 42 | + where: |
| 43 | + bidRoundingValue << [new AccountAuctionConfig(bidRounding: null), |
| 44 | + new AccountAuctionConfig(bidRounding: UNKNOWN), |
| 45 | + new AccountAuctionConfig(bidRounding: DOWN), |
| 46 | + new AccountAuctionConfig(bidRoundingSnakeCase: DOWN)] |
| 47 | + } |
| 48 | + |
| 49 | + def "PBS should round bid value to the up when account bid rounding setting is #bidRoundingValue"() { |
| 50 | + given: "Default bid request" |
| 51 | + def bidRequest = BidRequest.getDefaultBidRequest().tap { |
| 52 | + enableCache() |
| 53 | + } |
| 54 | + |
| 55 | + and: "Account in the DB" |
| 56 | + def account = getAccountWithBidRounding(bidRequest.accountId, bidRoundingValue) |
| 57 | + accountDao.save(account) |
| 58 | + |
| 59 | + and: "Default bid response" |
| 60 | + def bidPrice = PBSUtils.getRandomFloorValue() |
| 61 | + def bidResponse = BidResponse.getDefaultBidResponse(bidRequest).tap { |
| 62 | + seatbid[0].bid[0].price = bidPrice |
| 63 | + } |
| 64 | + bidder.setResponse(bidRequest.id, bidResponse) |
| 65 | + |
| 66 | + when: "PBS processes auction request" |
| 67 | + def response = defaultPbsService.sendAuctionRequest(bidRequest) |
| 68 | + |
| 69 | + then: "Targeting hb_pb should be round" |
| 70 | + def targeting = response.seatbid[0].bid[0].ext.prebid.targeting |
| 71 | + assert targeting["hb_pb"] == getRoundedTargetingValueWithUpPrecision(bidPrice) |
| 72 | + |
| 73 | + where: |
| 74 | + bidRoundingValue << [new AccountAuctionConfig(bidRounding: UP), |
| 75 | + new AccountAuctionConfig(bidRoundingSnakeCase: UP)] |
| 76 | + } |
| 77 | + |
| 78 | + def "PBS should round bid value to the up or down when account bid rounding setting is #bidRoundingValue"() { |
| 79 | + given: "Default bid request" |
| 80 | + def bidRequest = BidRequest.getDefaultBidRequest().tap { |
| 81 | + enableCache() |
| 82 | + } |
| 83 | + |
| 84 | + and: "Account in the DB" |
| 85 | + def account = getAccountWithBidRounding(bidRequest.accountId, bidRoundingValue) |
| 86 | + accountDao.save(account) |
| 87 | + |
| 88 | + and: "Default bid response" |
| 89 | + def bidPrice = PBSUtils.getRandomFloorValue() |
| 90 | + def bidResponse = BidResponse.getDefaultBidResponse(bidRequest).tap { |
| 91 | + seatbid[0].bid[0].price = bidPrice |
| 92 | + } |
| 93 | + bidder.setResponse(bidRequest.id, bidResponse) |
| 94 | + |
| 95 | + when: "PBS processes auction request" |
| 96 | + def response = defaultPbsService.sendAuctionRequest(bidRequest) |
| 97 | + |
| 98 | + then: "Targeting hb_pb should be round" |
| 99 | + def targeting = response.seatbid[0].bid[0].ext.prebid.targeting |
| 100 | + assert targeting["hb_pb"] == getRoundedTargetingValueWithHalfUpPrecision(bidPrice) |
| 101 | + |
| 102 | + where: |
| 103 | + bidRoundingValue << [new AccountAuctionConfig(bidRounding: TRUE), |
| 104 | + new AccountAuctionConfig(bidRoundingSnakeCase: TRUE)] |
| 105 | + } |
| 106 | + |
| 107 | + private static final Account getAccountWithBidRounding(String accountId, AccountAuctionConfig accountAuctionConfig) { |
| 108 | + def accountConfig = new AccountConfig(status: ACTIVE, auction: accountAuctionConfig) |
| 109 | + new Account(uuid: accountId, config: accountConfig) |
| 110 | + } |
| 111 | +} |
0 commit comments