Skip to content

Commit

Permalink
add unit test, add params to auction signals
Browse files Browse the repository at this point in the history
  • Loading branch information
wsusrasp committed Oct 2, 2023
1 parent 0e4637e commit cfe6725
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 18 deletions.
31 changes: 13 additions & 18 deletions modules/rasBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,23 +130,23 @@ const getGdprParams = (bidderRequest) => {
};

const parseAuctionConfigs = (serverResponse, bidRequest) => {
if (isEmpty(serverResponse) || isEmpty(bidRequest)) {
if (isEmpty(bidRequest)) {
return null;
}
let auctionConfigs = [];
const bidConfigs = Object.fromEntries(bidRequest.bidIds.map(x => [x.bidId, x]));
const auctionConfigs = [];
const gctx = serverResponse && serverResponse.body?.gctx;

serverResponse.ads.filter(bid => bidConfigs.hasOwnProperty(bid.id) && bidConfigs[bid.id].fledgeEnabled).forEach((bid) => {
bidRequest.bidIds.filter(bid => bid.fledgeEnabled).forEach((bid) => {
auctionConfigs.push({
'bidId': bidConfigs[bid.id].bidId,
'bidId': bid.bidId,
'config': {
'seller': 'https://csr.onet.pl',
'decisionLogicUrl': `https://csr.onet.pl/${bidConfigs[bid.id].network}/v1/protected-audience-api/decision-logic.js`,
'decisionLogicUrl': `https://csr.onet.pl/${encodeURIComponent(bid.params.network)}/v1/protected-audience-api/decision-logic.js`,
'interestGroupBuyers': ['https://csr.onet.pl'],
'auctionSignals': {
'site': bidConfigs[bid.id].site,
'kvismobile': bidConfigs[bid.id].isMobile,
'iusizes': bidConfigs[bid.id].iusizes
'params': bid.params,
'sizes': bid.sizes,
'gctx': gctx
}
}
});
Expand Down Expand Up @@ -180,10 +180,8 @@ export const spec = {
const bidIds = bidRequests.map((bid) => ({
slot: bid.params.slot,
bidId: bid.bidId,
network: network,
site: bid.params.site,
isMobile: Boolean(bid.params.pageContext?.keyValues?.ismobile),
iusizes: getAdUnitSizes(bid),
sizes: getAdUnitSizes(bid),
params: bid.params,
fledgeEnabled: fledgeEligible
}));

Expand All @@ -196,12 +194,9 @@ export const spec = {

interpretResponse: function (serverResponse, bidRequest) {
const response = serverResponse.body;
if (!response || !response.ads || response.ads.length === 0) {
return [];
}

const fledgeAuctionConfigs = parseAuctionConfigs(response, bidRequest);
const bids = response.ads.map(buildBid).filter((bid) => !isEmpty(bid));
const fledgeAuctionConfigs = parseAuctionConfigs(serverResponse, bidRequest);
const bids = (!response || !response.ads || response.ads.length === 0) ? [] : response.ads.map(buildBid).filter((bid) => !isEmpty(bid));

if (fledgeAuctionConfigs) {
// Return a tuple of bids and auctionConfigs. It is possible that bids could be null.
Expand Down
52 changes: 52 additions & 0 deletions test/spec/modules/rasBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect } from 'chai';
import { spec } from 'modules/rasBidAdapter.js';
import { newBidder } from 'src/adapters/bidderFactory.js';
import {getAdUnitSizes} from '../../../src/utils';

const CSR_ENDPOINT = 'https://csr.onet.pl/4178463/csr-006/csr.json?nid=4178463&';

Expand Down Expand Up @@ -192,5 +193,56 @@ describe('rasBidAdapter', function () {
const resp = spec.interpretResponse({ body: res }, {});
expect(resp).to.deep.equal([]);
});

it('should generate auctionConfig when fledge is enabled', function () {
let bidRequest = {
method: 'GET',
url: 'https://example.com',
bidIds: [{
slot: 'top',
bidId: '123',
network: 'testnetwork',
sizes: ['300x250'],
params: {
site: 'testsite',
area: 'testarea',
network: 'testnetwork'
},
fledgeEnabled: true
},
{
slot: 'top',
bidId: '456',
network: 'testnetwork',
sizes: ['300x250'],
params: {
site: 'testsite',
area: 'testarea',
network: 'testnetwork'
},
fledgeEnabled: false
}]
};

let auctionConfigs = [{
'bidId': '123',
'config': {
'seller': 'https://csr.onet.pl',
'decisionLogicUrl': 'https://csr.onet.pl/testnetwork/v1/protected-audience-api/decision-logic.js',
'interestGroupBuyers': ['https://csr.onet.pl'],
'auctionSignals': {
'params': {
site: 'testsite',
area: 'testarea',
network: 'testnetwork'
},
'sizes': ['300x250'],
'gctx': '1234567890'
}
}
}];
const resp = spec.interpretResponse({body: {gctx: '1234567890'}}, bidRequest);
expect(resp).to.deep.equal({bids: [], fledgeAuctionConfigs: auctionConfigs});
});
});
});

0 comments on commit cfe6725

Please sign in to comment.