Skip to content

Commit

Permalink
Fix for not syncing bidders. (#1598)
Browse files Browse the repository at this point in the history
* fix for #1582

* fixed typo and add unit tests
  • Loading branch information
Matt Kendall authored and matthewlane committed Sep 19, 2017
1 parent 2a6cdf8 commit 99aa370
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
5 changes: 3 additions & 2 deletions modules/prebidServerBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,11 @@ 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
syncedList = bidderCodes.filter(bidder => !syncedList.includes(bidder));
if (syncedList.length === 0) {
return;
}
_cookiesQueued = true;
const payload = JSON.stringify({
uuid: utils.generateUUID(),
bidders: bidderCodes
Expand Down
32 changes: 32 additions & 0 deletions test/spec/modules/prebidServerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 99aa370

Please sign in to comment.