Skip to content

Commit

Permalink
fix: improve logic and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vpontesfreestar committed Dec 19, 2023
1 parent b1430f8 commit 83bf3af
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/main/java/org/prebid/server/auction/ExchangeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -1135,25 +1135,18 @@ private static Content prepareContent(Content content) {
*/
private Source prepareSource(String bidder, BidRequest bidRequest, boolean transmitTid) {
final Source receivedSource = bidRequest.getSource();
final SupplyChain bidderSchain = supplyChainResolver.resolveForBidder(bidder, bidRequest);

if (bidderSchain == null) {

if (receivedSource == null) {
return null;
}
final SupplyChain bidderSchain = supplyChainResolver.resolveForBidder(bidder, bidRequest);

return receivedSource.toBuilder()
.tid(transmitTid ? receivedSource.getTid() : null)
.build();
if (bidderSchain == null && transmitTid) {
return receivedSource;
}

return receivedSource == null
? Source.builder().schain(bidderSchain).build()
: receivedSource.toBuilder()
.schain(bidderSchain)
.tid(transmitTid ? receivedSource.getTid() : null)
.build();
.schain(bidderSchain != null ? bidderSchain : receivedSource.getSchain())
.tid(transmitTid ? receivedSource.getTid() : null).build();
}

/**
Expand Down
44 changes: 44 additions & 0 deletions src/test/java/org/prebid/server/auction/ExchangeServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,50 @@ public void shouldPassTidsIfCreateTidsTrue() {
.containsExactly(TextNode.valueOf("bidderTidValue"));
}

@Test
public void shouldRemoveTidsIfCreateTidsFalseAndKeepReceivedSchain() {
// given
final String bidderName = "bidder";
final Bidder<?> bidder = mock(Bidder.class);
givenBidder(bidderName, bidder, givenEmptySeatBid());

final Imp imp = givenImp(Map.of(bidderName, 1), identity());
imp.getExt().put("tid", "bidderTidValue");
final BidRequest bidRequest = givenBidRequest(
singletonList(imp),
builder -> builder
.source(Source.builder().tid("sourceTidValue").schain(SupplyChain.of(1,
List.of(SupplyChainNode.of("freestar.com", "66", null, null,
null, 1, null)), "1.0", null))
.build())
.ext(ExtRequest.of(
ExtRequestPrebid.builder()
.createTids(false)
.build())));

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

// then
final ArgumentCaptor<BidderRequest> bidRequestCaptor = ArgumentCaptor.forClass(BidderRequest.class);
verify(httpBidderRequester)
.requestBids(same(bidder), bidRequestCaptor.capture(), any(), any(), any(), any(), anyBoolean());

final BidRequest capturedBidRequest = bidRequestCaptor.getValue().getBidRequest();
assertThat(capturedBidRequest)
.extracting(BidRequest::getSource)
.extracting(Source::getTid)
.isNull();
assertThat(capturedBidRequest)
.extracting(BidRequest::getSource)
.extracting(Source::getSchain)
.isNotNull();
assertThat(capturedBidRequest.getImp())
.extracting(Imp::getExt)
.extracting(ext -> ext.get("tid"))
.containsOnlyNulls();
}

@Test
public void shouldRemoveTidsIfTransmitTidActivityDisallowed() {
// given
Expand Down

0 comments on commit 83bf3af

Please sign in to comment.