From d9ac4db87c1e95c4e13bd67756e63d0d5c104672 Mon Sep 17 00:00:00 2001 From: anthony Date: Tue, 10 Apr 2018 16:15:51 -0700 Subject: [PATCH] ADSS-281 implement getUserSyncs and putting checks for empty ad server response --- modules/gumgumBidAdapter.js | 38 ++++++++++++++++++++-- test/spec/modules/gumgumBidAdapter_spec.js | 22 +++++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/modules/gumgumBidAdapter.js b/modules/gumgumBidAdapter.js index fc36e18e3ac..0b7a4223063 100644 --- a/modules/gumgumBidAdapter.js +++ b/modules/gumgumBidAdapter.js @@ -148,6 +148,16 @@ function buildRequests (validBidRequests) { function interpretResponse (serverResponse, bidRequest) { const bidResponses = [] const serverResponseBody = serverResponse.body + const defaultResponse = { + ad: { + price: 0, + id: 0, + markup: '' + }, + pag: { + pvid: 0 + } + } const { ad: { price: cpm, @@ -158,7 +168,7 @@ function interpretResponse (serverResponse, bidRequest) { pag: { pvid } - } = serverResponseBody + } = Object.assign(defaultResponse, serverResponseBody) let isTestUnit = (bidRequest.data && bidRequest.data.pi === 3 && bidRequest.data.si === 9) let [width, height] = utils.parseSizesInput(bidRequest.sizes)[0].split('x') @@ -183,11 +193,35 @@ function interpretResponse (serverResponse, bidRequest) { return bidResponses } +/** + * Register the user sync pixels which should be dropped after the auction. + * + * @param {SyncOptions} syncOptions Which user syncs are allowed? + * @param {ServerResponse[]} serverResponses List of server's responses. + * @return {UserSync[]} The user syncs which should be dropped. + */ +function getUserSyncs (syncOptions, serverResponses) { + const responses = serverResponses.map((response) => { + return (response.body && response.body.pxs && response.body.pxs.scr) || [] + }) + const userSyncs = responses.reduce(function (usersyncs, response) { + return usersyncs.concat(response) + }, []) + const syncs = userSyncs.map((sync) => { + return { + type: sync.t === 'f' ? 'iframe' : 'image', + url: sync.u + } + }) + return syncs; +} + export const spec = { code: BIDDER_CODE, aliases: ALIAS_BIDDER_CODE, isBidRequestValid, buildRequests, - interpretResponse + interpretResponse, + getUserSyncs } registerBidder(spec) diff --git a/test/spec/modules/gumgumBidAdapter_spec.js b/test/spec/modules/gumgumBidAdapter_spec.js index 30627d4d12d..276972a163f 100644 --- a/test/spec/modules/gumgumBidAdapter_spec.js +++ b/test/spec/modules/gumgumBidAdapter_spec.js @@ -135,4 +135,26 @@ describe('gumgumAdapter', () => { expect(result.length).to.equal(0); }); }) + describe('getUserSyncs', () => { + const syncOptions = { + 'iframeEnabled': 'true' + } + const response = { + 'pxs': { + 'scr': [ + { + 't': 'i', + 'u': 'https://c.gumgum.com/images/pixel.gif' + }, + { + 't': 'f', + 'u': 'https://www.nytimes.com/' + } + ] + } + } + let result = spec.getUserSyncs(syncOptions, [{ body: response }]); + expect(result[0].type).to.equal('image') + expect(result[1].type).to.equal('iframe') + }) });