From 4a64113ebea00488e321cabfe91d24b79a35234f Mon Sep 17 00:00:00 2001 From: pokutuna Date: Fri, 9 Nov 2018 14:40:55 +0900 Subject: [PATCH] handles empty responses in getUserSyncs & add tests - ajaBidAdapter --- modules/ajaBidAdapter.js | 2 +- test/spec/modules/ajaBidAdapter_spec.js | 42 +++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/modules/ajaBidAdapter.js b/modules/ajaBidAdapter.js index bbdbeb53886..ff44aaa1208 100644 --- a/modules/ajaBidAdapter.js +++ b/modules/ajaBidAdapter.js @@ -93,7 +93,7 @@ export const spec = { getUserSyncs: function(syncOptions, serverResponses) { const syncs = []; - if (syncOptions.pixelEnabled) { + if (syncOptions.pixelEnabled && serverResponses.length) { const bidderResponseBody = serverResponses[0].body; if (bidderResponseBody.syncs) { bidderResponseBody.syncs.forEach(sync => { diff --git a/test/spec/modules/ajaBidAdapter_spec.js b/test/spec/modules/ajaBidAdapter_spec.js index 5d5e5924cd5..8561f8c0baf 100644 --- a/test/spec/modules/ajaBidAdapter_spec.js +++ b/test/spec/modules/ajaBidAdapter_spec.js @@ -141,4 +141,46 @@ describe('AjaAdapter', function () { expect(result.length).to.equal(0); }); }); + + describe('getUserSyncs', function () { + const bidResponse1 = { + body: { + 'is_ad_return': true, + 'ad': { /* ad body */ }, + 'syncs': [ + 'https://example.test/1' + ] + } + }; + + const bidResponse2 = { + body: { + 'is_ad_return': true, + 'ad': { /* ad body */ }, + 'syncs': [ + 'https://example.test/2' + ] + } + }; + + it('should use a sync url from first response', function () { + const syncs = spec.getUserSyncs({ pixelEnabled: true }, [bidResponse1, bidResponse2]); + expect(syncs).to.deep.equal([ + { + type: 'image', + url: 'https://example.test/1' + } + ]); + }); + + it('handle empty response (e.g. timeout)', function () { + const syncs = spec.getUserSyncs({ pixelEnabled: true }, []); + expect(syncs).to.deep.equal([]); + }); + + it('returns empty syncs when not enabled', function () { + const syncs = spec.getUserSyncs({ pixelEnabled: false }, [bidResponse1]); + expect(syncs).to.deep.equal([]); + }); + }); });