Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zeta Ssp Bid Adapter: multiple bid reponses #7034

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 25 additions & 22 deletions modules/zetaSspBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,29 +102,32 @@ export const spec = {
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function (serverResponse, bidRequest) {
let bidResponse = [];
if (Object.keys(serverResponse.body).length !== 0) {
let zetaResponse = serverResponse.body;
let zetaBid = zetaResponse.seatbid[0].bid[0];
let bid = {
requestId: zetaBid.impid,
cpm: zetaBid.price,
currency: zetaResponse.cur,
width: zetaBid.w,
height: zetaBid.h,
ad: zetaBid.adm,
ttl: TTL,
creativeId: zetaBid.crid,
netRevenue: NET_REV,
};
if (zetaBid.adomain && zetaBid.adomain.length) {
bid.meta = {
advertiserDomains: zetaBid.adomain
};
}
bidResponse.push(bid);
let bidResponses = [];
const response = (serverResponse || {}).body;
if (response && response.seatbid && response.seatbid[0].bid && response.seatbid[0].bid.length) {
response.seatbid.forEach(zetaSeatbid => {
zetaSeatbid.bid.forEach(zetaBid => {
let bid = {
requestId: zetaBid.impid,
cpm: zetaBid.price,
currency: response.cur,
width: zetaBid.w,
height: zetaBid.h,
ad: zetaBid.adm,
ttl: TTL,
creativeId: zetaBid.crid,
netRevenue: NET_REV,
};
if (zetaBid.adomain && zetaBid.adomain.length) {
bid.meta = {
advertiserDomains: zetaBid.adomain
};
}
bidResponses.push(bid);
})
})
}
return bidResponse;
return bidResponses;
},

/**
Expand Down
87 changes: 54 additions & 33 deletions test/spec/modules/zetaSspBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {spec} from '../../../modules/zetaSspBidAdapter.js'

describe('Zeta Ssp Bid Adapter', function() {
describe('Zeta Ssp Bid Adapter', function () {
const eids = [
{
'source': 'example.com',
Expand Down Expand Up @@ -83,45 +83,66 @@ describe('Zeta Ssp Bid Adapter', function() {
expect(payload).to.not.be.empty;
});

const responseBody = {
id: '12345',
seatbid: [
{
bid: [
it('Test the response parsing function', function () {
const response = {
body: {
id: '12345',
seatbid: [
{
id: 'auctionId',
impid: 'impId',
price: 0.0,
adm: 'adMarkup',
crid: 'creativeId',
adomain: [
'https://example.com'
],
h: 250,
w: 300
bid: [
{
id: 'auctionId',
impid: 'impId',
price: 0.0,
adm: 'adMarkup',
crid: 'creativeId',
adomain: [
'https://example.com'
],
h: 250,
w: 300
},
{
id: 'auctionId2',
impid: 'impId2',
price: 0.1,
adm: 'adMarkup2',
crid: 'creativeId2',
adomain: [
'https://example2.com'
],
h: 150,
w: 200
}
]
}
]
],
cur: 'USD'
}
],
cur: 'USD'
};

it('Test the response parsing function', function () {
const receivedBid = responseBody.seatbid[0].bid[0];
const response = {};
response.body = responseBody;
};

const bidResponse = spec.interpretResponse(response, null);
expect(bidResponse).to.not.be.empty;

const bid = bidResponse[0];
expect(bid).to.not.be.empty;
expect(bid.ad).to.equal(receivedBid.adm);
expect(bid.cpm).to.equal(receivedBid.price);
expect(bid.height).to.equal(receivedBid.h);
expect(bid.width).to.equal(receivedBid.w);
expect(bid.requestId).to.equal(receivedBid.impid);
expect(bid.meta.advertiserDomains).to.equal(receivedBid.adomain);
const bid1 = bidResponse[0];
const receivedBid1 = response.body.seatbid[0].bid[0];
expect(bid1).to.not.be.empty;
expect(bid1.ad).to.equal(receivedBid1.adm);
expect(bid1.cpm).to.equal(receivedBid1.price);
expect(bid1.height).to.equal(receivedBid1.h);
expect(bid1.width).to.equal(receivedBid1.w);
expect(bid1.requestId).to.equal(receivedBid1.impid);
expect(bid1.meta.advertiserDomains).to.equal(receivedBid1.adomain);

const bid2 = bidResponse[1];
const receivedBid2 = response.body.seatbid[0].bid[1];
expect(bid2).to.not.be.empty;
expect(bid2.ad).to.equal(receivedBid2.adm);
expect(bid2.cpm).to.equal(receivedBid2.price);
expect(bid2.height).to.equal(receivedBid2.h);
expect(bid2.width).to.equal(receivedBid2.w);
expect(bid2.requestId).to.equal(receivedBid2.impid);
expect(bid2.meta.advertiserDomains).to.equal(receivedBid2.adomain);
});

it('Different cases for user syncs', function () {
Expand Down