Skip to content

Commit

Permalink
floorProvider can come from data obj now (#5559)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertrmartinez committed Aug 4, 2020
1 parent b4b77af commit 609da19
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
3 changes: 2 additions & 1 deletion modules/priceFloors.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ export function handleFetchResponse(fetchResponse) {
_floorsConfig.data = fetchData;
// set skipRate override if necessary
_floorsConfig.skipRate = utils.isNumber(fetchData.skipRate) ? fetchData.skipRate : _floorsConfig.skipRate;
_floorsConfig.floorProvider = fetchData.floorProvider || _floorsConfig.floorProvider;
}

// if any auctions are waiting for fetch to finish, we need to continue them!
Expand Down Expand Up @@ -569,7 +570,7 @@ export function handleSetFloorsConfig(config) {
_floorsConfig = utils.pick(config, [
'enabled', enabled => enabled !== false, // defaults to true
'auctionDelay', auctionDelay => auctionDelay || 0,
'floorProvider',
'floorProvider', floorProvider => utils.deepAccess(config, 'data.floorProvider', floorProvider),
'endpoint', endpoint => endpoint || {},
'skipRate', () => !isNaN(utils.deepAccess(config, 'data.skipRate')) ? config.data.skipRate : config.skipRate || 0,
'enforcement', enforcement => utils.pick(enforcement || {}, [
Expand Down
82 changes: 82 additions & 0 deletions test/spec/modules/priceFloors_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,52 @@ describe('the price floors module', function () {
floorProvider: 'floorprovider'
});
});
it('should pick the right floorProvider', function () {
let inputFloors = {
...basicFloorConfig,
floorProvider: 'providerA',
data: {
...basicFloorData,
floorProvider: 'providerB',
}
};
handleSetFloorsConfig(inputFloors);
runStandardAuction();
validateBidRequests(true, {
skipped: false,
modelVersion: 'basic model',
location: 'setConfig',
skipRate: 0,
fetchStatus: undefined,
floorProvider: 'providerB'
});

// if not at data level take top level
delete inputFloors.data.floorProvider;
handleSetFloorsConfig(inputFloors);
runStandardAuction();
validateBidRequests(true, {
skipped: false,
modelVersion: 'basic model',
location: 'setConfig',
skipRate: 0,
fetchStatus: undefined,
floorProvider: 'providerA'
});

// if none should be undefined
delete inputFloors.floorProvider;
handleSetFloorsConfig(inputFloors);
runStandardAuction();
validateBidRequests(true, {
skipped: false,
modelVersion: 'basic model',
location: 'setConfig',
skipRate: 0,
fetchStatus: undefined,
floorProvider: undefined
});
});
it('should take the right skipRate depending on input', function () {
// first priority is data object
sandbox.stub(Math, 'random').callsFake(() => 0.99);
Expand Down Expand Up @@ -643,6 +689,42 @@ describe('the price floors module', function () {
floorProvider: 'floorprovider'
});
});
it('it should correctly overwrite floorProvider with fetch provider', function () {
// init the fake server with response stuff
let fetchFloorData = {
...basicFloorData,
floorProvider: 'floorProviderD', // change the floor provider
modelVersion: 'fetch model name', // change the model name
};
fakeFloorProvider.respondWith(JSON.stringify(fetchFloorData));

// run setConfig indicating fetch
handleSetFloorsConfig({...basicFloorConfig, floorProvider: 'floorproviderC', auctionDelay: 250, endpoint: {url: 'http://www.fakeFloorProvider.json'}});

// floor provider should be called
expect(fakeFloorProvider.requests.length).to.equal(1);
expect(fakeFloorProvider.requests[0].url).to.equal('http://www.fakeFloorProvider.json');

// start the auction it should delay and not immediately call `continueAuction`
runStandardAuction();

// exposedAdUnits should be undefined if the auction has not continued
expect(exposedAdUnits).to.be.undefined;

// make the fetch respond
fakeFloorProvider.respond();

// the exposedAdUnits should be from the fetch not setConfig level data
// and fetchStatus is success since fetch worked
validateBidRequests(true, {
skipped: false,
modelVersion: 'fetch model name',
location: 'fetch',
skipRate: 0,
fetchStatus: 'success',
floorProvider: 'floorProviderD'
});
});
it('it should correctly overwrite skipRate with fetch skipRate', function () {
// so floors does not skip
sandbox.stub(Math, 'random').callsFake(() => 0.99);
Expand Down

0 comments on commit 609da19

Please sign in to comment.