Skip to content

Commit

Permalink
PBjs Core : fix creation of per-bidder syncOptions (prebid#12615)
Browse files Browse the repository at this point in the history
* Update tests for sspBC adapter

Update tests for sspBC adapter:
- change userSync test (due to tcf param appended in v4.6)
- add tests for onBidWon and onTimeout

* [sspbc-adapter] 5.3 updates: content-type for notifications

* [sspbc-adapter] pass CTA to native bid

* [sspbc-5.3] keep pbsize for detected adunits

* [maintenance] - remove old test for sspBc bid adaptor

* [sspbc-5.3] increment adaptor ver

* [sspbc-adapter] maintenance update to sspBCBidAdapter

* remove yarn.lock

* Delete package-lock.json

* remove package-lock.jsonfrom pull request

* [sspbc-adapter] send pageViewId in request

* [sspbc-adapter] update pageViewId test

* [sspbc-adapter] add viewabiility tracker to native ads

* [sspbc-adapter] add support for bid.admNative property

* [sspbc-adapter] ensure that placement id length is always 3 (improves matching response to request)

* [sspbc-adapter] read publisher id and custom ad label, then send them to banner creative

* [sspbc-adapter] adlabel and pubid are set as empty strings, if not present in bid response

* [sspbc-adapter] jstracker data fix

* [sspbc-adapter] jstracker data fix

* [sspbc-adapter] send tagid in notifications

* [sspbc-adapter] add gvlid to spec; prepare getUserSyncs for iframe + image sync

* update remote repo

* cleanup of grupawp/prebid master branch

* update sspBC adapter to v 5.9

* update tests for sspBC bid adapter

* [sspbc-adapter] add support for topicsFPD module

* [sspbc-adapter] change topic segment ids to int

* sspbc adapter -> update to v6

* bugfix proposal - using isActivityAllowed to build per-bidder syncOptions

* Fix preexisting tests

* Use canBidderRegisterSync

---------

Co-authored-by: Wojciech Biały <[email protected]>
Co-authored-by: decemberWP <[email protected]>
Co-authored-by: Demetrio Girardi <[email protected]>
  • Loading branch information
4 people authored and Miguel Morales committed Jan 14, 2025
1 parent 406fac0 commit 3e88a0b
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 49 deletions.
13 changes: 7 additions & 6 deletions src/adapters/bidderFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ import {createBid} from '../bidfactory.js';
import {userSync} from '../userSync.js';
import {nativeBidIsValid} from '../native.js';
import {isValidVideoBid} from '../video.js';
import { EVENTS, STATUS, REJECTION_REASON } from '../constants.js';
import {EVENTS, REJECTION_REASON, STATUS} from '../constants.js';
import * as events from '../events.js';
import {includes} from '../polyfill.js';
import {
delayExecution,
isArray,
isPlainObject,
logError,
logWarn, memoize,
logWarn,
memoize,
parseQueryStringParameters,
parseSizesInput, pick,
parseSizesInput,
pick,
uniques
} from '../utils.js';
import {hook} from '../hook.js';
Expand Down Expand Up @@ -523,10 +525,9 @@ export const processBidderRequests = hook('sync', function (spec, bids, bidderRe
export const registerSyncInner = hook('async', function(spec, responses, gdprConsent, uspConsent, gppConsent) {
const aliasSyncEnabled = config.getConfig('userSync.aliasSyncEnabled');
if (spec.getUserSyncs && (aliasSyncEnabled || !adapterManager.aliasRegistry[spec.code])) {
let filterConfig = config.getConfig('userSync.filterSettings');
let syncs = spec.getUserSyncs({
iframeEnabled: !!(filterConfig && (filterConfig.iframe || filterConfig.all)),
pixelEnabled: !!(filterConfig && (filterConfig.image || filterConfig.all)),
iframeEnabled: userSync.canBidderRegisterSync('iframe', spec.code),
pixelEnabled: userSync.canBidderRegisterSync('image', spec.code),
}, responses, gdprConsent, uspConsent, gppConsent);
if (syncs) {
if (!Array.isArray(syncs)) {
Expand Down
163 changes: 120 additions & 43 deletions test/spec/unit/core/bidderFactory_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,53 +91,130 @@ describe('bidderFactory', () => {
sandbox.restore();
});

it('should let registerSyncs run with invalid alias and aliasSync enabled', function () {
config.setConfig({
userSync: {
aliasSyncEnabled: true
}
});
spec.code = 'fakeBidder';
const bidder = newBidder(spec);
bidder.callBids({ bids: [] }, addBidResponseStub, doneStub, ajaxStub, onTimelyResponseStub, wrappedCallback);
expect(getConfigSpy.withArgs('userSync.filterSettings').calledOnce).to.equal(true);
});

it('should let registerSyncs run with valid alias and aliasSync enabled', function () {
config.setConfig({
userSync: {
aliasSyncEnabled: true
describe('user syncs', () => {
[
{
t: 'invalid alias, aliasSync enabled',
alias: false,
aliasSyncEnabled: true,
shouldRegister: true
},
{
t: 'valid alias, aliasSync enabled',
alias: true,
aliasSyncEnabled: true,
shouldRegister: true
},
{
t: 'invalid alias, aliasSync disabled',
alias: false,
aliasSyncEnabled: false,
shouldRegister: true,
},
{
t: 'valid alias, aliasSync disabled',
alias: true,
aliasSyncEnabled: false,
shouldRegister: false
}
].forEach(({t, alias, aliasSyncEnabled, shouldRegister}) => {
describe(t, () => {
it(shouldRegister ? 'should register sync' : 'should NOT register sync', () => {
config.setConfig({
userSync: {
aliasSyncEnabled
}
});
spec.code = 'someBidder';
if (alias) {
aliasRegistry[spec.code] = 'original';
}
const bidder = newBidder(spec);
bidder.callBids({ bids: [] }, addBidResponseStub, doneStub, ajaxStub, onTimelyResponseStub, wrappedCallback);
if (shouldRegister) {
sinon.assert.called(spec.getUserSyncs);
} else {
sinon.assert.notCalled(spec.getUserSyncs);
}
});
});
});
spec.code = 'aliasBidder';
const bidder = newBidder(spec);
bidder.callBids({ bids: [] }, addBidResponseStub, doneStub, ajaxStub, onTimelyResponseStub, wrappedCallback);
expect(getConfigSpy.withArgs('userSync.filterSettings').calledOnce).to.equal(true);
});

it('should let registerSyncs run with invalid alias and aliasSync disabled', function () {
config.setConfig({
userSync: {
aliasSyncEnabled: false
}
});
spec.code = 'fakeBidder';
const bidder = newBidder(spec);
bidder.callBids({ bids: [] }, addBidResponseStub, doneStub, ajaxStub, onTimelyResponseStub, wrappedCallback);
expect(getConfigSpy.withArgs('userSync.filterSettings').calledOnce).to.equal(true);
});
describe('getUserSyncs syncOptions', () => {
[
{
t: 'all image allowed, specific bidder denied iframe',
userSync: {
syncEnabled: true,
pixelEnabled: true,
iframeEnabled: true,
filterSettings: {
image: {
bidders: '*',
filter: 'include'
},
iframe: {
bidders: ['bidderB'],
filter: 'include'
}
}
},
expected: {
bidderA: {
iframeEnabled: false,
pixelEnabled: true
},
bidderB: {
iframeEnabled: true,
pixelEnabled: true,
}
}
},
{
t: 'specific bidders allowed specific methods',
userSync: {
syncEnabled: true,
pixelEnabled: true,
iframeEnabled: true,
filterSettings: {
image: {
bidders: ['bidderA'],
filter: 'include'
},
iframe: {
bidders: ['bidderB'],
filter: 'include'
}
},
},
expected: {
bidderA: {
iframeEnabled: false,
pixelEnabled: true
},
bidderB: {
iframeEnabled: true,
pixelEnabled: false,
}
}
}
].forEach(({t, userSync, expected}) => {
describe(`when ${t}`, () => {
beforeEach(() => {
config.setConfig({userSync});
});

it('should not let registerSyncs run with valid alias and aliasSync disabled', function () {
config.setConfig({
userSync: {
aliasSyncEnabled: false
}
});
spec.code = 'aliasBidder';
const bidder = newBidder(spec);
aliasRegistry = {[spec.code]: CODE};
bidder.callBids({ bids: [] }, addBidResponseStub, doneStub, ajaxStub, onTimelyResponseStub, wrappedCallback);
expect(getConfigSpy.withArgs('userSync.filterSettings').calledOnce).to.equal(false);
Object.entries(expected).forEach(([bidderCode, syncOptions]) => {
it(`should pass ${JSON.stringify(syncOptions)} to ${bidderCode}`, () => {
spec.code = bidderCode;
const bidder = newBidder(spec);
bidder.callBids({ bids: [] }, addBidResponseStub, doneStub, ajaxStub, onTimelyResponseStub, wrappedCallback);
sinon.assert.calledWith(spec.getUserSyncs, syncOptions);
})
})
})
})
})
});

describe('transaction IDs', () => {
Expand Down

0 comments on commit 3e88a0b

Please sign in to comment.