Skip to content

Commit

Permalink
YieldlabBidAdapter update main image asset mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
nkloeber committed May 5, 2023
1 parent e949cbb commit 3021c6d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion modules/yieldlabBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export const spec = {
// there may be publishers still rely on it
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 => hasValidProperty(asset, 'img'));
const nativeImageAssetObj = find(matchedBid.native.assets, asset => isMainImage(asset));
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'));
Expand Down Expand Up @@ -516,4 +516,15 @@ function hasValidProperty(obj, propName) {
return obj.hasOwnProperty(propName) && obj[propName] != null;
}

/**
* Checks if an asset object is a main image.
* A main image is defined as an image asset whose type value is 3.
*
* @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.
*/
function isMainImage(asset) {
return asset?.img?.type === 3
}

registerBidder(spec);
2 changes: 1 addition & 1 deletion test/spec/modules/yieldlabBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ const NATIVE_RESPONSE = Object.assign({}, RESPONSE, {
url: 'https://localhost:8080/yl-logo100x100.jpg',
w: 100,
h: 100,
type: 3,
},
},
{
Expand Down Expand Up @@ -557,7 +558,6 @@ describe('yieldlabBidAdapter', () => {

it('should add adUrl and native assets when type is Native', () => {
const result = spec.interpretResponse({body: [NATIVE_RESPONSE]}, {validBidRequests: [NATIVE_REQUEST()], queryParams: REQPARAMS});

expect(result[0].requestId).to.equal('2d925f27f5079f');
expect(result[0].cpm).to.equal(0.01);
expect(result[0].mediaType).to.equal('native');
Expand Down

0 comments on commit 3021c6d

Please sign in to comment.