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

Only set native targeting if value exists. #3225

Merged
merged 1 commit into from
Oct 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions src/native.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -163,7 +163,7 @@ export function getNativeTargeting(bid) {
value = value.url;
}

if (key) {
if (key && value) {
keyValues[key] = value;
}
});
Expand Down
23 changes: 23 additions & 0 deletions test/spec/native_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<script src=\"http://www.foobar.js\"></script>'
}
};

describe('native.js', function () {
let triggerPixelStub;
let insertHtmlIntoIframeStub;
Expand All @@ -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);
Expand Down