Skip to content

Commit

Permalink
Zeta ssp adapter: added multiimp request support (#8813)
Browse files Browse the repository at this point in the history
* multiimp ability

* add some test

* fix tests

* fix tests 2

Co-authored-by: Surovenko Alexey <[email protected]>
  • Loading branch information
asurovenko-zeta and surovenko authored Aug 16, 2022
1 parent 6e36e36 commit 2bc9f9d
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 21 deletions.
45 changes: 24 additions & 21 deletions modules/zeta_global_sspBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,31 +69,34 @@ export const spec = {
*/
buildRequests: function (validBidRequests, bidderRequest) {
const secure = 1; // treat all requests as secure
const request = validBidRequests[0];
const params = request.params;
const impData = {
id: request.bidId,
secure: secure
};
if (request.mediaTypes) {
for (const mediaType in request.mediaTypes) {
switch (mediaType) {
case BANNER:
impData.banner = buildBanner(request);
break;
case VIDEO:
impData.video = buildVideo(request);
break;
const params = validBidRequests[0].params;
const imps = validBidRequests.map(request => {
const impData = {
id: request.bidId,
secure: secure
};
if (request.mediaTypes) {
for (const mediaType in request.mediaTypes) {
switch (mediaType) {
case BANNER:
impData.banner = buildBanner(request);
break;
case VIDEO:
impData.video = buildVideo(request);
break;
}
}
}
}
if (!impData.banner && !impData.video) {
impData.banner = buildBanner(request);
}
if (!impData.banner && !impData.video) {
impData.banner = buildBanner(request);
}
return impData;
});

let payload = {
id: bidderRequest.auctionId,
cur: [DEFAULT_CUR],
imp: [impData],
imp: imps,
site: params.site ? params.site : {},
device: {...(bidderRequest.ortb2?.device || {}), ...params.device},
user: params.user ? params.user : {},
Expand Down Expand Up @@ -126,7 +129,7 @@ export const spec = {
deepSetValue(payload, 'regs.ext.us_privacy', bidderRequest.uspConsent);
}

provideEids(request, payload);
provideEids(validBidRequests[0], payload);
const url = params.shortname ? ENDPOINT_URL.concat('?shortname=', params.shortname) : ENDPOINT_URL;
return {
method: 'POST',
Expand Down
59 changes: 59 additions & 0 deletions test/spec/modules/zeta_global_sspBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,48 @@ describe('Zeta Ssp Bid Adapter', function () {
test: 1
};

const multiImpRequest = [
{
bidId: 12345,
auctionId: 67890,
mediaTypes: {
banner: {
sizes: [[300, 250]],
}
},
refererInfo: {
page: 'http://www.zetaglobal.com/page?param=value',
domain: 'www.zetaglobal.com',
},
gdprConsent: {
gdprApplies: 1,
consentString: 'consentString'
},
uspConsent: 'someCCPAString',
params: params,
userIdAsEids: eids
}, {
bidId: 54321,
auctionId: 67890,
mediaTypes: {
banner: {
sizes: [[600, 400]],
}
},
refererInfo: {
page: 'http://www.zetaglobal.com/page?param=value',
domain: 'www.zetaglobal.com',
},
gdprConsent: {
gdprApplies: 1,
consentString: 'consentString'
},
uspConsent: 'someCCPAString',
params: params,
userIdAsEids: eids
}
];

const bannerRequest = [{
bidId: 12345,
auctionId: 67890,
Expand Down Expand Up @@ -285,4 +327,21 @@ describe('Zeta Ssp Bid Adapter', function () {
expect(payload.ext.tags.someTag).to.eql(444);
expect(payload.ext.tags.shortname).to.be.undefined;
});

it('Test multi imp', function () {
const request = spec.buildRequests(multiImpRequest, multiImpRequest[0]);
const payload = JSON.parse(request.data);
expect(request.url).to.eql('https://ssp.disqus.com/bid/prebid?shortname=test_shortname');

expect(payload.imp.length).to.eql(2);

expect(payload.imp[0].id).to.eql(12345);
expect(payload.imp[1].id).to.eql(54321);

expect(payload.imp[0].banner.w).to.eql(300);
expect(payload.imp[0].banner.h).to.eql(250);

expect(payload.imp[1].banner.w).to.eql(600);
expect(payload.imp[1].banner.h).to.eql(400);
});
});

0 comments on commit 2bc9f9d

Please sign in to comment.