Skip to content

Commit 7dd9f8a

Browse files
authored
add default sizes value for appnexus native requests (prebid#3602)
1 parent 9868bc3 commit 7dd9f8a

File tree

3 files changed

+107
-1
lines changed

3 files changed

+107
-1
lines changed

modules/appnexusBidAdapter.js

+3
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,9 @@ function bidToTag(bid) {
508508

509509
if (bid.mediaType === NATIVE || utils.deepAccess(bid, `mediaTypes.${NATIVE}`)) {
510510
tag.ad_types.push(NATIVE);
511+
if (tag.sizes.length === 0) {
512+
tag.sizes = transformSizes([1, 1]);
513+
}
511514

512515
if (bid.nativeParams) {
513516
const nativeRequest = buildNativeRequest(bid.nativeParams);

test/spec/modules/appnexusBidAdapter_spec.js

+24
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,30 @@ describe('AppNexusAdapter', function () {
443443
});
444444
});
445445

446+
it('should always populated tags[].sizes with 1,1 for native if otherwise not defined', function () {
447+
let bidRequest = Object.assign({},
448+
bidRequests[0],
449+
{
450+
mediaType: 'native',
451+
nativeParams: {
452+
image: { required: true }
453+
}
454+
}
455+
);
456+
bidRequest.sizes = [[150, 100], [300, 250]];
457+
458+
let request = spec.buildRequests([bidRequest]);
459+
let payload = JSON.parse(request.data);
460+
expect(payload.tags[0].sizes).to.deep.equal([{width: 150, height: 100}, {width: 300, height: 250}]);
461+
462+
delete bidRequest.sizes;
463+
464+
request = spec.buildRequests([bidRequest]);
465+
payload = JSON.parse(request.data);
466+
467+
expect(payload.tags[0].sizes).to.deep.equal([{width: 1, height: 1}]);
468+
});
469+
446470
it('should convert keyword params to proper form and attaches to request', function () {
447471
let bidRequest = Object.assign({},
448472
bidRequests[0],

test/spec/unit/core/adapterManager_spec.js

+80-1
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ describe('adapterManager tests', function () {
913913
setSizeConfig([]);
914914
});
915915

916-
it('should not filter bids w/ no labels', function () {
916+
it('should not filter banner bids w/ no labels', function () {
917917
let bidRequests = adapterManager.makeBidRequests(
918918
adUnits,
919919
Date.now(),
@@ -933,6 +933,85 @@ describe('adapterManager tests', function () {
933933
expect(appnexusBidRequests.bids[1].sizes).to.deep.equal(find(adUnits, adUnit => adUnit.code === appnexusBidRequests.bids[1].adUnitCode).sizes);
934934
});
935935

936+
it('should not filter video bids', function () {
937+
setSizeConfig([{
938+
'mediaQuery': '(min-width: 768px) and (max-width: 1199px)',
939+
'sizesSupported': [
940+
[728, 90],
941+
[300, 250]
942+
],
943+
'labels': ['tablet', 'phone']
944+
}]);
945+
946+
let videoAdUnits = [{
947+
code: 'test_video',
948+
mediaTypes: {
949+
video: {
950+
playerSize: [300, 300],
951+
context: 'outstream'
952+
}
953+
},
954+
bids: [{
955+
bidder: 'appnexus',
956+
params: {
957+
placementId: 13232385,
958+
video: {
959+
skippable: true,
960+
playback_method: ['auto_play_sound_off']
961+
}
962+
}
963+
}]
964+
}];
965+
let bidRequests = adapterManager.makeBidRequests(
966+
videoAdUnits,
967+
Date.now(),
968+
utils.getUniqueIdentifierStr(),
969+
function callback() {},
970+
[]
971+
);
972+
expect(bidRequests[0].bids[0].sizes).to.deep.equal([300, 300]);
973+
});
974+
975+
it('should not filter native bids', function () {
976+
setSizeConfig([{
977+
'mediaQuery': '(min-width: 768px) and (max-width: 1199px)',
978+
'sizesSupported': [
979+
[728, 90],
980+
[300, 250]
981+
],
982+
'labels': ['tablet', 'phone']
983+
}]);
984+
985+
let nativeAdUnits = [{
986+
code: 'test_native',
987+
sizes: [[1, 1]],
988+
mediaTypes: {
989+
native: {
990+
title: { required: true },
991+
body: { required: false },
992+
image: { required: true },
993+
icon: { required: false },
994+
sponsoredBy: { required: true },
995+
clickUrl: { required: true },
996+
},
997+
},
998+
bids: [
999+
{
1000+
bidder: 'appnexus',
1001+
params: { placementId: 13232354 }
1002+
},
1003+
]
1004+
}];
1005+
let bidRequests = adapterManager.makeBidRequests(
1006+
nativeAdUnits,
1007+
Date.now(),
1008+
utils.getUniqueIdentifierStr(),
1009+
function callback() {},
1010+
[]
1011+
);
1012+
expect(bidRequests[0].bids[0].sizes).to.deep.equal([]);
1013+
});
1014+
9361015
it('should filter sizes using size config', function () {
9371016
let validSizes = [
9381017
[728, 90],

0 commit comments

Comments
 (0)