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

rubiconBidAdapter - Checking FPD values are defined before toString() #3165

Merged
merged 3 commits into from
Oct 9, 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
8 changes: 6 additions & 2 deletions modules/rubiconBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,14 +341,18 @@ export const spec = {
// visitor properties
if (params.visitor !== null && typeof params.visitor === 'object') {
Object.keys(params.visitor).forEach((key) => {
data[`tg_v.${key}`] = params.visitor[key].toString();
if (params.visitor[key] != null) {
data[`tg_v.${key}`] = params.visitor[key].toString(); // initialize array;
}
});
}

// inventory properties
if (params.inventory !== null && typeof params.inventory === 'object') {
Object.keys(params.inventory).forEach((key) => {
data[`tg_i.${key}`] = params.inventory[key].toString();
if (params.inventory[key] != null) {
data[`tg_i.${key}`] = params.inventory[key].toString();
}
});
}

Expand Down
66 changes: 66 additions & 0 deletions test/spec/modules/rubiconBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,72 @@ describe('the rubicon adapter', function () {
});
});

describe('first party data', function () {
it('should not have any tg_v or tg_i params if all are undefined', function () {
let params = {
inventory: {
rating: null,
prodtype: undefined
},
visitor: {
ucat: undefined,
lastsearch: null,
likes: undefined
},
};

// Overwrite the bidder request params with the above ones
Object.assign(bidderRequest.bids[0].params, params);

// get the built request
let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest);
let data = parseQuery(request.data);

// make sure that no tg_v or tg_i keys are present in the request
let matchingExp = RegExp('^tg_(i|v)\..*$')
Object.keys(data).forEach(key => {
expect(key).to.not.match(matchingExp);
});
});

it('should contain valid params when some are undefined', function () {
let params = {
inventory: {
rating: undefined,
prodtype: ['tech', 'mobile']
},
visitor: {
ucat: null,
lastsearch: 'iphone',
likes: undefined
},
};
let undefinedKeys = ['tg_i.rating', 'tg_v.ucat', 'tg_v.likes']
let expectedQuery = {
'tg_v.lastsearch': 'iphone',
'tg_i.prodtype': 'tech,mobile',
}

// Overwrite the bidder request params with the above ones
Object.assign(bidderRequest.bids[0].params, params);

// get the built request
let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest);
let data = parseQuery(request.data);

// make sure none of the undefined keys are in query
undefinedKeys.forEach(key => {
expect(typeof data[key]).to.equal('undefined');
});

// make sure the expected and defined ones do show up still
Object.keys(expectedQuery).forEach(key => {
let value = expectedQuery[key];
expect(data[key]).to.equal(value);
});
});
});

describe('singleRequest config', function () {
it('should group all bid requests with the same site id', function () {
sandbox.stub(Math, 'random').callsFake(() => 0.1);
Expand Down