Skip to content

Commit

Permalink
fix review10: fix test device w/o user agent
Browse files Browse the repository at this point in the history
  • Loading branch information
EvgeniiMunin committed Oct 16, 2024
1 parent 8ca1d7b commit d9ec9f1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public static Device givenDevice(UnaryOperator<Device.DeviceBuilder> deviceCusto
return deviceCustomizer.apply(Device.builder().ua(userAgent).ip("151.101.194.216")).build();
}

public static Device givenDeviceWithoutUserAgent(UnaryOperator<Device.DeviceBuilder> deviceCustomizer) {
return deviceCustomizer.apply(Device.builder().ip("151.101.194.216")).build();
}

public static Banner givenBanner() {
final Format format = Format.builder()
.w(320)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import static org.prebid.server.hooks.modules.greenbids.real.time.data.util.TestBidRequestProvider.givenBanner;
import static org.prebid.server.hooks.modules.greenbids.real.time.data.util.TestBidRequestProvider.givenBidRequest;
import static org.prebid.server.hooks.modules.greenbids.real.time.data.util.TestBidRequestProvider.givenDevice;
import static org.prebid.server.hooks.modules.greenbids.real.time.data.util.TestBidRequestProvider.givenDeviceWithoutUserAgent;
import static org.prebid.server.hooks.modules.greenbids.real.time.data.util.TestBidRequestProvider.givenImpExt;
import static org.prebid.server.hooks.modules.greenbids.real.time.data.util.TestBidRequestProvider.givenSite;

Expand Down Expand Up @@ -181,6 +182,13 @@ public void callShouldNotFilterBiddersAndReturnAnalyticsTagWhenExploration() thr
final InvocationResult<AuctionRequestPayload> result = future.result();

// then
final ActivityImpl activity = (ActivityImpl) result.analyticsTags().activities().getFirst();
final ResultImpl resultImpl = (ResultImpl) activity.results().getFirst();
final String fingerprint = resultImpl.values()
.get("adunitcodevalue")
.get("greenbids")
.get("fingerprint").asText();

assertThat(future).isNotNull();
assertThat(future.succeeded()).isTrue();
assertThat(result).isNotNull();
Expand All @@ -194,6 +202,7 @@ public void callShouldNotFilterBiddersAndReturnAnalyticsTagWhenExploration() thr
+ ".adunitcodevalue._children"
+ ".greenbids._children.fingerprint")
.isEqualTo(toAnalyticsTags(List.of(expectedAnalyticsResult)));
assertThat(fingerprint).isNotNull();
}

@Test
Expand All @@ -208,8 +217,9 @@ public void callShouldFilterBiddersBasedOnModelWhenAnyFeatureNotAvailable() thro
.build();

final Double explorationRate = 0.0001;
final Device device = givenDeviceWithoutUserAgent(identity());
final ExtRequest extRequest = givenExtRequest(explorationRate);
final BidRequest bidRequest = givenBidRequest(request -> request, List.of(imp), null, extRequest);
final BidRequest bidRequest = givenBidRequest(request -> request, List.of(imp), device, extRequest);
final AuctionContext auctionContext = givenAuctionContext(bidRequest, context -> context);
final AuctionInvocationContext invocationContext = givenAuctionInvocationContext(auctionContext);
when(invocationContext.auctionContext()).thenReturn(auctionContext);
Expand All @@ -218,8 +228,7 @@ public void callShouldFilterBiddersBasedOnModelWhenAnyFeatureNotAvailable() thro
when(thresholdsCacheWithExpiration.getIfPresent("throttlingThresholds_test-pbuid"))
.thenReturn(givenThrottlingThresholds());

final BidRequest expectedBidRequest = expectedUpdatedBidRequest(
request -> request, explorationRate);
final BidRequest expectedBidRequest = expectedUpdatedBidRequest(request -> request, explorationRate, device);
final AnalyticsResult expectedAnalyticsResult = expectedAnalyticsResult(false, false);

// when
Expand All @@ -232,6 +241,13 @@ public void callShouldFilterBiddersBasedOnModelWhenAnyFeatureNotAvailable() thro
.bidRequest();

// then
final ActivityImpl activity = (ActivityImpl) result.analyticsTags().activities().getFirst();
final ResultImpl resultImpl = (ResultImpl) activity.results().getFirst();
final String fingerprint = resultImpl.values()
.get("adunitcodevalue")
.get("greenbids")
.get("fingerprint").asText();

assertThat(future).isNotNull();
assertThat(future.succeeded()).isTrue();
assertThat(result).isNotNull();
Expand All @@ -245,10 +261,8 @@ public void callShouldFilterBiddersBasedOnModelWhenAnyFeatureNotAvailable() thro
+ ".adunitcodevalue._children"
+ ".greenbids._children.fingerprint")
.isEqualTo(toAnalyticsTags(List.of(expectedAnalyticsResult)));
assertThat(resultBidRequest).usingRecursiveComparison()
.ignoringFields("imp.ext._children.tid", "device")
.isEqualTo(expectedBidRequest);
assertThat(resultBidRequest.getDevice()).isNull();
assertThat(fingerprint).isNotNull();
assertThat(resultBidRequest).usingRecursiveComparison().isEqualTo(expectedBidRequest);
}

@Test
Expand All @@ -275,7 +289,7 @@ public void callShouldFilterBiddersBasedOnModelResults() throws OrtException, IO
.thenReturn(givenThrottlingThresholds());

final BidRequest expectedBidRequest = expectedUpdatedBidRequest(
request -> request, explorationRate);
request -> request, explorationRate, device);
final AnalyticsResult expectedAnalyticsResult = expectedAnalyticsResult(false, false);

// when
Expand All @@ -288,6 +302,13 @@ public void callShouldFilterBiddersBasedOnModelResults() throws OrtException, IO
.bidRequest();

// then
final ActivityImpl activityImpl = (ActivityImpl) result.analyticsTags().activities().getFirst();
final ResultImpl resultImpl = (ResultImpl) activityImpl.results().getFirst();
final String fingerprint = resultImpl.values()
.get("adunitcodevalue")
.get("greenbids")
.get("fingerprint").asText();

assertThat(future).isNotNull();
assertThat(future.succeeded()).isTrue();
assertThat(result).isNotNull();
Expand All @@ -301,8 +322,8 @@ public void callShouldFilterBiddersBasedOnModelResults() throws OrtException, IO
+ ".adunitcodevalue._children"
+ ".greenbids._children.fingerprint")
.isEqualTo(toAnalyticsTags(List.of(expectedAnalyticsResult)));
assertThat(fingerprint).isNotNull();
assertThat(resultBidRequest).usingRecursiveComparison()
.ignoringFields("imp.ext._children.tid")
.isEqualTo(expectedBidRequest);
}

Expand Down Expand Up @@ -354,7 +375,8 @@ private ThrottlingThresholds givenThrottlingThresholds() throws IOException {

private BidRequest expectedUpdatedBidRequest(
UnaryOperator<BidRequest.BidRequestBuilder> bidRequestCustomizer,
Double explorationRate) {
Double explorationRate,
Device device) {

final Banner banner = givenBanner();

Expand All @@ -376,7 +398,7 @@ private BidRequest expectedUpdatedBidRequest(
.id("request")
.imp(List.of(imp))
.site(givenSite(site -> site))
.device(givenDevice(device -> device))
.device(device)
.ext(givenExtRequest(explorationRate))).build();
}

Expand Down

0 comments on commit d9ec9f1

Please sign in to comment.