From 77c7a553bd2f9b05e69e3d19f039035e0190a284 Mon Sep 17 00:00:00 2001 From: Surovenko Alexey Date: Wed, 16 Jun 2021 13:55:55 +0600 Subject: [PATCH] Zeta Ssp Bid Adapter: multiple bid responses --- modules/zetaSspBidAdapter.js | 47 +++++------ test/spec/modules/zetaSspBidAdapter_spec.js | 87 +++++++++++++-------- 2 files changed, 79 insertions(+), 55 deletions(-) diff --git a/modules/zetaSspBidAdapter.js b/modules/zetaSspBidAdapter.js index 54c0657e9df..76ceea0fdd1 100644 --- a/modules/zetaSspBidAdapter.js +++ b/modules/zetaSspBidAdapter.js @@ -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; }, /** diff --git a/test/spec/modules/zetaSspBidAdapter_spec.js b/test/spec/modules/zetaSspBidAdapter_spec.js index 080c487a29e..9f25a489dab 100644 --- a/test/spec/modules/zetaSspBidAdapter_spec.js +++ b/test/spec/modules/zetaSspBidAdapter_spec.js @@ -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', @@ -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 () {