Skip to content

Commit

Permalink
rubiconBidAdapter - Checking FPD values are defined before toString() (
Browse files Browse the repository at this point in the history
…#3165)

* rubiconBidAdapter - Checking FPD values are defined before toString()
                  - Added two tests for this behavior

* Removing unused variable

* changed to compare against null

added some null params to the tests to verify
  • Loading branch information
Robert Ray Martinez III authored and idettman committed Oct 9, 2018
1 parent a4d91fd commit 7f94928
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 2 deletions.
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

0 comments on commit 7f94928

Please sign in to comment.