Skip to content

Commit

Permalink
handle native response privacy link (#8838)
Browse files Browse the repository at this point in the history
Co-authored-by: Zicong Zhou <[email protected]>
  • Loading branch information
lksharma and Zicong Zhou authored Aug 18, 2022
1 parent 94d34d1 commit 940339a
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/native.js
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ function toLegacyResponse(ortbResponse, ortbRequest) {
const legacyResponse = {};
const requestAssets = ortbRequest?.assets || [];
legacyResponse.clickUrl = ortbResponse.link.url;
legacyResponse.privacyLink = ortbResponse.privacy;
for (const asset of ortbResponse?.assets || []) {
const requestAsset = requestAssets.find(reqAsset => asset.id === reqAsset.id);
if (asset.title) {
Expand Down
144 changes: 144 additions & 0 deletions test/spec/native_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,106 @@ const bid = {
},
};

const ortbBid = {
adId: '123',
transactionId: 'au',
native: {
ortb: {
assets: [
{
id: 0,
title: {
text: 'Native Creative'
}
},
{
id: 1,
data: {
value: 'Cool description great stuff'
}
},
{
id: 2,
data: {
value: 'Do it'
}
},
{
id: 3,
img: {
url: 'http://cdn.example.com/p/creative-image/image.png',
h: 83,
w: 127
}
},
{
id: 4,
img: {
url: 'http://cdn.example.com/p/creative-image/icon.jpg',
h: 742,
w: 989
}
},
{
id: 5,
data: {
value: 'AppNexus',
type: 1
}
}
],
link: {
url: 'https://www.link.example'
},
privacy: 'https://privacy-link.example',
ver: '1.2'
}
},
};

const ortbRequest = {
assets: [
{
id: 0,
required: 0,
title: {
len: 140
}
}, {
id: 1,
required: 0,
data: {
type: 2
}
}, {
id: 2,
required: 0,
data: {
type: 12
}
}, {
id: 3,
required: 0,
img: {
type: 3
}
}, {
id: 4,
required: 0,
img: {
type: 1
}
}, {
id: 5,
required: 0,
data: {
type: 1
}
}
],
ver: '1.2'
}

const bidWithUndefinedFields = {
transactionId: 'au',
native: {
Expand Down Expand Up @@ -401,6 +501,50 @@ describe('native.js', function () {
});
});

it('creates native all asset message with OpenRTB format', function () {
const messageRequest = {
message: 'Prebid Native',
action: 'allAssetRequest',
adId: '123',
};

const message = getAllAssetsMessage(messageRequest, ortbBid, {getNativeReq: () => ortbRequest});

expect(message.assets.length).to.equal(8);
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,
});
expect(message.assets).to.deep.include({
key: 'title',
value: bid.native.title,
});
expect(message.assets).to.deep.include({
key: 'icon',
value: bid.native.icon.url,
});
expect(message.assets).to.deep.include({
key: 'cta',
value: bid.native.cta,
});
expect(message.assets).to.deep.include({
key: 'sponsoredBy',
value: bid.native.sponsoredBy,
});
expect(message.assets).to.deep.include({
key: 'privacyLink',
value: ortbBid.native.ortb.privacy,
});
});

const SAMPLE_ORTB_REQUEST = toOrtbNativeRequest({
title: 'vtitle',
body: 'vbody'
Expand Down

0 comments on commit 940339a

Please sign in to comment.