Skip to content
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

Add test for imp.ext.context own copy for each imp change #902

Merged
merged 2 commits into from
Sep 9, 2020
Merged
Changes from 1 commit
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
42 changes: 38 additions & 4 deletions src/test/java/org/prebid/server/auction/ExchangeServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1192,13 +1192,47 @@ public void shouldCleanImpExtContextDataWhenFirstPartyDataNotPermittedForBidder(
exchangeService.holdAuction(givenRequestContext(bidRequest));

// then
final BidRequest capturedRequestExt = captureBidRequest();
assertThat(capturedRequestExt.getImp())
final BidRequest capturedRequest = captureBidRequest();
assertThat(capturedRequest.getImp())
.extracting(Imp::getExt)
.extracting(impExtNode -> impExtNode.get("context"))
.containsOnly(mapper.createObjectNode().put("otherField", "value"));
}

@Test
public void shouldDeepCopyImpExtContextToEachImpressionAndNotRemoveDataForAllWhenDeprecatedOnlyOneBidder() throws InterruptedException {
// given
final ObjectNode impExt = mapper.createObjectNode().put("someBidder", 1).put("deprecatedBidder", 2)
.set("context", mapper.createObjectNode().put("data", "data").put("otherField", "value"));
final BidRequest bidRequest = givenBidRequest(singletonList(Imp.builder()
.id("impId")
.banner(Banner.builder()
.format(singletonList(Format.builder().w(400).h(300).build()))
.build()).ext(impExt).build()),
builder -> builder.ext(ExtRequest.of(ExtRequestPrebid.builder()
.data(ExtRequestPrebidData.of(singletonList("someBidder")))
.build())));
given(httpBidderRequester.requestBids(any(), any(), any(), anyBoolean()))
.willReturn(Future.succeededFuture(givenSeatBid(singletonList(
givenBid(Bid.builder().price(TEN).build())))));

// when
exchangeService.holdAuction(givenRequestContext(bidRequest));

// then
final ArgumentCaptor<BidRequest> bidRequestCaptor = ArgumentCaptor.forClass(BidRequest.class);
verify(httpBidderRequester, times(2)).requestBids(any(), bidRequestCaptor.capture(), any(), anyBoolean());
assertThat(bidRequestCaptor.getAllValues())
.flatExtracting(BidRequest::getImp)
.extracting(Imp::getExt)
.extracting(impExtNode -> impExtNode.get("context"))
.containsOnly(
// data erased for deprecatedBidder
mapper.createObjectNode().put("otherField", "value"),
// data present for someBidder
mapper.createObjectNode().put("data", "data").put("otherField", "value"));
}

@Test
public void shouldSetUserBuyerIdsFromUserExtPrebidAndClearPrebidBuyerIdsAfterwards() {
// given
Expand Down Expand Up @@ -1241,8 +1275,8 @@ public void shouldCleanRequestExtPrebidData() {
exchangeService.holdAuction(givenRequestContext(bidRequest));

// then
final ExtRequest capturedRequestExt = captureBidRequest().getExt();
assertThat(capturedRequestExt).isEqualTo(ExtRequest.of(ExtRequestPrebid.builder()
final ExtRequest capturedRequest = captureBidRequest().getExt();
assertThat(capturedRequest).isEqualTo(ExtRequest.of(ExtRequestPrebid.builder()
.aliases(singletonMap("someBidder", "alias_should_stay"))
.auctiontimestamp(1000L)
.build()));
Expand Down