From cd71f0826af698d47e309f5f63ae03c12e2c7d8f Mon Sep 17 00:00:00 2001 From: mkendall07 Date: Mon, 18 Sep 2017 16:41:22 -0400 Subject: [PATCH 1/2] fix for #1582 --- modules/prebidServerBidAdapter.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/prebidServerBidAdapter.js b/modules/prebidServerBidAdapter.js index 7ec9301e54d..3af10ef3b3e 100644 --- a/modules/prebidServerBidAdapter.js +++ b/modules/prebidServerBidAdapter.js @@ -212,7 +212,9 @@ function PrebidServer() { */ baseAdapter.queueSync = function({bidderCodes}) { let syncedList = StorageManager.get(pbjsSyncsKey) || []; - if (_cookiesQueued || syncedList.length === bidderCodes.length) { + // filter synced bidders - https://github.com/prebid/Prebid.js/issues/1582 + syncList = bidderCodes.filter(bidder => !syncList.includes(bidder)); + if (_cookiesQueued || syncedList.length === 0) { return; } _cookiesQueued = true; From e1095f021b943687e56cf1607b24f048577a9f76 Mon Sep 17 00:00:00 2001 From: mkendall07 Date: Tue, 19 Sep 2017 15:48:28 -0400 Subject: [PATCH 2/2] fixed typo and add unit tests --- modules/prebidServerBidAdapter.js | 5 ++- .../modules/prebidServerBidAdapter_spec.js | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/modules/prebidServerBidAdapter.js b/modules/prebidServerBidAdapter.js index 3af10ef3b3e..bec62dfbc7f 100644 --- a/modules/prebidServerBidAdapter.js +++ b/modules/prebidServerBidAdapter.js @@ -213,11 +213,10 @@ function PrebidServer() { baseAdapter.queueSync = function({bidderCodes}) { let syncedList = StorageManager.get(pbjsSyncsKey) || []; // filter synced bidders - https://github.com/prebid/Prebid.js/issues/1582 - syncList = bidderCodes.filter(bidder => !syncList.includes(bidder)); - if (_cookiesQueued || syncedList.length === 0) { + syncedList = bidderCodes.filter(bidder => !syncedList.includes(bidder)); + if (syncedList.length === 0) { return; } - _cookiesQueued = true; const payload = JSON.stringify({ uuid: utils.generateUUID(), bidders: bidderCodes diff --git a/test/spec/modules/prebidServerBidAdapter_spec.js b/test/spec/modules/prebidServerBidAdapter_spec.js index f55897ac67c..44850249adc 100644 --- a/test/spec/modules/prebidServerBidAdapter_spec.js +++ b/test/spec/modules/prebidServerBidAdapter_spec.js @@ -5,6 +5,7 @@ import CONSTANTS from 'src/constants.json'; import * as utils from 'src/utils'; import cookie from 'src/cookie'; import { userSync } from 'src/userSync'; +import { StorageManager } from 'src/storagemanager'; let CONFIG = { accountId: '1', @@ -157,6 +158,37 @@ describe('S2S Adapter', () => { beforeEach(() => adapter = new Adapter()); + describe('queue sync function', () => { + let server; + let storageManagerAddStub; + + beforeEach(() => { + server = sinon.fakeServer.create(); + storageManagerAddStub = sinon.stub(StorageManager, 'add'); + }); + + afterEach(() => { + server.restore(); + storageManagerAddStub.restore(); + localStorage.removeItem('pbjsSyncs'); + }); + + it('exists and is a function', () => { + expect(adapter.queueSync).to.exist.and.to.be.a('function'); + }); + + it('requests only bidders that are not already synced', () => { + server.respondWith(JSON.stringify({status: 'ok', bidderCodes: ['rubicon'] })); + const reqBidderCodes = ['appnexus', 'newBidder']; + const syncedBidders = ['appnexus', 'rubicon']; + localStorage.setItem('pbjsSyncs', JSON.stringify(syncedBidders)); + adapter.setConfig(CONFIG); + adapter.queueSync({bidderCodes: reqBidderCodes}); + server.respond(); + sinon.assert.calledTwice(storageManagerAddStub); + }); + }); + describe('request function', () => { let xhr; let requests;