Skip to content
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
13 changes: 12 additions & 1 deletion src/main/java/org/prebid/server/bidder/nativo/NativoBidder.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.prebid.server.proto.openrtb.ext.request.ExtRequestPrebid;
import org.prebid.server.proto.openrtb.ext.request.ExtRequestPrebidSdk;
import org.prebid.server.proto.openrtb.ext.request.ExtRequestPrebidSdkRenderer;
import org.prebid.server.proto.openrtb.ext.response.BidType;
import org.prebid.server.proto.openrtb.ext.response.ExtBidPrebid;
import org.prebid.server.proto.openrtb.ext.response.ExtBidPrebidMeta;
import org.prebid.server.util.BidderUtil;
Expand Down Expand Up @@ -88,10 +89,20 @@ private List<BidderBid> bidsFromResponse(BidRequest bidRequest, BidResponse bidR
.flatMap(Collection::stream)
.filter(Objects::nonNull)
.map(bid -> updateBid(bid, rendererVersion, errors))
.map(bid -> BidderBid.of(bid, BidderUtil.getBidType(bid, impMap), bidResponse.getCur()))
.map(bid -> BidderBid.of(bid, getBidType(bid, impMap), bidResponse.getCur()))
.toList();
}

private static BidType getBidType(Bid bid, Map<String, Imp> impMap) {
return switch (bid.getMtype()) {
case 1 -> BidType.banner;
case 2 -> BidType.video;
case 3 -> BidType.audio;
case 4 -> BidType.xNative;
case null, default -> BidderUtil.getBidType(bid, impMap);
};
}

private String getNativoRendererVersion(BidRequest bidRequest) {
return Optional.ofNullable(bidRequest.getExt())
.map(ExtRequest::getPrebid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,83 @@ public void makeBidsShouldReturnErrorAndOriginalBidWhenBidExtCannotBeParsed()
assertThat(result.getValue().getFirst().getBid().getExt()).isEqualTo(invalidExt);
}

@Test
public void makeBidsShouldReturnNativeBidWhenMtypeIsNative() throws JsonProcessingException {
// given
final BidRequest bidRequest = givenBidRequest(imp -> imp.id("imp1"));
final Bid bid = givenBid("bid1", "imp1", 4);
final BidderCall<BidRequest> httpCall = givenHttpCall(bidRequest, givenBidResponse(singletonList(bid)));

// when
final Result<List<BidderBid>> result = target.makeBids(httpCall, bidRequest);

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue()).containsExactly(BidderBid.of(bid, BidType.xNative, "USD"));
}
Comment thread
CTMBNara marked this conversation as resolved.
Resolved

@Test
public void makeBidsShouldReturnBannerBidWhenMtypeIsBanner() throws JsonProcessingException {
// given
final BidRequest bidRequest = givenBidRequest(imp -> imp.id("imp1"));
final Bid bid = givenBid("bid1", "imp1", 1);
final BidderCall<BidRequest> httpCall = givenHttpCall(bidRequest, givenBidResponse(singletonList(bid)));

// when
final Result<List<BidderBid>> result = target.makeBids(httpCall, bidRequest);

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue()).containsExactly(BidderBid.of(bid, BidType.banner, "USD"));
}
Comment thread
CTMBNara marked this conversation as resolved.
Resolved

@Test
public void makeBidsShouldReturnVideoBidWhenMtypeIsVideo() throws JsonProcessingException {
// given
final BidRequest bidRequest = givenBidRequest(imp -> imp.id("imp1"));
final Bid bid = givenBid("bid1", "imp1", 2);
final BidderCall<BidRequest> httpCall = givenHttpCall(bidRequest, givenBidResponse(singletonList(bid)));

// when
final Result<List<BidderBid>> result = target.makeBids(httpCall, bidRequest);

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue()).containsExactly(BidderBid.of(bid, BidType.video, "USD"));
}
Comment thread
CTMBNara marked this conversation as resolved.
Resolved

@Test
public void makeBidsShouldReturnAudioBidWhenMtypeIsAudio() throws JsonProcessingException {
// given
final BidRequest bidRequest = givenBidRequest(imp -> imp.id("imp1"));
final Bid bid = givenBid("bid1", "imp1", 3);
final BidderCall<BidRequest> httpCall = givenHttpCall(bidRequest, givenBidResponse(singletonList(bid)));

// when
final Result<List<BidderBid>> result = target.makeBids(httpCall, bidRequest);

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue()).containsExactly(BidderBid.of(bid, BidType.audio, "USD"));
}
Comment thread
CTMBNara marked this conversation as resolved.
Resolved

@Test
public void makeBidsShouldReturnBidTypeFromImpWhenMtypeIsUnrecognized() throws JsonProcessingException {
// given
final BidRequest bidRequest = givenBidRequest(imp -> imp.id("imp1")
.banner(Banner.builder().build())
.xNative(Native.builder().build()));
final Bid bid = givenBid("bid1", "imp1", 7);
final BidderCall<BidRequest> httpCall = givenHttpCall(bidRequest, givenBidResponse(singletonList(bid)));

// when
final Result<List<BidderBid>> result = target.makeBids(httpCall, bidRequest);

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue()).containsExactly(BidderBid.of(bid, BidType.banner, "USD"));
}

private static BidRequest givenBidRequest(UnaryOperator<Imp.ImpBuilder> impCustomizer) {
return BidRequest.builder()
.imp(singletonList(impCustomizer.apply(Imp.builder().id("imp1")).build()))
Expand All @@ -282,11 +359,16 @@ private static BidRequest givenBidRequestWithRenderer(UnaryOperator<Imp.ImpBuild
}

private static Bid givenBid(String id, String impId) {
return givenBid(id, impId, null);
}

private static Bid givenBid(String id, String impId, Integer mtype) {
return Bid.builder()
.id(id)
.impid(impId)
.price(BigDecimal.valueOf(1.5))
.adm("adm001")
.mtype(mtype)
.build();
}

Expand Down
Loading