From f795baabd90e16d9367e24251b4d15ea48a8a6d1 Mon Sep 17 00:00:00 2001 From: antonbabak Date: Tue, 24 Sep 2024 09:34:41 +0200 Subject: [PATCH 1/6] Update Currency Warning --- src/main/java/org/prebid/server/auction/ExchangeService.java | 5 +++-- .../java/org/prebid/server/auction/ExchangeServiceTest.java | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/prebid/server/auction/ExchangeService.java b/src/main/java/org/prebid/server/auction/ExchangeService.java index 2dbf1a6528f..e495eb1e696 100644 --- a/src/main/java/org/prebid/server/auction/ExchangeService.java +++ b/src/main/java/org/prebid/server/auction/ExchangeService.java @@ -1388,8 +1388,9 @@ private AuctionParticipation validBidderResponse(AuctionParticipation auctionPar final List 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()))); + errors.add(BidderError.badInput( + "a single currency (%s) has been chosen for the request. ".formatted(requestCurrencies.getFirst()) + + "ORTB 2.6 requires that all responses are in the same currency.")); } final List bids = seatBid.getBids(); diff --git a/src/test/java/org/prebid/server/auction/ExchangeServiceTest.java b/src/test/java/org/prebid/server/auction/ExchangeServiceTest.java index 0c7710dbc74..1a4e8b1a393 100644 --- a/src/test/java/org/prebid/server/auction/ExchangeServiceTest.java +++ b/src/test/java/org/prebid/server/auction/ExchangeServiceTest.java @@ -3338,8 +3338,9 @@ public void shouldUpdateBidPriceWithCurrencyConversionAndAddErrorAboutMultipleCu contextArgumentCaptor.getValue().getAuctionParticipations(); assertThat(auctionParticipations).hasSize(1); - final BidderError expectedError = BidderError.badInput("Cur parameter contains more than one currency." - + " CUR1 will be used"); + final BidderError expectedError = BidderError.badInput( + "a single currency (CUR1) has been chosen for the request. " + + "ORTB 2.6 requires that all responses are in the same currency."); final BidderSeatBid firstSeatBid = auctionParticipations.getFirst().getBidderResponse().getSeatBid(); assertThat(firstSeatBid.getBids()) .extracting(BidderBid::getBid) From 64ea9cdcca0eed8a747e3fc357c7d02b70daa15b Mon Sep 17 00:00:00 2001 From: antonbabak Date: Tue, 24 Sep 2024 16:44:26 +0200 Subject: [PATCH 2/6] Change Error to Warning --- .../java/org/prebid/server/auction/ExchangeService.java | 6 ++---- .../org/prebid/server/auction/ExchangeServiceTest.java | 9 +++++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/prebid/server/auction/ExchangeService.java b/src/main/java/org/prebid/server/auction/ExchangeService.java index e495eb1e696..fc5d21be811 100644 --- a/src/main/java/org/prebid/server/auction/ExchangeService.java +++ b/src/main/java/org/prebid/server/auction/ExchangeService.java @@ -1388,7 +1388,7 @@ private AuctionParticipation validBidderResponse(AuctionParticipation auctionPar final List requestCurrencies = bidRequest.getCur(); if (requestCurrencies.size() > 1) { - errors.add(BidderError.badInput( + warnings.add(BidderError.badInput( "a single currency (%s) has been chosen for the request. ".formatted(requestCurrencies.getFirst()) + "ORTB 2.6 requires that all responses are in the same currency.")); } @@ -1412,9 +1412,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) diff --git a/src/test/java/org/prebid/server/auction/ExchangeServiceTest.java b/src/test/java/org/prebid/server/auction/ExchangeServiceTest.java index 1a4e8b1a393..b3dade5c95b 100644 --- a/src/test/java/org/prebid/server/auction/ExchangeServiceTest.java +++ b/src/test/java/org/prebid/server/auction/ExchangeServiceTest.java @@ -3338,15 +3338,16 @@ public void shouldUpdateBidPriceWithCurrencyConversionAndAddErrorAboutMultipleCu contextArgumentCaptor.getValue().getAuctionParticipations(); assertThat(auctionParticipations).hasSize(1); - final BidderError expectedError = BidderError.badInput( - "a single currency (CUR1) has been chosen for the request. " - + "ORTB 2.6 requires that all responses are in the same currency."); final BidderSeatBid firstSeatBid = auctionParticipations.getFirst().getBidderResponse().getSeatBid(); assertThat(firstSeatBid.getBids()) .extracting(BidderBid::getBid) .flatExtracting(Bid::getPrice) .containsOnly(updatedPrice); - assertThat(firstSeatBid.getErrors()).containsOnly(expectedError); + + final BidderError expectedError = 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(expectedError); } @Test From cf067966b8fa043c1d27ea03278035fecb29909e Mon Sep 17 00:00:00 2001 From: Markiyan Mykush <95693607+marki1an@users.noreply.github.com> Date: Mon, 30 Sep 2024 11:25:10 +0300 Subject: [PATCH 3/6] Test: Currency `warning` (#3463) --- .../functional/tests/CurrencySpec.groovy | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/test/groovy/org/prebid/server/functional/tests/CurrencySpec.groovy b/src/test/groovy/org/prebid/server/functional/tests/CurrencySpec.groovy index 568f202be55..df5bba70028 100644 --- a/src/test/groovy/org/prebid/server/functional/tests/CurrencySpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/tests/CurrencySpec.groovy @@ -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 { @@ -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 getExternalCurrencyConverterConfig() { ["auction.ad-server-currency" : DEFAULT_CURRENCY as String, "currency-converter.external-rates.enabled" : "true", From 344e47080dfffee76da8b3bd29f600d3bf157b2b Mon Sep 17 00:00:00 2001 From: antonbabak Date: Mon, 30 Sep 2024 10:50:56 +0200 Subject: [PATCH 4/6] Resolve Conflicts --- .../java/org/prebid/server/auction/BidsAdjuster.java | 9 ++++----- .../java/org/prebid/server/auction/BidsAdjusterTest.java | 8 +++++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/prebid/server/auction/BidsAdjuster.java b/src/main/java/org/prebid/server/auction/BidsAdjuster.java index ec6b1c9d2f3..7aca904eb61 100644 --- a/src/main/java/org/prebid/server/auction/BidsAdjuster.java +++ b/src/main/java/org/prebid/server/auction/BidsAdjuster.java @@ -95,8 +95,9 @@ private AuctionParticipation validBidderResponse(AuctionParticipation auctionPar final List 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 (%s) has been chosen for the request. ".formatted(requestCurrencies.getFirst()) + + "ORTB 2.6 requires that all responses are in the same currency.")); } final List bids = seatBid.getBids(); @@ -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) diff --git a/src/test/java/org/prebid/server/auction/BidsAdjusterTest.java b/src/test/java/org/prebid/server/auction/BidsAdjusterTest.java index 2691b629544..26ade6de99e 100644 --- a/src/test/java/org/prebid/server/auction/BidsAdjusterTest.java +++ b/src/test/java/org/prebid/server/auction/BidsAdjusterTest.java @@ -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 expectedError = 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(expectedError); } @Test From 4e460093f48cc2f74345bcb137da41958d4e1e54 Mon Sep 17 00:00:00 2001 From: antonbabak Date: Mon, 30 Sep 2024 11:07:27 +0200 Subject: [PATCH 5/6] Fix comments --- .../java/org/prebid/server/auction/BidsAdjusterTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/prebid/server/auction/BidsAdjusterTest.java b/src/test/java/org/prebid/server/auction/BidsAdjusterTest.java index 26ade6de99e..8b7dd0589b0 100644 --- a/src/test/java/org/prebid/server/auction/BidsAdjusterTest.java +++ b/src/test/java/org/prebid/server/auction/BidsAdjusterTest.java @@ -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( @@ -369,10 +369,10 @@ public void shouldUpdateBidPriceWithCurrencyConversionAndAddErrorAboutMultipleCu .flatExtracting(Bid::getPrice) .containsOnly(updatedPrice); - final BidderError expectedError = BidderError.badInput( + 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(expectedError); + assertThat(firstSeatBid.getWarnings()).containsOnly(expectedWarning); } @Test From b4469ba12b17fa9d0b277e24d0314b916806241d Mon Sep 17 00:00:00 2001 From: antonbabak Date: Mon, 30 Sep 2024 12:41:45 +0200 Subject: [PATCH 6/6] Fix comments --- src/main/java/org/prebid/server/auction/BidsAdjuster.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/prebid/server/auction/BidsAdjuster.java b/src/main/java/org/prebid/server/auction/BidsAdjuster.java index 7aca904eb61..8134662fcd9 100644 --- a/src/main/java/org/prebid/server/auction/BidsAdjuster.java +++ b/src/main/java/org/prebid/server/auction/BidsAdjuster.java @@ -96,7 +96,7 @@ private AuctionParticipation validBidderResponse(AuctionParticipation auctionPar final List requestCurrencies = bidRequest.getCur(); if (requestCurrencies.size() > 1) { warnings.add(BidderError.badInput( - "a single currency (%s) has been chosen for the request. ".formatted(requestCurrencies.getFirst()) + "a single currency (" + requestCurrencies.getFirst() + ") has been chosen for the request. " + "ORTB 2.6 requires that all responses are in the same currency.")); }