Skip to content

Commit

Permalink
resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
przemkaczmarek committed Jun 3, 2024
1 parent 9b8a705 commit 683b1dd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 28 deletions.
13 changes: 2 additions & 11 deletions src/main/java/org/prebid/server/bidder/loyal/LoyalBidder.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,8 @@ public Result<List<HttpRequest<BidRequest>>> makeHttpRequests(BidRequest request
for (Imp imp : request.getImp()) {
try {
final ExtImpLoyal extImpLoyal = parseExtImp(imp);
if (isValidImp(extImpLoyal)) {
final Imp modifiedImp = modifyImp(imp, extImpLoyal);
httpRequests.add(makeHttpRequest(request, modifiedImp));
} else {
errors.add(BidderError.badInput("Invalid imp: " + imp.getId()));
}
final Imp modifiedImp = modifyImp(imp, extImpLoyal);
httpRequests.add(makeHttpRequest(request, modifiedImp));
} catch (PreBidException e) {
errors.add(BidderError.badInput(e.getMessage()));
}
Expand All @@ -85,11 +81,6 @@ private ExtImpLoyal parseExtImp(Imp imp) {
}
}

private boolean isValidImp(ExtImpLoyal extImpLoyal) {
return StringUtils.isNotEmpty(extImpLoyal.getPlacementId())
|| StringUtils.isNotEmpty(extImpLoyal.getEndpointId());
}

private Imp modifyImp(Imp imp, ExtImpLoyal extImpLoyal) {
final LoyalImpExt impExtLoyalWithType = resolveImpExt(extImpLoyal);
final ObjectNode modifiedImpExtBidder = mapper.mapper().createObjectNode();
Expand Down
27 changes: 10 additions & 17 deletions src/test/java/org/prebid/server/bidder/loyal/LoyalBidderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ public void creationShouldFailOnInvalidEndpointUrl() {
public void makeHttpRequestsShouldMakeOneRequestPerImp() {
// given
final BidRequest bidRequest = BidRequest.builder()
.imp(asList(givenImp(UnaryOperator.identity()), givenImp2(UnaryOperator.identity())))
.imp(asList(
givenImp(UnaryOperator.identity()),
givenImp(imp -> imp.id("321").ext(mapper.valueToTree(ExtPrebid
.of(null, ExtImpLoyal.of("placementId2", "endpointId2")))))))
.build();

//when
Expand Down Expand Up @@ -83,7 +86,6 @@ public void shouldMakeOneRequestWhenOneImpIsValidAndAnotherIsNot() {
final Result<List<HttpRequest<BidRequest>>> result = target.makeHttpRequests(bidRequest);

//then
assertThat(result.getErrors().get(0).getMessage()).isEqualTo("Invalid imp: invalidImp");
assertThat(result.getValue()).hasSize(1)
.extracting(HttpRequest::getPayload)
.flatExtracting(BidRequest::getImp)
Expand Down Expand Up @@ -249,7 +251,7 @@ public void makeBidsShouldReturnBannerBid() throws JsonProcessingException {
final ObjectNode bidExt = mapper.createObjectNode()
.putPOJO("prebid", ExtBidPrebid.builder().type(banner).build());
final BidderCall<BidRequest> httpCall = givenHttpCall(
givenBidResponse(bidBuilder -> bidBuilder.ext(bidExt).impid("123")));
givenBidResponse(bidBuilder -> bidBuilder.ext(bidExt).impid("123")));

// when
final Result<List<BidderBid>> result = target.makeBids(httpCall, null);
Expand All @@ -267,7 +269,7 @@ public void makeBidsShouldReturnVideoBid() throws JsonProcessingException {
final ObjectNode bidExt = mapper.createObjectNode()
.putPOJO("prebid", ExtBidPrebid.builder().type(video).build());
final BidderCall<BidRequest> httpCall = givenHttpCall(
givenBidResponse(bidBuilder -> bidBuilder.ext(bidExt).impid("123")));
givenBidResponse(bidBuilder -> bidBuilder.ext(bidExt).impid("123")));

// when
final Result<List<BidderBid>> result = target.makeBids(httpCall, null);
Expand All @@ -285,7 +287,7 @@ public void makeBidsShouldReturnNativeBid() throws JsonProcessingException {
final ObjectNode bidExt = mapper.createObjectNode()
.putPOJO("prebid", ExtBidPrebid.builder().type(xNative).build());
final BidderCall<BidRequest> httpCall = givenHttpCall(
givenBidResponse(bidBuilder -> bidBuilder.ext(bidExt).impid("123")));
givenBidResponse(bidBuilder -> bidBuilder.ext(bidExt).impid("123")));

// when
final Result<List<BidderBid>> result = target.makeBids(httpCall, null);
Expand All @@ -303,7 +305,7 @@ public void makeBidsShouldReturnErrorForWrongType() throws JsonProcessingExcepti
final ObjectNode bidExt = mapper.createObjectNode()
.set("prebid", mapper.createArrayNode());
final BidderCall<BidRequest> httpCall = givenHttpCall(
givenBidResponse(bidBuilder -> bidBuilder.ext(bidExt).id("123")));
givenBidResponse(bidBuilder -> bidBuilder.ext(bidExt).id("123")));

// when
final Result<List<BidderBid>> result = target.makeBids(httpCall, null);
Expand All @@ -321,7 +323,7 @@ public void makeBidsShouldReturnErrorForAudioType() throws JsonProcessingExcepti
final ObjectNode bidExt = mapper.createObjectNode()
.putPOJO("prebid", ExtBidPrebid.builder().type(audio).build());
final BidderCall<BidRequest> httpCall = givenHttpCall(
givenBidResponse(bidBuilder -> bidBuilder.ext(bidExt).id("123")));
givenBidResponse(bidBuilder -> bidBuilder.ext(bidExt).id("123")));

// when
final Result<List<BidderBid>> result = target.makeBids(httpCall, null);
Expand Down Expand Up @@ -354,19 +356,10 @@ private static Imp givenImp(UnaryOperator<Imp.ImpBuilder> impCustomizer) {
.build();
}

private static Imp givenImp2(UnaryOperator<Imp.ImpBuilder> impCustomizer) {
return impCustomizer.apply(Imp.builder()
.id("321")
.ext(mapper.valueToTree(ExtPrebid.of(null,
ExtImpLoyal.of("placementId", "endpointId")))))
.build();
}

private static Imp givenBadImp(UnaryOperator<Imp.ImpBuilder> impCustomizer) {
return impCustomizer.apply(Imp.builder()
.id("invalidImp")
.ext(mapper.valueToTree(ExtPrebid.of(null,
ExtImpLoyal.of(null, null)))))
.ext(mapper.createObjectNode().set("bidder", mapper.createArrayNode())))
.build();
}

Expand Down

0 comments on commit 683b1dd

Please sign in to comment.