Skip to content

Commit

Permalink
Price floors module: expand on bug fix with custom priceFloor schemas…
Browse files Browse the repository at this point in the history
… tests (#8027)

* fix(priceFloors): retrieve matching bid request

* Make default fieldMatchingFunctions work without request; add unit tests

* Make default fieldMatchingFunctions work without request; add unit tests

Co-authored-by: Julie <julie@hubvisor.io>
  • Loading branch information
dgirardi and JulieLorin authored Feb 8, 2022
1 parent dc4ab54 commit 6317dc3
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
8 changes: 6 additions & 2 deletions modules/priceFloors.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,19 @@ function getGptSlotFromAdUnit(transactionId, {index = auctionManager.index} = {}
return isGam && adUnit.ortb2Imp.ext.data.adserver.adslot;
}

function getAdUnitCode(request, response, {index = auctionManager.index} = {}) {
return request?.adUnitCode || index.getAdUnit(response).code;
}

/**
* @summary floor field types with their matching functions to resolve the actual matched value
*/
export let fieldMatchingFunctions = {
'size': (bidRequest, bidResponse) => parseGPTSingleSizeArray(bidResponse.size) || '*',
'mediaType': (bidRequest, bidResponse) => bidResponse.mediaType || 'banner',
'gptSlot': (bidRequest, bidResponse) => getGptSlotFromAdUnit((bidRequest || bidResponse).transactionId) || getGptSlotInfoForAdUnitCode((bidRequest || bidResponse).adUnitCode).gptSlot,
'gptSlot': (bidRequest, bidResponse) => getGptSlotFromAdUnit((bidRequest || bidResponse).transactionId) || getGptSlotInfoForAdUnitCode(getAdUnitCode(bidRequest, bidResponse)).gptSlot,
'domain': (bidRequest, bidResponse) => referrerHostname || getHostNameFromReferer(getRefererInfo().referer),
'adUnitCode': (bidRequest, bidResponse) => (bidRequest || bidResponse).adUnitCode
'adUnitCode': (bidRequest, bidResponse) => getAdUnitCode(bidRequest, bidResponse)
}

/**
Expand Down
46 changes: 46 additions & 0 deletions test/spec/modules/priceFloors_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ describe('the price floors module', function () {
bidder: 'rubicon',
adUnitCode: 'test_div_1',
auctionId: '1234-56-789',
transactionId: 'tr_test_div_1'
};

function getAdUnitMock(code = 'adUnit-code') {
Expand Down Expand Up @@ -1735,4 +1736,49 @@ describe('the price floors module', function () {
expect(_floorDataForAuction[AUCTION_END_EVENT.auctionId]).to.be.undefined;
});
});

describe('fieldMatchingFunctions', () => {
let sandbox;

const req = {
...basicBidRequest,
}

const resp = {
transactionId: req.transactionId,
size: [100, 100],
mediaType: 'banner',
}

beforeEach(() => {
sandbox = sinon.sandbox.create();
sandbox.stub(auctionManager, 'index').get(() => stubAuctionIndex({
adUnits: [
{
code: req.adUnitCode,
transactionId: req.transactionId,
ortb2Imp: {ext: {data: {adserver: {name: 'gam', adslot: 'slot'}}}}
}
]
}));
});

afterEach(() => {
sandbox.restore();
})

Object.entries({
size: '100x100',
mediaType: resp.mediaType,
gptSlot: 'slot',
domain: 'localhost',
adUnitCode: req.adUnitCode,
}).forEach(([test, expected]) => {
describe(`${test}`, () => {
it('should work with only bidResponse', () => {
expect(fieldMatchingFunctions[test](undefined, resp)).to.eql(expected)
})
});
})
});
});

0 comments on commit 6317dc3

Please sign in to comment.