Skip to content

Commit

Permalink
[rtbhouse] Add schain support (prebid#5281)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamoris authored and iggyfisk committed Jun 22, 2020
1 parent ea672bf commit df5d714
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 3 deletions.
50 changes: 47 additions & 3 deletions modules/rtbhouseBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ export const spec = {
site: mapSite(validBidRequests, bidderRequest),
cur: DEFAULT_CURRENCY_ARR,
test: validBidRequests[0].params.test || 0,
source: {
tid: validBidRequests[0].transactionId
}
source: mapSource(validBidRequests[0]),
};
if (bidderRequest && bidderRequest.gdprConsent && bidderRequest.gdprConsent.gdprApplies) {
const consentStr = (bidderRequest.gdprConsent.consentString)
Expand Down Expand Up @@ -145,6 +143,52 @@ function mapSite(slot, bidderRequest) {
}
}

/**
* @param {object} slot Ad Unit Params by Prebid
* @returns {object} Source by OpenRTB 2.5 §3.2.2
*/
function mapSource(slot) {
const source = {
tid: slot.transactionId,
};
const schain = mapSchain(slot.schain);
if (schain) {
source.ext = {
schain: schain
}
}
return source;
}

/**
* @param {object} schain object set by Publisher
* @returns {object} OpenRTB SupplyChain object
*/
function mapSchain(schain) {
if (!schain) {
return null;
}
if (!validateSchain(schain)) {
utils.logError('RTB House: required schain params missing');
return null;
}
return schain;
}

/**
* @param {object} schain object set by Publisher
* @returns {object} bool
*/
function validateSchain(schain) {
if (!schain.nodes) {
return false;
}
const requiredFields = ['asi', 'sid', 'hp'];
return schain.nodes.every(node => {
return requiredFields.every(field => node[field]);
});
}

/**
* @param {object} slot Ad Unit Params by Prebid
* @returns {object} Request by OpenRTB Native Ads 1.1 §4
Expand Down
42 changes: 42 additions & 0 deletions test/spec/modules/rtbhouseBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ describe('RTBHouseAdapter', () => {
'bidderRequestId': '22edbae2733bf6',
'auctionId': '1d1a030790a475',
'transactionId': 'example-transaction-id',
'schain': {
'ver': '1.0',
'complete': 1,
'nodes': [
{
'asi': 'directseller.com',
'sid': '00001',
'rid': 'BidRequest1',
'hp': 1
}
]
}
}
];
const bidderRequest = {
Expand Down Expand Up @@ -173,6 +185,36 @@ describe('RTBHouseAdapter', () => {
expect(data.imp[0].bidfloor).to.equal(0.01)
});

it('should include source.ext.schain in request', () => {
const bidRequest = Object.assign([], bidRequests);
const request = spec.buildRequests(bidRequest, bidderRequest);
const data = JSON.parse(request.data);
expect(data.source.ext.schain).to.deep.equal({
'ver': '1.0',
'complete': 1,
'nodes': [
{
'asi': 'directseller.com',
'sid': '00001',
'rid': 'BidRequest1',
'hp': 1
}
]
});
});

it('should not include invalid schain', () => {
const bidRequest = Object.assign([], bidRequests);
bidRequest[0].schain = {
'nodes': [{
'unknown_key': 1
}]
};
const request = spec.buildRequests(bidRequest, bidderRequest);
const data = JSON.parse(request.data);
expect(data.source).to.not.have.property('ext');
});

describe('native imp', () => {
function basicRequest(extension) {
return Object.assign({
Expand Down

0 comments on commit df5d714

Please sign in to comment.