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

fix log message not displaying when referencing missing bidder #1737

Merged
merged 3 commits into from
Oct 23, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/adaptermanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,20 +197,18 @@ exports.callBids = ({adUnits, cbTimeout}) => {
$$PREBID_GLOBAL$$._bidsRequested.push(bidderRequest);
_bidderRequests.push(bidderRequest);
}
} else {
utils.logError(`Adapter trying to be called which does not exist: ${bidderCode} adaptermanager.callBids`);
}
});

_bidderRequests.forEach(bidRequest => {
bidRequest.start = new Date().getTime();
const adapter = _bidderRegistry[bidRequest.bidderCode];
if (adapter) {
if (bidRequest.bids && bidRequest.bids.length !== 0) {
utils.logMessage(`CALLING BIDDER ======= ${bidRequest.bidderCode}`);
events.emit(CONSTANTS.EVENTS.BID_REQUESTED, bidRequest);
adapter.callBids(bidRequest);
}
} else {
utils.logError(`Adapter trying to be called which does not exist: ${bidRequest.bidderCode} adaptermanager.callBids`);
if (bidRequest.bids && bidRequest.bids.length !== 0) {
utils.logMessage(`CALLING BIDDER ======= ${bidRequest.bidderCode}`);
events.emit(CONSTANTS.EVENTS.BID_REQUESTED, bidRequest);
adapter.callBids(bidRequest);
}
})
};
Expand Down
18 changes: 18 additions & 0 deletions test/spec/unit/pbjs_api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,24 @@ describe('Unit: Prebid Module', function () {
adaptermanager.callBids.restore();
});

it('should log an error if a bidder is used that does not exist', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This test should go in adapterManager_spec. You can use adaptermanager.callBids function to test.
#1508 has some good arguments to avoid $$PREBID_GLOBAL$$ in unit tests

Also stubs should be in beforeEach loop because if this test fails to avoid logError wont be restored.

sinon.stub(utils, 'logError');

const adUnits = [{
code: 'adUnit-code',
bids: [
{bidder: 'appnexus', params: {placementId: 'id'}},
{bidder: 'fakeBidder', params: {placementId: 'id'}}
]
}];

$$PREBID_GLOBAL$$.requestBids({adUnits});

sinon.assert.called(utils.logError);

utils.logError.restore();
});

it('should not callBids if a video adUnit has non-video bidders', () => {
sinon.spy(adaptermanager, 'callBids');
const videoAdaptersBackup = adaptermanager.videoAdapters;
Expand Down