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

fixed #1246 and add unit test #1427

Merged
merged 7 commits into from
Aug 17, 2017
Merged

Conversation

mkendall07
Copy link
Member

@mkendall07 mkendall07 commented Jul 27, 2017

  • Bugfix

Description of change

Fixes #1246

edit: This fixes #1246 not 1267. 1267 is related but not resolved in this PR.

Other information

@prebid/core
Cc: @harpere @bretg

@mkendall07 mkendall07 changed the title fixed #1267 and add unit test fixed #1246 and add unit test Jul 27, 2017
* @param {string} key
* @returns {${key_value}: ${groupByArray}, key_value: {groupByArray}}
*/
export function groupBy(xs, key) {
Copy link
Contributor

@dbemiller dbemiller Jul 27, 2017

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.

Copy link
Member Author

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?

Copy link
Contributor

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.

@@ -0,0 +1,81 @@
import { expect } from 'chai';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the file location... could we make an effort to group the unit tests into one folder? In this case, tests/spec/core => tests/spec/unit/core

In the current organization, I'd expect to find integration tests (for example, connecting videoCache to prebid-cache) right next to unit tests like this one. This is bad for automated testing, because we'll want different subsets of [unit tests, integration tests, nightwatch/selenium tests] to run at different times during the dev, PR, and Release processes.

src/targeting.js Outdated
return {
[bid.adUnitCode]: getTargetingMap(bid, standardKeys.filter(
key => typeof bid.adserverTargeting[key] !== 'undefined') // mainly for possibly
// unset hb_deal
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we clear out the stale comments? I have no idea what these two mean.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, although it's not stale. It's saying that hb_deal isn't always defined even though it's in the default key set. I think it should be obvious from the code though.

@dbemiller dbemiller self-assigned this Jul 31, 2017
@mkendall07
Copy link
Member Author

mkendall07 commented Aug 14, 2017

@dbemiller ready for re-review

Edit: nevermind, looks like moving the spec file caused the unit test to fail :(

@dbemiller
Copy link
Contributor

dbemiller commented Aug 14, 2017

That... sucks :/.

Something similar happened to me when I added spec/unit/bidmanager_spec.js. A totally unrelated test in pbjs_api_spec mysteriously started failing.

In that case, it was because that test didn't set up all the global state required by the code it was testing. I fixed it by setting it in the beforeEach block.

In targeting.js, I see the code relying on the pbTargetingKeys array, $$PREBID_GLOBAL$$._adUnitCodes, $$PREBID_GLOBAL$$.adUnits, and window.googletag.pubads(). Maybe try setting those up in your beforeEach block?

@dbemiller dbemiller mentioned this pull request Aug 16, 2017
Copy link
Contributor

@dbemiller dbemiller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into the issue with $$PREBID_GLOBAL$$.setConfig vs. config.setConfig.

The core issue is that each _spec file gets its own webpack bundle, but $$PREBID_GLOBAL$$ lives on the window, which is shared between tests.

I ran some tests, and it looks like we can fix this by building a single bundle to run the tests. It also cuts our test time down to ~15 seconds... which is awesome.

...unfortunately, it also results in 100+ test failures. So while it's a great idea, we've got a long way to go before we get there.

All that to say... this looks good for now.

Copy link
Collaborator

@matthewlane matthewlane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was able to reproduce original error in #1246, and then get expected result of highest bid consistently selected in sendAllBids mode with this fix. LGTM

@matthewlane matthewlane merged commit 4010783 into master Aug 17, 2017
@matthewlane matthewlane deleted the bugfix/1267_not_selecting_high_bid branch August 17, 2017 22:54
philipwatson pushed a commit to mbrtargeting/Prebid.js that referenced this pull request Sep 18, 2017
* fixed prebid#1267 and add unit test

* remove markup

* move unit tests

* remove comment

* interim fix

* fix unit tests. Not sure about having to import config directly in the spec file
jbAdyoulike pushed a commit to jbAdyoulike/Prebid.js that referenced this pull request Sep 21, 2017
* fixed prebid#1267 and add unit test

* remove markup

* move unit tests

* remove comment

* interim fix

* fix unit tests. Not sure about having to import config directly in the spec file
dluxemburg pushed a commit to Genius/Prebid.js that referenced this pull request Jul 17, 2018
* fixed prebid#1267 and add unit test

* remove markup

* move unit tests

* remove comment

* interim fix

* fix unit tests. Not sure about having to import config directly in the spec file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prebid does not select highest bid when more than one bid per bidder/adapter in "send all bids" mode.
3 participants