Skip to content

Commit

Permalink
fix bugs and tests for prebid-server native
Browse files Browse the repository at this point in the history
  • Loading branch information
snapwich committed Jul 23, 2019
1 parent 45441eb commit 61589da
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 66 deletions.
22 changes: 12 additions & 10 deletions modules/prebidServerBidAdapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -799,16 +799,18 @@ const OPEN_RTB_PROTOCOL = {
[nativeEventTrackerMethodMap.img]: adm.imptrackers || [],
[nativeEventTrackerMethodMap.js]: adm.jstracker ? [adm.jstracker] : []
};
adm.eventtrackers.forEach(tracker => {
switch (tracker.method) {
case nativeEventTrackerMethodMap.img:
trackers[nativeEventTrackerMethodMap.img].push(tracker.url);
break;
case nativeEventTrackerMethodMap.js:
trackers[nativeEventTrackerMethodMap.js].push(tracker.url);
break;
}
});
if (adm.eventtrackers) {
adm.eventtrackers.forEach(tracker => {
switch (tracker.method) {
case nativeEventTrackerMethodMap.img:
trackers[nativeEventTrackerMethodMap.img].push(tracker.url);
break;
case nativeEventTrackerMethodMap.js:
trackers[nativeEventTrackerMethodMap.js].push(tracker.url);
break;
}
});
}

