From 0be75953199556af5020b5699ab6f2851acc74fd Mon Sep 17 00:00:00 2001 From: Nick Llerandi Date: Mon, 13 May 2024 10:46:56 -0400 Subject: [PATCH] KRAK-4688: Adds support for PAAPI module (#34) (#11480) * adds support for paapi module * slight revision --- modules/kargoBidAdapter.js | 17 +++++++- test/spec/modules/kargoBidAdapter_spec.js | 49 +++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/modules/kargoBidAdapter.js b/modules/kargoBidAdapter.js index f3b3166ccadc..cafbbd982faa 100644 --- a/modules/kargoBidAdapter.js +++ b/modules/kargoBidAdapter.js @@ -196,6 +196,7 @@ function buildRequests(validBidRequests, bidderRequest) { function interpretResponse(response, bidRequest) { const bids = response.body; + const fledgeAuctionConfigs = []; const bidResponses = []; if (isEmpty(bids) || typeof bids !== 'object') { @@ -237,9 +238,23 @@ function interpretResponse(response, bidRequest) { } bidResponses.push(bidResponse); + + if (adUnit.auctionConfig) { + fledgeAuctionConfigs.push({ + bidId: bidID, + config: adUnit.auctionConfig + }) + } } - return bidResponses; + if (fledgeAuctionConfigs.length > 0) { + return { + bids: bidResponses, + fledgeAuctionConfigs + } + } else { + return bidResponses; + } } function getUserSyncs(syncOptions, _, gdprConsent, usPrivacy, gppConsent) { diff --git a/test/spec/modules/kargoBidAdapter_spec.js b/test/spec/modules/kargoBidAdapter_spec.js index 7aa853ad902c..ee89d6468a5d 100644 --- a/test/spec/modules/kargoBidAdapter_spec.js +++ b/test/spec/modules/kargoBidAdapter_spec.js @@ -1807,6 +1807,55 @@ describe('kargo adapter tests', function() { advertiserDomains: [ 'https://foo.com', 'https://bar.com' ] }); }); + + it('should return fledgeAuctionConfigs if provided in bid response', function () { + const auctionConfig = { + seller: 'https://kargo.com', + decisionLogicUrl: 'https://kargo.com/decision_logic.js', + interestGroupBuyers: ['https://some_buyer.com'], + perBuyerSignals: { + 'https://some_buyer.com': { a: 1 } + } + } + + const body = response.body; + for (const key in body) { + if (body.hasOwnProperty(key)) { + if (key % 2 !== 0) { // Add auctionConfig to every other object + body[key].auctionConfig = auctionConfig; + } + } + } + + let result = spec.interpretResponse(response, bidderRequest); + + // Test properties of bidResponses + result.bids.forEach(bid => { + expect(bid).to.have.property('requestId'); + expect(bid).to.have.property('cpm'); + expect(bid).to.have.property('width'); + expect(bid).to.have.property('height'); + expect(bid).to.have.property('ttl'); + expect(bid).to.have.property('creativeId'); + expect(bid.netRevenue).to.be.true; + expect(bid).to.have.property('meta').that.is.an('object'); + }); + + // Test properties of fledgeAuctionConfigs + expect(result.fledgeAuctionConfigs).to.have.lengthOf(3); + + const expectedBidIds = ['1', '3', '5']; // Expected bidIDs + result.fledgeAuctionConfigs.forEach(config => { + expect(config).to.have.property('bidId'); + expect(expectedBidIds).to.include(config.bidId); + + expect(config).to.have.property('config').that.is.an('object'); + expect(config.config).to.have.property('seller', 'https://kargo.com'); + expect(config.config).to.have.property('decisionLogicUrl', 'https://kargo.com/decision_logic.js'); + expect(config.config.interestGroupBuyers).to.be.an('array').that.includes('https://some_buyer.com'); + expect(config.config.perBuyerSignals).to.have.property('https://some_buyer.com').that.deep.equals({ a: 1 }); + }); + }); }); describe('getUserSyncs', function() {