-
Notifications
You must be signed in to change notification settings - Fork 220
Showheroes bidder #4190
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
base: master
Are you sure you want to change the base?
Showheroes bidder #4190
Conversation
public ShowheroesBidder(String endpointUrl, | ||
CurrencyConversionService currencyConversionService, | ||
PrebidVersionProvider prebidVersionProvider, | ||
JacksonMapper mapper) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please fix formatting
} | ||
|
||
private BidderError validate(BidRequest bidRequest) { | ||
// request must contain site object with page or app object with bundle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove comments here and further
} | ||
|
||
@Override | ||
public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest request) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please place the methods in the class in a calling order, according to the style guide of the repo
this.pbsVersion = prebidVersionProvider.getNameVersionRecord(); | ||
} | ||
|
||
private BidderError validate(BidRequest bidRequest) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static
return null; | ||
} | ||
|
||
private ExtRequestPrebidChannel getPrebidChannel(BidRequest bidRequest) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static
BidderDeps showheroesBidderDeps(BidderConfigurationProperties showheroesConfigurationProperties, | ||
@NotBlank @Value("${external-url}") String externalUrl, | ||
CurrencyConversionService currencyConversionService, | ||
PrebidVersionProvider prebidVersionProvider, | ||
JacksonMapper mapper) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix formatting
.banner(Banner.builder().build()) | ||
.build())) | ||
.build(), | ||
mapper.writeValueAsString( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please hide mapper.writeValueAsString
inside the givenHttpCall
assertThat(result.getValue()) | ||
.extracting(BidderBid::getType) | ||
.containsExactly(video); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please check the whole bid, not just a type, here and further
BidRequest.builder() | ||
.imp(List.of( | ||
Imp.builder().id("123").banner(Banner.builder().build()).build(), | ||
Imp.builder().id("456").video(Video.builder().build()).build())) | ||
.build(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
passing BidRequest is redundant, because it's never used by the makeBids
method, so I believe we can just remove this parameter from the givenHttpCall
aliases: | ||
showheroes-bs: ~ | ||
showheroesBs: ~ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
separate integration tests should be added for all the hard aliases to make sure the configuration is correct
@Override | ||
public Result<List<BidderBid>> makeBids(BidderCall<BidRequest> httpCall, BidRequest bidRequest) { | ||
final BidResponse bidResponse; | ||
|
||
try { | ||
bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class); | ||
} catch (DecodeException | PreBidException e) { | ||
return Result.withError(BidderError.badServerResponse(e.getMessage())); | ||
} | ||
|
||
return Result.of(extractBids(bidResponse), Collections.emptyList()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Override
public Result<List<BidderBid>> makeBids(BidderCall<BidRequest> httpCall, BidRequest bidRequest) {
try {
final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class);
return Result.withValues(extractBids(bidResponse));
} catch (DecodeException e) {
return Result.withError(BidderError.badServerResponse(e.getMessage()));
}
}
/** | ||
* Defines the contract for bidRequest.imp[i].ext.showheroes | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove the comment
|
||
@BeforeEach | ||
public void setUp() { | ||
// set always 'test_version' as Prebid version for testing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove the comment
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; | ||
import static java.util.Collections.singletonList; | ||
|
||
public class ShowheroesBSTest extends IntegrationTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you've missed one alias
assertThat(result.getValue()).hasSize(1); | ||
|
||
final BidRequest outgoingRequest = result.getValue().get(0).getPayload(); | ||
assertThat(outgoingRequest.getImp()).hasSize(2) | ||
.extracting(Imp::getId) | ||
.containsExactly("imp1", "imp2"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertThat(result.getValue()).hasSize(1)
.extracting(HttpRequest::getImpIds)
.containsOnly(Set.of("imp1", "imp2"));
@Test | ||
public void makeBidsShouldReturnVideoBidIfVideoIsPresentInImp() throws JsonProcessingException { | ||
// given | ||
final BidderCall<BidRequest> httpCall = givenHttpCall( | ||
givenBidResponse(bidBuilder -> bidBuilder.impid("123").mtype(2))); | ||
|
||
// when | ||
final Result<List<BidderBid>> result = target.makeBids(httpCall, null); | ||
|
||
// then | ||
assertThat(result.getErrors()).isEmpty(); | ||
assertThat(result.getValue()) | ||
.extracting(BidderBid::getBid, BidderBid::getType) | ||
.containsExactly(tuple(Bid.builder().impid("123").mtype(2).build(), video)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is redundant because there is no such test case as this test covers.
@Test | ||
public void makeBidsShouldReturnBannerBidIfBannerIsPresentInImp() throws JsonProcessingException { | ||
// given | ||
final BidderCall<BidRequest> httpCall = givenHttpCall( | ||
givenBidResponse(bidBuilder -> bidBuilder.impid("123").mtype(1))); | ||
|
||
// when | ||
final Result<List<BidderBid>> result = target.makeBids(httpCall, null); | ||
|
||
// then | ||
assertThat(result.getErrors()).isEmpty(); | ||
assertThat(result.getValue()) | ||
.extracting(BidderBid::getBid, BidderBid::getType) | ||
.containsExactly(tuple(Bid.builder().impid("123").mtype(1).build(), banner)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is redundant because there is no such test case as this test covers.
assertThat(result.getValue()).hasSize(1); | ||
|
||
final Map<String, String> headers = result.getValue().get(0).getHeaders().entries().stream() | ||
.collect(java.util.stream.Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); | ||
assertThat(headers).containsEntry("Content-Type", "application/json;charset=utf-8") | ||
.containsEntry("Accept", "application/json"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertThat(result.getValue()).hasSize(1).first()
.extracting(HttpRequest::getHeaders)
.satisfies(headers -> assertThat(headers.get(CONTENT_TYPE_HEADER))
.isEqualTo(APPLICATION_JSON_CONTENT_TYPE))
.satisfies(headers -> assertThat(headers.get(ACCEPT_HEADER))
.isEqualTo(APPLICATION_JSON_VALUE));
src/test/java/org/prebid/server/bidder/showheroes/ShowheroesBidderTest.java
Show resolved
Hide resolved
src/test/java/org/prebid/server/bidder/showheroes/ShowheroesBidderTest.java
Show resolved
Hide resolved
@AntoxaAntoxic I think I addressed all your comments. Thanks for your review. |
private Imp modifyImp(BidRequest bidRequest, Imp imp, ExtRequestPrebidChannel prebidChannel) { | ||
final ExtImpShowheroes extImpShowheroes = parseImpExt(imp); | ||
|
||
final Imp.ImpBuilder impBuilder = imp.toBuilder(); | ||
|
||
if (prebidChannel != null && imp.getDisplaymanager() == null) { | ||
impBuilder.displaymanager(prebidChannel.getName()); | ||
impBuilder.displaymanagerver(prebidChannel.getVersion()); | ||
} | ||
|
||
impBuilder.ext(modifyImpExt(imp, extImpShowheroes)); | ||
|
||
if (!shouldConvertFloor(imp)) { | ||
return impBuilder.build(); | ||
} | ||
|
||
return impBuilder | ||
.bidfloorcur(BID_CURRENCY) | ||
.bidfloor(resolveBidFloor(bidRequest, imp)) | ||
.build(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to suggest the following refactoring
private Imp modifyImp(BidRequest bidRequest, Imp imp, ExtRequestPrebidChannel prebidChannel) {
final ExtImpShowheroes extImpShowheroes = parseImpExt(imp); // I'd prefer to move this out of the modifyImp method
final boolean shouldSetDisplayManager = prebidChannel != null && imp.getDisplaymanager() == null;
final boolean shouldConvertFloor = shouldConvertFloor(imp);
return imp.toBuilder()
.displaymanager(shouldSetDisplayManager ? prebidChannel.getName() : imp.getDisplaymanager())
.displaymanagerver(shouldSetDisplayManager ? prebidChannel.getVersion()) : imp.getDisplaymanagerver())
.bidfloorcur(shouldConvertFloor ? BID_CURRENCY : imp.getBidfloorcur())
.bidfloor(shouldConvertFloor ? resolveBidFloor(bidRequest, imp) : imp.getbidloor())
.ext(modifyImpExt(imp, extImpShowheroes));
.build();
}
try { | ||
final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class); | ||
return Result.of(extractBids(bidResponse), Collections.emptyList()); | ||
} catch (DecodeException | PreBidException e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PreBidException is impossible here
.toList(); | ||
} | ||
|
||
private BidType getBidType(Bid bid) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static
final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest); | ||
|
||
// then | ||
assertThat(result.getErrors()).hasSize(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what kind of error is expected?
final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest); | ||
|
||
// then | ||
assertThat(result.getErrors()).hasSize(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what kind of error is expected?
tuple(Bid.builder().impid("456").mtype(2).price(BigDecimal.TEN).build(), video)); | ||
} | ||
|
||
private static BidRequest givenBidRequest(Function<Imp.ImpBuilder, Imp.ImpBuilder> impCustomizer) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method utilizes the impCustomizer
only once in the makeHttpRequestsShouldReturnErrorIfImpExtCouldNotBeParsed
. All other tests call the givenBidRequest(identity())
, so I believe we don't need the impCustomizer
parameter
final BidRequest outgoingRequest = result.getValue().get(0).getPayload(); | ||
assertThat(outgoingRequest.getImp()).hasSize(2) | ||
.extracting(Imp::getId) | ||
.containsExactly("imp1", "imp2"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the suggestion
assertThat(result.getValue()).hasSize(1)
.extracting(HttpRequest::getPayload)
.flatExtracting(BidRequest::getImp)
.extracting(Imp::getId)
.containsExactly("imp1", "imp2");
assertThat(result.getValue()) | ||
.extracting(BidderBid::getBid, BidderBid::getType) | ||
.containsExactly(tuple(Bid.builder().impid("123").mtype(99).build(), video)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^^
@Test | ||
public void makeBidsShouldReturnMultipleBids() throws JsonProcessingException { | ||
// given | ||
final BidderCall<BidRequest> httpCall = givenHttpCall( | ||
BidResponse.builder() | ||
.seatbid(singletonList(SeatBid.builder() | ||
.bid(List.of( | ||
Bid.builder().impid("123").mtype(1).price(BigDecimal.ONE).build(), | ||
Bid.builder().impid("456").mtype(2).price(BigDecimal.TEN).build())) | ||
.build())) | ||
.build()); | ||
|
||
// when | ||
final Result<List<BidderBid>> result = target.makeBids(httpCall, null); | ||
|
||
// then | ||
assertThat(result.getErrors()).isEmpty(); | ||
assertThat(result.getValue()).hasSize(2) | ||
.extracting(BidderBid::getBid, BidderBid::getType) | ||
.containsExactlyInAnyOrder( | ||
tuple(Bid.builder().impid("123").mtype(1).price(BigDecimal.ONE).build(), banner), | ||
tuple(Bid.builder().impid("456").mtype(2).price(BigDecimal.TEN).build(), video)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^^
Hi @AntoxaAntoxic and @CTMBNara , can we know the next steps to do for this bidder to be merged? Do we need a second approval? We'd like to push this forward; thanks. |
π§ Type of changes
β¨ What's the context?
Adding support for the
showheroes
bid adapter. Copy of the: prebid/prebid-server#4533Docs PR: prebid/prebid.github.io#6256
π New Bid Adapter Checklist
π§ͺ Test plan
How do you know the changes are safe to ship to production?
π Quality check