if (utils.isPlainObject(adm) && Array.isArray(adm.assets)) {
let origAssets = nativeAssetCache[bidRequest.adUnitCode];
Expand Down
132 changes: 76 additions & 56 deletions test/spec/modules/prebidServerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,17 @@ const REQUEST = {
'sizes': [[ 300, 250 ], [ 300, 300 ]]
},
'native': {
'image': {
'title': {
'required': true,
'sizes': [1, 1]
'len': 800
},
'title': {
'image': {
'required': true,
'len': 80
'sizes': [989, 742],
},
'sponsoredBy': {
'required': true
},
'clickUrl': {
'required': true
},
'body': {
'required': false
},
'icon': {
'required': false,
'sizes': [1, 1]
},
}
}
},
'transactionId': '4ef956ad-fd83-406d-bd35-e4bb786ab86c',
Expand Down Expand Up @@ -411,45 +401,78 @@ const RESPONSE_OPENRTB_NATIVE = {
{
'bid': [
{
'id': '123',
'id': '6451317310275562039',
'impid': 'div-gpt-ad-1460505748561-0',
'price': 0.13,
'price': 10,
'adm': {
'ver': '1.2',
'assets': [
{
'title': {
'text': 'Prebid.js'
}
},
{
'id': 1,
'img': {
'type': 3,
'url': 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI4MCIgaGVpZ2h0PSIzMCI+PHRleHQgeD0iMTAiIHk9IjIwIj5QcmViaWQuanM8L3RleHQ+PC9zdmc+',
'w': 80,
'h': 30
'url': 'https://vcdn.adnxs.com/p/creative-image/f8/7f/0f/13/f87f0f13-230c-4f05-8087-db9216e393de.jpg',
'w': 989,
'h': 742,
'ext': {
'appnexus': {
'prevent_crop': 0
}
}
}
},
{
'data': {
'type': 1,
'value': 'Prebid.org'
'id': 0,
'title': {
'text': 'This is a Prebid Native Creative'
}
},
{
'id': 2,
'data': {
'type': 6,
'value': 'free'
'value': 'Prebid.org'
}
}
],
'link': {
'url': 'https://github.com/prebid/Prebid.js'
}
'url': 'https://lax1-ib.adnxs.com/click?AAAAAAAAJEAAAAAAAAAkQAAAAAAAACRAAAAAAAAAJEAAAAAAAAAkQGdce2vBWudAJZpFu1er1zA7ZzddAAAAAOLoyQBtJAAAbSQAAAIAAAC8pM8FnPgWAAAAAABVU0QAVVNEAAEAAQBNXQAAAAABAgMCAAAAALsAuhVqdgAAAAA./cpcpm=AAAAAAAAAAA=/bcr=AAAAAAAA8D8=/pp=${AUCTION_PRICE}/cnd=%213Q5HCQj8-LwKELzJvi4YnPFbIAQoADEAAAAAAAAkQDoJTEFYMTo0MDc3QKcPSQAAAAAAAPA_UQAAAAAAAAAAWQAAAAAAAAAAYQAAAAAAAAAAaQAAAAAAAAAAcQAAAAAAAAAA/cca=OTMyNSNMQVgxOjQwNzc=/bn=84305/test=1/clickenc=http%3A%2F%2Fprebid.org%2Fdev-docs%2Fshow-native-ads.html'
},
'eventtrackers': [
{
'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AwOABACSBAkvb3BlbnJ0YjKYBACiBA0xNzMuMjQ0LjM2LjQwqATtoySyBAwIABAAGAAgADAAOAC4BADABADIBADSBA45MzI1I0xBWDE6NDA3N9oEAggB4AQA8AS8yb4uiAUBmAUAoAX___________8BqgUkZTU5YzNlYjYtNmRkNi00MmQ5LWExMWEtM2FhMTFjOTc5MGUwwAUAyQUAAAAAAADwP9IFCQkAaVh0ANgFAeAFAfAFmfQh-gUECAAQAJAGAZgGALgGAMEGCSQk8D_IBgDaBhYKEAkQGQEBwTTgBgzyBgIIAIAHAYgHAA..&s=11ababa390e9f7983de260493fc5b91ec5b1b3d4&pp=${AUCTION_PRICE}'
}
]
},
'crid': '123',
'adid': '97494204',
'adomain': [
'http://prebid.org'
],
'iurl': 'https://lax1-ib.adnxs.com/cr?id=97494204',
'cid': '9325',
'crid': '97494204',
'cat': [
'IAB3-1'
],
'ext': {
'prebid': {
'type': 'native'
'targeting': {
'hb_bidder': 'appnexus',
'hb_pb': '10.00'
},
'type': 'native',
'video': {
'duration': 0,
'primary_category': ''
}
},
'bidder': {
'appnexus': {
'brand_id': 555545,
'auction_id': 4676806524825984103,
'bidder_id': 2,
'bid_ad_type': 3
}
}
}
}
Expand Down Expand Up @@ -783,40 +806,30 @@ describe('S2S Adapter', function () {
request: JSON.stringify({
'context': 1,
'plcmttype': 1,
'eventtrackers': [{
event: 1,
methods: [1]
}],
'assets': [
{
'required': 1,
'img': {
'type': 3,
'w': 1,
'h': 1
'title': {
'len': 800
}
},
{
'required': 1,
'title': {
'len': 80
'img': {
'type': 3,
'w': 989,
'h': 742
}
},
{
'required': 1,
'data': {
'type': 1
}
},
{
'required': 0,
'data': {
'type': 2
}
},
{
'required': 0,
'img': {
'type': 1,
'w': 1,
'h': 1
}
}
]
}),
Expand Down Expand Up @@ -1498,6 +1511,11 @@ describe('S2S Adapter', function () {
});

it('handles OpenRTB native responses', function () {
sinon.stub(utils, 'getBidRequest').returns({
adUnitCode: 'div-gpt-ad-1460505748561-0',
bidder: 'appnexus',
bidId: '123'
});
const s2sConfig = Object.assign({}, CONFIG, {
endpoint: 'https://prebidserverurl/openrtb2/auction?querystring=param'
});
Expand All @@ -1514,7 +1532,9 @@ describe('S2S Adapter', function () {
expect(response).to.have.property('mediaType', 'native');
expect(response).to.have.property('bidderCode', 'appnexus');
expect(response).to.have.property('requestId', '123');
expect(response).to.have.property('cpm', 0.13);
expect(response).to.have.property('cpm', 10);

utils.getBidRequest.restore();
});

it('should log warning for unsupported bidder', function () {
Expand Down

0 comments on commit 61589da

Please sign in to comment.