From 4910719c434d4ba47811b6b7ba2a4687065f18ba Mon Sep 17 00:00:00 2001 From: Kenan Shifflett Date: Wed, 24 Oct 2018 16:23:22 -0400 Subject: [PATCH] Only set native targeting if value exists. --- src/native.js | 4 ++-- test/spec/native_spec.js | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/native.js b/src/native.js index b4d2d959b70..c9d274ddccd 100644 --- a/src/native.js +++ b/src/native.js @@ -147,7 +147,7 @@ export function fireNativeTrackers(message, adObject) { } /** - * Gets native targeting key-value paris + * Gets native targeting key-value pairs * @param {Object} bid * @return {Object} targeting */ @@ -163,7 +163,7 @@ export function getNativeTargeting(bid) { value = value.url; } - if (key) { + if (key && value) { keyValues[key] = value; } }); diff --git a/test/spec/native_spec.js b/test/spec/native_spec.js index 91b96cac281..68653808c06 100644 --- a/test/spec/native_spec.js +++ b/test/spec/native_spec.js @@ -16,6 +16,19 @@ const bid = { } }; +const bidWithUndefinedFields = { + native: { + title: 'Native Creative', + body: undefined, + cta: undefined, + sponsoredBy: 'AppNexus', + clickUrl: 'https://www.link.example', + clickTrackers: ['https://tracker.example'], + impressionTrackers: ['https://impression.example'], + javascriptTrackers: '' + } +}; + describe('native.js', function () { let triggerPixelStub; let insertHtmlIntoIframeStub; @@ -37,6 +50,16 @@ describe('native.js', function () { expect(targeting[CONSTANTS.NATIVE_KEYS.clickUrl]).to.equal(bid.native.clickUrl); }); + it('should only include native targeting keys with values', function () { + const targeting = getNativeTargeting(bidWithUndefinedFields); + + expect(Object.keys(targeting)).to.deep.equal([ + CONSTANTS.NATIVE_KEYS.title, + CONSTANTS.NATIVE_KEYS.sponsoredBy, + CONSTANTS.NATIVE_KEYS.clickUrl + ]); + }); + it('fires impression trackers', function () { fireNativeTrackers({}, bid); sinon.assert.calledOnce(triggerPixelStub);