-
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
BaseAdapter for the Prebid 0.x -> 1.x transition #1494
Merged
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
c1080dd
Added a base adapter for single-request adapters, and ported the appn…
dbemiller 70fcf51
Renamed the SingleRequestBidder to BidderFactory. Updated it to handl…
dbemiller 211e7fc
Added a unit test for the delayExecution function.
dbemiller 6246eaf
Merged from master. Fixed conflicts.
dbemiller d509150
Made newBidder a default import. Added some unit tests.
dbemiller 8d4ebc1
Added more tests.
dbemiller 7ffc16f
Merge branch 'master' of https://github.com/prebid/Prebid.js into sin…
dbemiller 1f23044
Added more tests, and fixed a few bugs.
dbemiller 8d1efa6
Merged from master. Fixed a conflict.
dbemiller a627a43
Changed an error to a log message. Fixed a small bug.
dbemiller ff99ff6
Merged from master, and fixed conflicts.
dbemiller c246aa6
Did the no-brainer improvements from PR comments.
dbemiller 6c80c3d
Added spec-level support for aliases and mediaTypes. Aliases may stil…
dbemiller 37399c7
Added support for aliases. Added more tests
dbemiller 1b42995
Cleaned up some unnecessary code.
dbemiller 5c3d645
Removed the GET/POST constants. Fixed some typos, and renamed some Re…
dbemiller 31899f4
Merged from master. Fixed conflicts.
dbemiller 735f2bc
Re-added some code for outstream rendering, which was apparently lost…
dbemiller dd4e595
Removed confusing use of this
dbemiller 25f822a
Fixed lint error
dbemiller e63f2d6
Moved JSON parsing into the bidderFactory, and moved the JSDocs to th…
dbemiller 13d3911
Removed placementCode from everywhere I could.
dbemiller 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
Made newBidder a default import. Added some unit tests.
- Loading branch information
commit d509150e47a8b187b2e5326e378d6706e9b50aca
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ import { logWarn, logError, parseQueryStringParameters, delayExecution } from 's | |
* | ||
* @param {BidderSpec} spec An object containing the bare-bones functions we need to make a Bidder. | ||
*/ | ||
export function newBidder(spec) { | ||
export default function newBidder(spec) { | ||
return Object.assign(new Adapter(spec.code), { | ||
callBids: function(bidsRequest) { | ||
if (!bidsRequest.bids || !bidsRequest.bids.filter) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like an array check. Would be more clear as |
||
|
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,127 @@ | ||
import newBidder from 'src/adapters/bidderFactory'; | ||
import bidmanager from 'src/bidmanager'; | ||
import * as ajax from 'src/ajax'; | ||
import { expect } from 'chai'; | ||
|
||
const CODE = 'sampleBidder'; | ||
const MOCK_BIDS_REQUEST = { | ||
bids: [ | ||
{ | ||
placementCode: 'mock/placement', | ||
params: { | ||
param: 5 | ||
} | ||
}, | ||
{ | ||
placementCode: 'mock/placement2', | ||
params: { | ||
badParam: 6 | ||
} | ||
} | ||
] | ||
} | ||
|
||
describe('The bidder factory', () => { | ||
let spec; | ||
let bidder; | ||
let addBidRequestStub; | ||
let ajaxMock; | ||
|
||
beforeEach(() => { | ||
spec = { | ||
code: CODE, | ||
areParamsValid: sinon.stub(), | ||
buildRequests: sinon.stub(), | ||
interpretResponse: sinon.stub() | ||
}; | ||
bidder = newBidder(spec); | ||
addBidRequestStub = sinon.stub(bidmanager, 'addBidResponse'); | ||
ajaxMock = sinon.mock(ajax); | ||
}); | ||
|
||
afterEach(() => { | ||
addBidRequestStub.restore(); | ||
ajaxMock.restore(); | ||
}) | ||
|
||
it('should handle bad bid requests gracefully', () => { | ||
ajaxMock.expects('ajax').never(); | ||
|
||
bidder.callBids({}); | ||
bidder.callBids({ bids: 'nothing useful' }); | ||
expect(spec.areParamsValid.called).to.equal(false); | ||
expect(spec.buildRequests.called).to.equal(false); | ||
expect(spec.interpretResponse.called).to.equal(false); | ||
}); | ||
|
||
it('should call buildRequests(bidRequest) the params are valid.', () => { | ||
spec.areParamsValid.returns(true); | ||
spec.buildRequests.returns([]); | ||
ajaxMock.expects('ajax').never(); | ||
|
||
bidder.callBids(MOCK_BIDS_REQUEST); | ||
|
||
expect(spec.areParamsValid.calledTwice).to.equal(true); | ||
expect(spec.buildRequests.calledOnce).to.equal(true); | ||
expect(spec.buildRequests.firstCall.args[0]).to.deep.equal(MOCK_BIDS_REQUEST.bids); | ||
}); | ||
|
||
it('should not call buildRequests the params are invalid.', () => { | ||
spec.areParamsValid.returns(false); | ||
spec.buildRequests.returns([]); | ||
ajaxMock.expects('ajax').never(); | ||
|
||
bidder.callBids(MOCK_BIDS_REQUEST); | ||
|
||
expect(spec.areParamsValid.calledTwice).to.equal(true); | ||
expect(spec.buildRequests.called).to.equal(false); | ||
}); | ||
|
||
it('should filter out invalid bids before calling buildRequests.', () => { | ||
spec.areParamsValid.onFirstCall().returns(true); | ||
spec.areParamsValid.onSecondCall().returns(false); | ||
spec.buildRequests.returns([]); | ||
ajaxMock.expects('ajax').never(); | ||
|
||
bidder.callBids(MOCK_BIDS_REQUEST); | ||
|
||
expect(spec.areParamsValid.calledTwice).to.equal(true); | ||
expect(spec.buildRequests.calledOnce).to.equal(true); | ||
expect(spec.buildRequests.firstCall.args[0]).to.deep.equal([MOCK_BIDS_REQUEST.bids[0]]); | ||
}); | ||
|
||
it('should make the appropriate POST requests.', () => { | ||
const url = 'test.url.com'; | ||
const data = { arg: 2 }; | ||
spec.areParamsValid.returns(true); | ||
spec.buildRequests.returns({ | ||
type: 'POST', | ||
endpoint: url, | ||
data: data | ||
}); | ||
ajaxMock.expects('ajax').once().withArgs(url, sinon.match.object, JSON.stringify(data), { | ||
method: 'POST', | ||
contentType: 'text/plain', | ||
withCredentials: true | ||
}); | ||
|
||
bidder.callBids(MOCK_BIDS_REQUEST); | ||
}); | ||
|
||
it('should make the appropriate GET requests.', () => { | ||
const url = 'test.url.com'; | ||
const data = { arg: 2 }; | ||
spec.areParamsValid.returns(true); | ||
spec.buildRequests.returns({ | ||
type: 'GET', | ||
endpoint: url, | ||
data: data | ||
}); | ||
ajaxMock.expects('ajax').once().withArgs(`${url}?arg=2&`, sinon.match.object, undefined, { | ||
method: 'GET', | ||
withCredentials: true | ||
}); | ||
|
||
bidder.callBids(MOCK_BIDS_REQUEST); | ||
}); | ||
}); |
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.
We need to figure out how aliasing is going to work with this new pattern. Currently I have it calling
new
on the.constructor
link of an existing instance. In this case it would be an instance of just plain Adapter, which means it wouldn't work.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.
Added support for these. I'm not sure this is the best way, though... so let me know if you have better ideas.
If we think this API is general enough to be the only base class, I might re-organize the code a bit so that "bidder creation" is in a separate file from "bidder registration".
I still haven't heard anyone weigh in on whether or not this handles all the 1.0 use-cases, though, or whether i'm overly-constraining adapters with it.