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

feat(OAFLO-186): added support for schain #4

Merged
merged 1 commit into from
Sep 16, 2019
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
19 changes: 18 additions & 1 deletion modules/openxBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {parse} from '../src/url';
const SUPPORTED_AD_TYPES = [BANNER, VIDEO];
const BIDDER_CODE = 'openx';
const BIDDER_CONFIG = 'hb_pb';
const BIDDER_VERSION = '2.1.7';
const BIDDER_VERSION = '2.1.9';

let shouldSendBoPixel = true;

Expand Down Expand Up @@ -243,9 +243,26 @@ function buildCommonQueryParamsFromBids(bids, bidderRequest) {
defaultParams.pubcid = bids[0].crumbs.pubcid;
}

if (bids[0].schain) {
defaultParams.schain = serializeSupplyChain(bids[0].schain);
}

return defaultParams;
}

function serializeSupplyChain(supplyChain) {
return `${supplyChain.ver},${supplyChain.complete}!${serializeSupplyChainNodes(supplyChain.nodes)}`;
}

function serializeSupplyChainNodes(supplyChainNodes) {
const supplyChainNodePropertyOrder = ['asi', 'sid', 'hp', 'rid', 'name', 'domain'];

return supplyChainNodes.map(supplyChainNode => {
return supplyChainNodePropertyOrder.map(property => supplyChainNode[property] || '')
.join(',');
}).join('!');
}

