Skip to content

Commit

Permalink
KRAK-4688: Adds support for PAAPI module (prebid#34) (prebid#11480)
Browse files Browse the repository at this point in the history
* adds support for paapi module

* slight revision
  • Loading branch information
nickllerandi authored and f.caspar committed May 14, 2024
1 parent 7fc5977 commit 8b86d69
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
17 changes: 16 additions & 1 deletion modules/kargoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down Expand Up @@ -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) {
Expand Down
49 changes: 49 additions & 0 deletions test/spec/modules/kargoBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 8b86d69

Please sign in to comment.