Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

floorProvider can come from data obj now #5559

Merged
merged 1 commit into from
Aug 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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