Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YieldlabBidAdapter updated native asset mapping #9989

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions modules/yieldlabBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,21 @@ export const spec = {
// there may be publishers still rely on it
nkloeber marked this conversation as resolved.
Show resolved Hide resolved
bidResponse.adUrl = `${ENDPOINT}/d/${matchedBid.id}/${bidRequest.params.supplyId}/?ts=${timestamp}${extId}${gdprApplies}${gdprConsent}${pvId}`;
bidResponse.mediaType = NATIVE;
const nativeImageAssetObj = find(matchedBid.native.assets, asset => isMainImage(asset));
const nativeIconAssetObj = find(matchedBid.native.assets, asset => isImageAssetOfType(asset, 1));
nkloeber marked this conversation as resolved.
Show resolved Hide resolved
const nativeImageAssetObj = find(matchedBid.native.assets, asset => isImageAssetOfType(asset, 3));
const nativeImageAsset = nativeImageAssetObj ? nativeImageAssetObj.img : { url: '', w: 0, h: 0 };
const nativeTitleAsset = find(matchedBid.native.assets, asset => hasValidProperty(asset, 'title'));
const nativeBodyAsset = find(matchedBid.native.assets, asset => hasValidProperty(asset, 'data'));
bidResponse.native = {
title: nativeTitleAsset ? nativeTitleAsset.title.text : '',
body: nativeBodyAsset ? nativeBodyAsset.data.value : '',
...nativeIconAssetObj?.img && {
icon: {
url: nativeIconAssetObj.img.url,
width: nativeIconAssetObj.img.w,
nkloeber marked this conversation as resolved.
Show resolved Hide resolved
height: nativeIconAssetObj.img.h,
},
},
image: {
url: nativeImageAsset.url,
width: nativeImageAsset.w,
Expand Down Expand Up @@ -517,14 +525,14 @@ function hasValidProperty(obj, propName) {
}

/**
* Checks if an asset object is a main image.
* A main image is defined as an image asset whose type value is 3.
* Checks if an asset object is of the given type.
*
* @param {Object} asset - The asset object to check.
* @returns {boolean} Returns true if the object has a property img.type with a value of 3, otherwise false.
* @param {number} type - The type number to compare.
* @returns {boolean} Returns true if the object has a property img.type with a value of the given type, otherwise false.
*/
function isMainImage(asset) {
return asset?.img?.type === 3
function isImageAssetOfType(asset, type) {
nkloeber marked this conversation as resolved.
Show resolved Hide resolved
return asset?.img?.type === type
}

registerBidder(spec);
44 changes: 42 additions & 2 deletions test/spec/modules/yieldlabBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,15 @@ const NATIVE_RESPONSE = Object.assign({}, RESPONSE, {
value: 'Native body value',
},
},
{
id: 4,
img: {
url: 'https://localhost:8080/assets/favicon/favicon-16x16.png',
w: 16,
h: 16,
type: 1,
},
},
],
imptrackers: [
'http://localhost:8080/ve?d=ODE9ZSY2MTI1MjAzNjMzMzYxPXN0JjA0NWUwZDk0NTY5Yi05M2FiLWUwZTQtOWFjNy1hYWY0MzFiZj1kaXQmMj12',
Expand Down Expand Up @@ -567,15 +576,24 @@ describe('yieldlabBidAdapter', () => {
expect(result[0].native.image.url).to.equal('https://localhost:8080/yl-logo100x100.jpg');
expect(result[0].native.image.width).to.equal(100);
expect(result[0].native.image.height).to.equal(100);
expect(result[0].native.icon.url).to.equal('https://localhost:8080/assets/favicon/favicon-16x16.png');
expect(result[0].native.icon.width).to.equal(16);
nkloeber marked this conversation as resolved.
Show resolved Hide resolved
expect(result[0].native.icon.height).to.equal(16);
expect(result[0].native.clickUrl).to.equal('https://www.yieldlab.de');
expect(result[0].native.impressionTrackers.length).to.equal(3);
expect(result[0].native.assets.length).to.equal(3);
expect(result[0].native.assets.length).to.equal(4);
const titleAsset = result[0].native.assets.find(asset => 'title' in asset);
const imageAsset = result[0].native.assets.find(asset => 'img' in asset);
const imageAsset = result[0].native.assets.find((asset) => {
return asset?.img?.type === 3;
});
const iconAsset = result[0].native.assets.find((asset) => {
return asset?.img?.type === 1;
});
const bodyAsset = result[0].native.assets.find(asset => 'data' in asset);
expect(titleAsset).to.exist.and.to.have.nested.property('id', 1)
expect(imageAsset).to.exist.and.to.have.nested.property('id', 2)
expect(bodyAsset).to.exist.and.to.have.nested.property('id', 3)
expect(iconAsset).to.exist.and.to.have.nested.property('id', 4)
});

it('should add adUrl and default native assets when type is Native', () => {
Expand All @@ -601,6 +619,28 @@ describe('yieldlabBidAdapter', () => {
expect(result[0].native.image.height).to.equal(0);
});

it('should not add icon if not present in the native response', () => {
const NATIVE_RESPONSE_WITHOUT_ICON = Object.assign({}, NATIVE_RESPONSE, {
native: {
link: {
url: 'https://www.yieldlab.de',
},
assets: [
{
id: 1,
title: {
text: 'This is a great headline',
}
}
],
imptrackers: [],
},
});
const result = spec.interpretResponse({body: [NATIVE_RESPONSE_WITHOUT_ICON]}, {validBidRequests: [NATIVE_REQUEST()], queryParams: REQPARAMS});
expect(result[0].native.hasOwnProperty('icon')).to.be.false;
expect(result[0].native.title).to.equal('This is a great headline');
});

it('should append gdpr parameters to vastUrl', () => {
const result = spec.interpretResponse({body: [VIDEO_RESPONSE]}, {validBidRequests: [VIDEO_REQUEST()], queryParams: REQPARAMS_GDPR});

Expand Down