function buildOXBannerRequest(bids, bidderRequest) {
let customParamsForAllBids = [];
let hasCustomParam = false;
Expand Down
175 changes: 142 additions & 33 deletions test/spec/modules/openxBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,39 +394,6 @@ describe('OpenxAdapter', function () {
'bidderRequestId': 'test-bid-request-1',
'auctionId': 'test-auction-1'
}];
const bidRequestsWithPlatformAndDelDomain = [{
'bidder': 'openx',
'params': {
'unit': '11',
'delDomain': 'test-del-domain',
'platform': '1cabba9e-cafe-3665-beef-f00f00f00f00',
},
'adUnitCode': '/adunit-code/test-path',
mediaTypes: {
banner: {
sizes: [[300, 250], [300, 600]]
}
},
'bidId': 'test-bid-id-1',
'bidderRequestId': 'test-bid-request-1',
'auctionId': 'test-auction-1'
}, {
'bidder': 'openx',
'params': {
'unit': '11',
'delDomain': 'test-del-domain',
'platform': '1cabba9e-cafe-3665-beef-f00f00f00f00',
},
'adUnitCode': '/adunit-code/test-path',
mediaTypes: {
banner: {
sizes: [[300, 250], [300, 600]]
}
},
'bidId': 'test-bid-id-1',
'bidderRequestId': 'test-bid-request-1',
'auctionId': 'test-auction-1'
}];

it('should send bid request to openx url via GET, with mediaType specified as banner', function () {
const request = spec.buildRequests(bidRequestsWithMediaType);
Expand All @@ -450,6 +417,40 @@ describe('OpenxAdapter', function () {
});

it('should send bid request to openx platform url via GET, if both params present', function () {
const bidRequestsWithPlatformAndDelDomain = [{
'bidder': 'openx',
'params': {
'unit': '11',
'delDomain': 'test-del-domain',
'platform': '1cabba9e-cafe-3665-beef-f00f00f00f00',
},
'adUnitCode': '/adunit-code/test-path',
mediaTypes: {
banner: {
sizes: [[300, 250], [300, 600]]
}
},
'bidId': 'test-bid-id-1',
'bidderRequestId': 'test-bid-request-1',
'auctionId': 'test-auction-1'
}, {
'bidder': 'openx',
'params': {
'unit': '11',
'delDomain': 'test-del-domain',
'platform': '1cabba9e-cafe-3665-beef-f00f00f00f00',
},
'adUnitCode': '/adunit-code/test-path',
mediaTypes: {
banner: {
sizes: [[300, 250], [300, 600]]
}
},
'bidId': 'test-bid-id-1',
'bidderRequestId': 'test-bid-request-1',
'auctionId': 'test-auction-1'
}];

const request = spec.buildRequests(bidRequestsWithPlatformAndDelDomain);
expect(request[0].url).to.equal(`//u.openx.net${URLBASE}`);
expect(request[0].data.ph).to.equal(bidRequestsWithPlatform[0].params.platform);
Expand Down Expand Up @@ -1000,6 +1001,114 @@ describe('OpenxAdapter', function () {
expect(request[0].data.pubcid).to.equal('c1a4c843-2368-4b5e-b3b1-6ee4702b9ad6');
});
})

describe('when schain is provided', function () {
let bidRequests;
let schainConfig;
const supplyChainNodePropertyOrder = ['asi', 'sid', 'hp', 'rid', 'name', 'domain'];

beforeEach(function () {
schainConfig = {
'ver': '1.0',
'complete': 1,
'nodes': [
{
'asi': 'exchange1.com',
'sid': '1234',
'hp': 1,
'rid': 'bid-request-1',
'name': 'publisher',
'domain': 'publisher.com'
// omitted ext
},
{
'asi': 'exchange2.com',
'sid': 'abcd',
'hp': 1,
'rid': 'bid-request-2',
// name field missing
'domain': 'intermediary.com'
},
{
'asi': 'exchange3.com',
'sid': '4321',
'hp': 1,
// request id
// name field missing
'domain': 'intermediary-2.com'
}
]
};

bidRequests = [{
'bidder': 'openx',
'params': {
'unit': '11',
'delDomain': 'test-del-domain'
},
'adUnitCode': '/adunit-code/test-path',
mediaTypes: {
banner: {
sizes: [[300, 250], [300, 600]]
}
},
'bidId': 'test-bid-id-1',
'bidderRequestId': 'test-bid-request-1',
'auctionId': 'test-auction-1',
'schain': schainConfig
}];
});

it('should send a schain parameter with the proper delimiter symbols', function () {
const request = spec.buildRequests(bidRequests);
const dataParams = request[0].data;
const numNodes = schainConfig.nodes.length;

// each node will have a ! to denote beginning of a new node
expect(dataParams.schain.match(/!/g).length).to.equal(numNodes);

// 1 comma in the front for version
// 5 commas per node
expect(dataParams.schain.match(/,/g).length).to.equal(numNodes * 5 + 1);
});

it('should send a schain with the right version', function () {
const request = spec.buildRequests(bidRequests);
const dataParams = request[0].data;
let serializedSupplyChain = dataParams.schain.split('!');
let version = serializedSupplyChain.shift().split(',')[0];

expect(version).to.equal(bidRequests[0].schain.ver);
});

it('should send a schain with the right complete value', function () {
const request = spec.buildRequests(bidRequests);
const dataParams = request[0].data;
let serializedSupplyChain = dataParams.schain.split('!');
let isComplete = serializedSupplyChain.shift().split(',')[1];

expect(isComplete).to.equal(String(bidRequests[0].schain.complete));
});

it('should send all available params in the right order', function () {
const request = spec.buildRequests(bidRequests);
const dataParams = request[0].data;
let serializedSupplyChain = dataParams.schain.split('!');
serializedSupplyChain.shift();

serializedSupplyChain.forEach((serializedNode, nodeIndex) => {
let nodeProperties = serializedNode.split(',');

nodeProperties.forEach((nodeProperty, propertyIndex) => {
let node = schainConfig.nodes[nodeIndex];
let key = supplyChainNodePropertyOrder[propertyIndex];

expect(nodeProperty).to.equal(node[key] ? String(node[key]) : '',
`expected node '${nodeIndex}' property '${nodeProperty}' to key '${key}' to be the same value`)
});
});
});
});
});

describe('buildRequests for video', function () {
Expand Down