Skip to content

Commit

Permalink
fixed bug when latitute/longitue are not provided (#2533)
Browse files Browse the repository at this point in the history
  • Loading branch information
harpere authored May 15, 2018
1 parent ab5ca4d commit 6785bc5
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
4 changes: 2 additions & 2 deletions modules/rubiconBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ export const spec = {
'p_screen_res', _getScreenResolution(),
'kw', keywords,
'tk_user_key', userId,
'p_geo.latitude', parseFloat(latitude).toFixed(4),
'p_geo.longitude', parseFloat(longitude).toFixed(4)
'p_geo.latitude', isNaN(parseFloat(latitude)) ? undefined : parseFloat(latitude).toFixed(4),
'p_geo.longitude', isNaN(parseFloat(longitude)) ? undefined : parseFloat(longitude).toFixed(4)
];

if (gdprConsent) {
Expand Down
62 changes: 61 additions & 1 deletion test/spec/modules/rubiconBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ describe('the rubicon adapter', () => {
},
position: 'atf',
referrer: 'localhost',
latLong: [40.7608, '111.8910']
latLong: [40.7607823, '111.8910325']
},
adUnitCode: '/19968336/header-bid-tag-0',
code: 'div-1',
Expand Down Expand Up @@ -256,6 +256,66 @@ describe('the rubicon adapter', () => {
});
});

it('should make a well-formed request object without latLong', () => {
let expectedQuery = {
'account_id': '14062',
'site_id': '70608',
'zone_id': '335918',
'size_id': '15',
'alt_size_ids': '43',
'p_pos': 'atf',
'rp_floor': '0.01',
'rp_secure': /[01]/,
'rand': '0.1',
'tk_flint': INTEGRATION,
'x_source.tid': 'd45dd707-a418-42ec-b8a7-b70a6c6fab0b',
'p_screen_res': /\d+x\d+/,
'tk_user_key': '12346',
'kw': 'a,b,c',
'tg_v.ucat': 'new',
'tg_v.lastsearch': 'iphone',
'tg_i.rating': '5-star',
'tg_i.prodtype': 'tech',
'rf': 'localhost',
'p_geo.latitude': undefined,
'p_geo.longitude': undefined
};

sandbox.stub(Math, 'random').callsFake(() => 0.1);

delete bidderRequest.bids[0].params.latLong;
[request] = spec.buildRequests(bidderRequest.bids, bidderRequest);
data = parseQuery(request.data);

expect(request.url).to.equal('//fastlane.rubiconproject.com/a/api/fastlane.json');

// test that all values above are both present and correct
Object.keys(expectedQuery).forEach(key => {
let value = expectedQuery[key];
if (value instanceof RegExp) {
expect(data[key]).to.match(value);
} else {
expect(data[key]).to.equal(value);
}
});

bidderRequest.bids[0].params.latLong = [];
let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest);
let data = parseQuery(request.data);

expect(request.url).to.equal('//fastlane.rubiconproject.com/a/api/fastlane.json');

// test that all values above are both present and correct
Object.keys(expectedQuery).forEach(key => {
let value = expectedQuery[key];
if (value instanceof RegExp) {
expect(data[key]).to.match(value);
} else {
expect(data[key]).to.equal(value);
}
});
});

it('page_url should use params.referrer, config.getConfig("pageUrl"), utils.getTopWindowUrl() in that order', () => {
sandbox.stub(utils, 'getTopWindowUrl').callsFake(() => 'http://www.prebid.org');

Expand Down

0 comments on commit 6785bc5

Please sign in to comment.