Skip to content

Commit

Permalink
Send url value when replacing image and icons types (prebid#3609)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewlane authored and jsnellbaker committed Mar 5, 2019
1 parent 7dd9f8a commit 1a4c964
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
21 changes: 14 additions & 7 deletions src/native.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,7 @@ export function getNativeTargeting(bid, bidReq) {

Object.keys(bid['native']).forEach(asset => {
const key = CONSTANTS.NATIVE_KEYS[asset];
let value = bid['native'][asset];

// native image-type assets can be a string or an object with a url prop
if (typeof value === 'object' && value.url) {
value = value.url;
}
let value = getAssetValue(bid['native'][asset]);

const sendPlaceholder = deepAccess(
bidReq,
Expand Down Expand Up @@ -195,10 +190,22 @@ export function getAssetMessage(data, adObject) {

data.assets.forEach(asset => {
const key = getKeyByValue(CONSTANTS.NATIVE_KEYS, asset);
const value = adObject.native[key];
const value = getAssetValue(adObject.native[key]);

message.assets.push({ key, value });
});

return message;
}

/**
* Native assets can be a string or an object with a url prop. Returns the value
* appropriate for sending in adserver targeting or placeholder replacement.
*/
function getAssetValue(value) {
if (typeof value === 'object' && value.url) {
return value.url;
}

return value;
}
18 changes: 16 additions & 2 deletions test/spec/native_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ const bid = {
title: 'Native Creative',
body: 'Cool description great stuff',
cta: 'Do it',
image: {
url: 'http://cdn.example.com/p/creative-image/image.png',
height: 83,
width: 127
},
icon: {
url: 'http://cdn.example.com/p/creative-image/icon.jpg',
height: 742,
width: 989
},
sponsoredBy: 'AppNexus',
clickUrl: 'https://www.link.example',
clickTrackers: ['https://tracker.example'],
Expand Down Expand Up @@ -96,16 +106,20 @@ describe('native.js', function () {
message: 'Prebid Native',
action: 'assetRequest',
adId: '123',
assets: ['hb_native_body', 'hb_native_linkurl'],
assets: ['hb_native_body', 'hb_native_image', 'hb_native_linkurl'],
};

const message = getAssetMessage(messageRequest, bid);

expect(message.assets.length).to.equal(2);
expect(message.assets.length).to.equal(3);
expect(message.assets).to.deep.include({
key: 'body',
value: bid.native.body
});
expect(message.assets).to.deep.include({
key: 'image',
value: bid.native.image.url
});
expect(message.assets).to.deep.include({
key: 'clickUrl',
value: bid.native.clickUrl
Expand Down

0 comments on commit 1a4c964

Please sign in to comment.