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

Update Currency Warning #3459

Merged
merged 7 commits into from
Sep 30, 2024
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
9 changes: 4 additions & 5 deletions src/main/java/org/prebid/server/auction/BidsAdjuster.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ private AuctionParticipation validBidderResponse(AuctionParticipation auctionPar

final List<String> requestCurrencies = bidRequest.getCur();
if (requestCurrencies.size() > 1) {
errors.add(BidderError.badInput("Cur parameter contains more than one currency. %s will be used"
.formatted(requestCurrencies.getFirst())));
warnings.add(BidderError.badInput(
"a single currency (" + requestCurrencies.getFirst() + ") has been chosen for the request. "
+ "ORTB 2.6 requires that all responses are in the same currency."));
}

final List<BidderBid> bids = seatBid.getBids();
Expand All @@ -118,9 +119,7 @@ private AuctionParticipation validBidderResponse(AuctionParticipation auctionPar
}
}

final BidderResponse resultBidderResponse = errors.size() == seatBid.getErrors().size()
? bidderResponse
: bidderResponse.with(
final BidderResponse resultBidderResponse = bidderResponse.with(
seatBid.toBuilder()
.bids(validBids)
.errors(errors)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import static org.prebid.server.functional.model.Currency.CHF
import static org.prebid.server.functional.model.Currency.EUR
import static org.prebid.server.functional.model.Currency.JPY
import static org.prebid.server.functional.model.Currency.USD
import static org.prebid.server.functional.model.response.auction.ErrorType.GENERIC
import static org.prebid.server.functional.testcontainers.Dependencies.networkServiceContainer

class CurrencySpec extends BaseSpec {
Expand Down Expand Up @@ -146,6 +147,49 @@ class CurrencySpec extends BaseSpec {
CHF || EUR
}

def "PBS should emit warning when request contain more that one currency"() {
given: "Default BidRequest with currencies"
def currencies = [EUR, USD]
def bidRequest = BidRequest.defaultBidRequest.tap {
cur = currencies
}

when: "PBS processes auction request"
def bidResponse = pbsService.sendAuctionRequest(bidRequest)

then: "Bid response should contain first requested currency"
assert bidResponse.cur == currencies[0]

and: "Bidder request should contain requested currencies"
def bidderRequest = bidder.getBidderRequest(bidRequest.id)
assert bidderRequest.cur == currencies

and: "Bid response should contain warnings"
assert bidResponse.ext.warnings[GENERIC]?.message == ["a single currency (${currencies[0]}) has been chosen for the request. " +
"ORTB 2.6 requires that all responses are in the same currency." as String]
}

def "PBS shouldn't emit warning when request contain one currency"() {
given: "Default BidRequest with currency"
def currency = [USD]
def bidRequest = BidRequest.defaultBidRequest.tap {
cur = currency
}

when: "PBS processes auction request"
def bidResponse = pbsService.sendAuctionRequest(bidRequest)

then: "Bid response should contain first requested currency"
assert bidResponse.cur == currency[0]

and: "Bidder request should contain requested currency"
def bidderRequest = bidder.getBidderRequest(bidRequest.id)
assert bidderRequest.cur == currency

and: "Bid response shouldn't contain warnings"
assert !bidResponse.ext.warnings
}

private static Map<String, String> getExternalCurrencyConverterConfig() {
["auction.ad-server-currency" : DEFAULT_CURRENCY as String,
"currency-converter.external-rates.enabled" : "true",
Expand Down
10 changes: 6 additions & 4 deletions src/test/java/org/prebid/server/auction/BidsAdjusterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public void shouldRespondWithOneBidAndErrorWhenBidResponseContainsOneUnsupported
}

@Test
public void shouldUpdateBidPriceWithCurrencyConversionAndAddErrorAboutMultipleCurrency() {
public void shouldUpdateBidPriceWithCurrencyConversionAndAddWarningAboutMultipleCurrency() {
// given
final BigDecimal bidderPrice = BigDecimal.valueOf(2.0);
final BidderResponse bidderResponse = BidderResponse.of(
Expand Down Expand Up @@ -363,14 +363,16 @@ public void shouldUpdateBidPriceWithCurrencyConversionAndAddErrorAboutMultipleCu

assertThat(result).hasSize(1);

final BidderError expectedError = BidderError.badInput("Cur parameter contains more than one currency."
+ " CUR1 will be used");
final BidderSeatBid firstSeatBid = result.getFirst().getBidderResponse().getSeatBid();
assertThat(firstSeatBid.getBids())
.extracting(BidderBid::getBid)
.flatExtracting(Bid::getPrice)
.containsOnly(updatedPrice);
assertThat(firstSeatBid.getErrors()).containsOnly(expectedError);

final BidderError expectedWarning = BidderError.badInput(
"a single currency (CUR1) has been chosen for the request. "
+ "ORTB 2.6 requires that all responses are in the same currency.");
assertThat(firstSeatBid.getWarnings()).containsOnly(expectedWarning);
}

@Test
Expand Down
Loading