diff --git a/modules/yieldlabBidAdapter.js b/modules/yieldlabBidAdapter.js index cadeb9c1300..31e9b35f178 100644 --- a/modules/yieldlabBidAdapter.js +++ b/modules/yieldlabBidAdapter.js @@ -184,13 +184,12 @@ export const spec = { if (isNative(bidRequest, adType)) { // there may be publishers still rely on it - const url = `${ENDPOINT}/d/${matchedBid.id}/${bidRequest.params.supplyId}/?ts=${timestamp}${extId}${gdprApplies}${gdprConsent}${pvId}`; - bidResponse.adUrl = url; + bidResponse.adUrl = `${ENDPOINT}/d/${matchedBid.id}/${bidRequest.params.supplyId}/?ts=${timestamp}${extId}${gdprApplies}${gdprConsent}${pvId}`; bidResponse.mediaType = NATIVE; - const nativeImageAssetObj = find(matchedBid.native.assets, e => e.id === 2); + 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, e => e.id === 1); - const nativeBodyAsset = find(matchedBid.native.assets, e => e.id === 3); + 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 : '', @@ -201,6 +200,7 @@ export const spec = { }, clickUrl: matchedBid.native.link.url, impressionTrackers: matchedBid.native.imptrackers, + assets: matchedBid.native.assets, }; } @@ -505,4 +505,26 @@ function getBidFloor(bid, sizes) { return undefined; } +/** + * Checks if an object has a property with a given name and the property value is not null or undefined. + * + * @param {Object} obj - The object to check. + * @param {string} propName - The name of the property to check. + * @returns {boolean} Returns true if the object has a property with the given name and the property value is not null or undefined, otherwise false. + */ +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); diff --git a/test/spec/modules/yieldlabBidAdapter_spec.js b/test/spec/modules/yieldlabBidAdapter_spec.js index e5151cf789c..80537facd41 100644 --- a/test/spec/modules/yieldlabBidAdapter_spec.js +++ b/test/spec/modules/yieldlabBidAdapter_spec.js @@ -191,6 +191,7 @@ const NATIVE_RESPONSE = Object.assign({}, RESPONSE, { url: 'https://localhost:8080/yl-logo100x100.jpg', w: 100, h: 100, + type: 3, }, }, { @@ -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'); @@ -569,6 +569,13 @@ describe('yieldlabBidAdapter', () => { expect(result[0].native.image.height).to.equal(100); 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); + const titleAsset = result[0].native.assets.find(asset => 'title' in asset); + const imageAsset = result[0].native.assets.find(asset => 'img' in asset); + 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) }); it('should add adUrl and default native assets when type is Native', () => {