Skip to content

Commit

Permalink
Appnexus Bid Adapter: add support for ast_override_div debug feature (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
astartsky authored Apr 26, 2024
1 parent 6c0648b commit 4deba89
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
12 changes: 12 additions & 0 deletions modules/appnexusBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,18 @@ function bidToTag(bid) {
} else {
tag.code = bid.params.inv_code;
}
// Xandr expects GET variable to be in a following format:
// page.html?ast_override_div=divId:creativeId,divId2:creativeId2
const overrides = getParameterByName('ast_override_div');
if (isStr(overrides) && overrides !== '') {
const adUnitOverride = overrides.split(',').find((pair) => pair.startsWith(`${bid.adUnitCode}:`));
if (adUnitOverride) {
const forceCreativeId = adUnitOverride.split(':')[1];
if (forceCreativeId) {
tag.force_creative_id = parseInt(forceCreativeId, 10);
}
}
}
tag.allow_smaller_sizes = bid.params.allow_smaller_sizes || false;
tag.use_pmt_rule = (typeof bid.params.use_payment_rule === 'boolean') ? bid.params.use_payment_rule
: (typeof bid.params.use_pmt_rule === 'boolean') ? bid.params.use_pmt_rule : false;
Expand Down
82 changes: 82 additions & 0 deletions test/spec/modules/appnexusBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,88 @@ describe('AppNexusAdapter', function () {
config.getConfig.restore();
});

describe('ast_override_div', function () {
let getParamStub;
let bidRequest = Object.assign({}, bidRequests[0]);
let bidRequest2 = deepClone(bidRequests[0]);
bidRequest2.adUnitCode = 'adUnit_code_2';
let bidRequest3 = deepClone(bidRequests[0]);
bidRequest3.adUnitCode = 'adUnit_code_3';

before(function () {
getParamStub = sinon.stub(utils, 'getParameterByName');
});

it('should set forced creative id if one adUnitCode passed', function () {
getParamStub.callsFake(function(par) {
if (par === 'ast_override_div') return 'adunit-code:1234';
return '';
});

const request = spec.buildRequests([bidRequest, bidRequest2]);
const payload = JSON.parse(request.data);

expect(payload.tags[0].force_creative_id).to.deep.equal(1234);
expect(payload.tags[1].force_creative_id).to.not.exist;
});

it('should set forced creative id if `ast_override_div` is set to override multiple adUnitCode', function () {
getParamStub.callsFake(function(par) {
if (par === 'ast_override_div') return 'adunit-code:1234,adUnit_code_2:5678';
return '';
});

const request = spec.buildRequests([bidRequest, bidRequest2, bidRequest3]);
const payload = JSON.parse(request.data);

expect(payload.tags[0].force_creative_id).to.deep.equal(1234);
expect(payload.tags[1].force_creative_id).to.deep.equal(5678);
expect(payload.tags[2].force_creative_id).to.not.exist;
});

it('should not set forced creative id if `ast_override_div` is missing creativeId', function () {
getParamStub.callsFake(function(par) {
if (par === 'ast_override_div') return 'adunit-code';
return '';
});

const request = spec.buildRequests([bidRequest, bidRequest2]);
const payload = JSON.parse(request.data);

expect(payload.tags[0].force_creative_id).to.not.exist;
expect(payload.tags[1].force_creative_id).to.not.exist;
});

it('should not set forced creative id if `ast_override_div` is in the wrong format', function () {
getParamStub.callsFake(function(par) {
if (par === 'ast_override_div') return 'adunit-code;adUnit_code_2:5678';
return '';
}); ;

const request = spec.buildRequests([bidRequest, bidRequest2]);
const payload = JSON.parse(request.data);

expect(payload.tags[0].force_creative_id).to.not.exist;
expect(payload.tags[1].force_creative_id).to.not.exist;
});

it('should not set forced creative id if `ast_override_div` is missing', function () {
getParamStub.callsFake(function(par) {
return '';
}); ;

const request = spec.buildRequests([bidRequest, bidRequest2]);
const payload = JSON.parse(request.data);

expect(payload.tags[0].force_creative_id).to.not.exist;
expect(payload.tags[1].force_creative_id).to.not.exist;
});

after(function () {
getParamStub.restore();
});
});

it('should set the X-Is-Test customHeader if test flag is enabled', function () {
let bidRequest = Object.assign({}, bidRequests[0]);
sinon.stub(config, 'getConfig')
Expand Down

0 comments on commit 4deba89

Please sign in to comment.