-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
fixed #1246 and add unit test #1427
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a89edd3
fixed #1267 and add unit test
mkendall07 3e76801
remove markup
mkendall07 d267567
move unit tests
mkendall07 a4772a5
resolve conflict
mkendall07 dc8e699
remove comment
mkendall07 5bf3a19
interim fix
mkendall07 4d4729b
fix unit tests. Not sure about having to import config directly in th…
mkendall07 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { expect } from 'chai'; | ||
import Targeting from 'src/targeting'; | ||
import { config } from 'src/config'; | ||
import { getAdUnits } from 'test/fixtures/fixtures'; | ||
import CONSTANTS from 'src/constants.json'; | ||
|
||
const bid1 = { | ||
'bidderCode': 'rubicon', | ||
'width': '300', | ||
'height': '250', | ||
'statusMessage': 'Bid available', | ||
'adId': '148018fe5e', | ||
'cpm': 0.537234, | ||
'ad': 'markup', | ||
'ad_id': '3163950', | ||
'sizeId': '15', | ||
'requestTimestamp': 1454535718610, | ||
'responseTimestamp': 1454535724863, | ||
'timeToRespond': 123, | ||
'pbLg': '0.50', | ||
'pbMg': '0.50', | ||
'pbHg': '0.53', | ||
'adUnitCode': '/123456/header-bid-tag-0', | ||
'bidder': 'rubicon', | ||
'size': '300x250', | ||
'adserverTargeting': { | ||
'hb_bidder': 'rubicon', | ||
'hb_adid': '148018fe5e', | ||
'hb_pb': '0.53', | ||
'foobar': '300x250' | ||
} | ||
}; | ||
|
||
const bid2 = { | ||
'bidderCode': 'rubicon', | ||
'width': '300', | ||
'height': '250', | ||
'statusMessage': 'Bid available', | ||
'adId': '5454545', | ||
'cpm': 0.25, | ||
'ad': 'markup', | ||
'ad_id': '3163950', | ||
'sizeId': '15', | ||
'requestTimestamp': 1454535718610, | ||
'responseTimestamp': 1454535724863, | ||
'timeToRespond': 123, | ||
'pbLg': '0.25', | ||
'pbMg': '0.25', | ||
'pbHg': '0.25', | ||
'adUnitCode': '/123456/header-bid-tag-0', | ||
'bidder': 'rubicon', | ||
'size': '300x250', | ||
'adserverTargeting': { | ||
'hb_bidder': 'rubicon', | ||
'hb_adid': '5454545', | ||
'hb_pb': '0.25', | ||
'foobar': '300x250' | ||
} | ||
}; | ||
|
||
describe('targeting tests', () => { | ||
describe('getAllTargeting', () => { | ||
beforeEach(() => { | ||
$$PREBID_GLOBAL$$._sendAllBids = false; | ||
$$PREBID_GLOBAL$$._bidsReceived = []; | ||
$$PREBID_GLOBAL$$._adUnitCodes = []; | ||
$$PREBID_GLOBAL$$.adUnits = []; | ||
}); | ||
|
||
it('selects the top bid when _sendAllBids true', () => { | ||
$$PREBID_GLOBAL$$.adUnits = [{ | ||
code: '/123456/header-bid-tag-0', | ||
sizes: [300, 250], | ||
bids: [ | ||
{ | ||
'bidder': 'rubicon', | ||
'params': { | ||
'accountId': 10617, | ||
'siteId': 23635, | ||
'zoneId': 453908 | ||
} | ||
} | ||
] | ||
}]; | ||
config.setConfig({ enableSendAllBids: true }); | ||
$$PREBID_GLOBAL$$._bidsReceived.push(bid1, bid2); | ||
$$PREBID_GLOBAL$$._adUnitCodes = ['/123456/header-bid-tag-0']; | ||
let targeting = Targeting.getAllTargeting(['/123456/header-bid-tag-0']); | ||
let flattened = []; | ||
targeting.filter(obj => obj['/123456/header-bid-tag-0'] !== undefined).forEach(item => flattened = flattened.concat(item['/123456/header-bid-tag-0'])); | ||
let sendAllBidCpm = flattened.filter(obj => obj.hb_pb_rubicon !== undefined); | ||
let winningBidCpm = flattened.filter(obj => obj.hb_pb !== undefined); | ||
// we shouldn't get more than 1 key for hb_pb_${bidder} | ||
expect(sendAllBidCpm.length).to.equal(1); | ||
// expect the winning CPM to be equal to the sendAllBidCPM | ||
expect(sendAllBidCpm[0]['hb_pb_rubicon']).to.deep.equal(winningBidCpm[0]['hb_pb']); | ||
}); | ||
}); // end getAllTargeting tests | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hooray! Nice general code.
This is a bit subjective... but if you want to stretch it even more, you could make this function much more powerful (and only a little bit more complicated) if you accept an
(element) => key
function here, rather than a raw "key".Your call would replace
groupBy($$PREBID_GLOBAL$$._bidsReceived, 'adUnitCode')
with
groupBy($$PREBID_GLOBAL$$._bidsReceived, bid => bid.adUnitCode)
.In exchange, this function would work with arrays of anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, but I don't understand how this is useful to me?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol, it's not. Sorry... should have been clear: I didn't actually expect a change here. More of a fun FYI.
Many general-purpose utils libraries have this function, including lodash, async, the scala stdlib, etc. I was just pointing out how close this comes to "the bleeding edge" of general-purpose code.