From 48cd24551a633d1421e10a8dad4f8a957f14d87a Mon Sep 17 00:00:00 2001 From: Patrick Loughrey Date: Mon, 1 May 2023 09:24:54 -0400 Subject: [PATCH] Triplelift Bid Adapter: copying ad unit impression data (#9865) * TL-35335: Cast playbackmethod as array * TL-36204: Copy tid to imp extension obj * Added support for entire ortb2Imp obj * Only setting what exists in ortb2Imp.ext * Added additional test to check copy of entire ext obj * Revert "TL-36204: Copy tid to imp extension object" * TL-36204: Copying ortb2Imp.ext to impression ext obj * Added edge case logic and additional test * recos for tid change * Added spread operator to replace deepClone --------- Co-authored-by: nllerandi3lift <75995508+nllerandi3lift@users.noreply.github.com> Co-authored-by: Nick Llerandi --- modules/tripleliftBidAdapter.js | 7 +++ .../spec/modules/tripleliftBidAdapter_spec.js | 61 ++++++++++++++++--- 2 files changed, 60 insertions(+), 8 deletions(-) diff --git a/modules/tripleliftBidAdapter.js b/modules/tripleliftBidAdapter.js index 038cd7d757d..45931bce27e 100644 --- a/modules/tripleliftBidAdapter.js +++ b/modules/tripleliftBidAdapter.js @@ -130,8 +130,15 @@ function _buildPostBody(bidRequests, bidderRequest) { } if (!isEmpty(bidRequest.ortb2Imp)) { + // legacy method for extracting ortb2Imp.ext imp.fpd = _getAdUnitFpd(bidRequest.ortb2Imp); + + // preferred method for extracting ortb2Imp.ext + if (!isEmpty(bidRequest.ortb2Imp.ext)) { + imp.ext = { ...bidRequest.ortb2Imp.ext }; + } } + return imp; }); diff --git a/test/spec/modules/tripleliftBidAdapter_spec.js b/test/spec/modules/tripleliftBidAdapter_spec.js index 4debf516f89..718d030be91 100644 --- a/test/spec/modules/tripleliftBidAdapter_spec.js +++ b/test/spec/modules/tripleliftBidAdapter_spec.js @@ -139,15 +139,13 @@ describe('triplelift adapter', function () { sizes: [[300, 250], [300, 600], [1, 1, 1], ['flex']], bidId: '30b31c1838de1e', bidderRequestId: '22edbae2733bf6', + transactionId: '173f49a8-7549-4218-a23c-e7ba59b47229', auctionId: '1d1a030790a475', userId: {}, schain, ortb2Imp: { ext: { - data: { - pbAdSlot: 'homepage-top-rect', - adUnitSpecificAttribute: 123 - } + tid: '173f49a8-7549-4218-a23c-e7ba59b47229' } } }, @@ -178,6 +176,15 @@ describe('triplelift adapter', function () { auctionId: '1d1a030790a475', userId: {}, schain, + ortb2Imp: { + ext: { + data: { + pbAdSlot: 'homepage-top-rect', + adUnitSpecificAttribute: 123 + }, + tid: '173f49a8-7549-4218-a23c-e7ba59b47229' + } + } }, // banner and outstream video { @@ -245,6 +252,11 @@ describe('triplelift adapter', function () { auctionId: '1d1a030790a475', userId: {}, schain, + ortb2Imp: { + misc: { + test: 1 + } + } }, // incomplete banner and incomplete video { @@ -689,6 +701,39 @@ describe('triplelift adapter', function () { expect(payload.imp[13].video.placement).to.equal(3); }); + it('should add tid to imp.ext if transactionId exists', function() { + const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); + expect(request.data.imp[0].ext.tid).to.exist.and.be.a('string'); + expect(request.data.imp[0].ext.tid).to.equal('173f49a8-7549-4218-a23c-e7ba59b47229'); + }); + + it('should not add impression ext object if ortb2Imp does not exist', function() { + const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); + expect(request.data.imp[2].ext).to.not.exist; + }); + + it('should not add impression ext object if ortb2Imp.ext does not exist', function() { + const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); + expect(request.data.imp[3].ext).to.not.exist; + }); + + it('should copy entire impression ext object', function() { + const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); + expect(request.data.imp[1].ext).to.haveOwnProperty('tid'); + expect(request.data.imp[1].ext).to.haveOwnProperty('data'); + expect(request.data.imp[1].ext.data).to.haveOwnProperty('adUnitSpecificAttribute'); + expect(request.data.imp[1].ext.data).to.haveOwnProperty('pbAdSlot'); + expect(request.data.imp[1].ext).to.deep.equal( + { + data: { + pbAdSlot: 'homepage-top-rect', + adUnitSpecificAttribute: 123 + }, + tid: '173f49a8-7549-4218-a23c-e7ba59b47229' + } + ); + }); + it('should add tdid to the payload if included', function () { const id = '6bca7f6b-a98a-46c0-be05-6020f7604598'; bidRequests[0].userId.tdid = id; @@ -1103,10 +1148,10 @@ describe('triplelift adapter', function () { }); it('should send ad unit fpd if kvps are available', function() { const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - expect(request.data.imp[0].fpd.context).to.haveOwnProperty('data'); - expect(request.data.imp[0].fpd.context.data).to.haveOwnProperty('pbAdSlot'); - expect(request.data.imp[0].fpd.context.data).to.haveOwnProperty('adUnitSpecificAttribute'); - expect(request.data.imp[1].fpd).to.not.exist; + expect(request.data.imp[1].fpd.context).to.haveOwnProperty('data'); + expect(request.data.imp[1].fpd.context.data).to.haveOwnProperty('pbAdSlot'); + expect(request.data.imp[1].fpd.context.data).to.haveOwnProperty('adUnitSpecificAttribute'); + expect(request.data.imp[2].fpd).to.not.exist; }); it('should send 1PlusX data as fpd if localStorage is available and no other fpd is defined', function() { sandbox.stub(storage, 'getDataFromLocalStorage').callsFake(() => '{"kid":1,"s":"ySRdArquXuBolr/cVv0UNqrJhTO4QZsbNH/t+2kR3gXjbA==","t":"/yVtBrquXuBolr/cVv0UNtx1mssdLYeKFhWFI3Dq1dJnug=="}');