From 7d0fb3647951284ddaf44649da4f62c7f51c6c88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Sok=C3=B3=C5=82?= Date: Tue, 8 Nov 2022 15:25:50 +0100 Subject: [PATCH] Discard bid response if ad and adUrl empty --- modules/smartadserverBidAdapter.js | 2 +- .../modules/smartadserverBidAdapter_spec.js | 26 +++++++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/modules/smartadserverBidAdapter.js b/modules/smartadserverBidAdapter.js index d6e1c8de452..4d530de6e8f 100644 --- a/modules/smartadserverBidAdapter.js +++ b/modules/smartadserverBidAdapter.js @@ -208,7 +208,7 @@ export const spec = { const bidResponses = []; let response = serverResponse.body; try { - if (response && !response.isNoAd) { + if (response && !response.isNoAd && (response.ad || response.adUrl)) { const bidRequest = JSON.parse(bidRequestString.data); let bidResponse = { diff --git a/test/spec/modules/smartadserverBidAdapter_spec.js b/test/spec/modules/smartadserverBidAdapter_spec.js index 727a7d7c1d6..6ff9949c800 100644 --- a/test/spec/modules/smartadserverBidAdapter_spec.js +++ b/test/spec/modules/smartadserverBidAdapter_spec.js @@ -200,6 +200,27 @@ describe('Smart bid adapter tests', function () { }).to.not.throw(); }); + it('Should not nest response if ad and adUrl empty', () => { + const BID_RESPONSE_EMPTY = { + body: { + ad: null, + adUrl: null, + cpm: 0.92, + isNoAd: false + } + }; + + const request = spec.buildRequests(DEFAULT_PARAMS); + const bids = spec.interpretResponse(BID_RESPONSE_EMPTY, request[0]); + + expect(bids).to.have.lengthOf(0); + expect(() => { + spec.interpretResponse(BID_RESPONSE_EMPTY, { + data: 'invalid Json' + }); + }).to.not.throw(); + }); + it('Verify parse response', function () { const request = spec.buildRequests(DEFAULT_PARAMS); const bids = spec.interpretResponse(BID_RESPONSE, request[0]); @@ -338,7 +359,6 @@ describe('Smart bid adapter tests', function () { describe('gdpr tests', function () { afterEach(function () { config.resetConfig(); - $$PREBID_GLOBAL$$.requestBids.removeAll(); }); it('Verify build request with GDPR', function () { @@ -390,7 +410,6 @@ describe('Smart bid adapter tests', function () { describe('ccpa/us privacy tests', function () { afterEach(function () { config.resetConfig(); - $$PREBID_GLOBAL$$.requestBids.removeAll(); }); it('Verify build request with us privacy', function () { @@ -419,7 +438,6 @@ describe('Smart bid adapter tests', function () { describe('Instream video tests', function () { afterEach(function () { config.resetConfig(); - $$PREBID_GLOBAL$$.requestBids.removeAll(); }); const INSTREAM_DEFAULT_PARAMS = [{ @@ -678,7 +696,6 @@ describe('Smart bid adapter tests', function () { describe('Outstream video tests', function () { afterEach(function () { config.resetConfig(); - $$PREBID_GLOBAL$$.requestBids.removeAll(); }); const OUTSTREAM_DEFAULT_PARAMS = [{ @@ -1019,7 +1036,6 @@ describe('Smart bid adapter tests', function () { describe('Verify bid requests with multiple mediaTypes', function () { afterEach(function () { config.resetConfig(); - $$PREBID_GLOBAL$$.requestBids.removeAll(); }); var DEFAULT_PARAMS_MULTIPLE_MEDIA_TYPES = [{