Skip to content

Commit

Permalink
returns empty object when no config gound
Browse files Browse the repository at this point in the history
  • Loading branch information
karimMourra committed Aug 23, 2022
1 parent 7151707 commit 128b718
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion modules/videoModule/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export function PbVideo(videoCore_, getConfig_, pbGlobal_, pbEvents_, videoEvent

function getAdServerConfig(adUnitVideoConfig) {
const globalVideoConfig = getConfig('video');
const globalProviderConfig = globalVideoConfig.providers.find(provider => provider.divId === adUnitVideoConfig.divId);
const globalProviderConfig = globalVideoConfig.providers.find(provider => provider.divId === adUnitVideoConfig.divId) || {};
if (!globalVideoConfig.adServer && !globalProviderConfig.adServer && !adUnitVideoConfig.adServer) {
return;
}
Expand Down
18 changes: 12 additions & 6 deletions test/spec/modules/videoModule/pbVideo_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ function resetTestVars() {
requestBids: requestBidsMock,
getHighestCpmBids: sinon.spy(),
getBidResponsesForAdUnitCode: sinon.spy(),
setConfig: sinon.spy()
setConfig: sinon.spy(),
getConfig: () => ({}),
markWinningBidAsUsed: sinon.spy()
};
pbEventsMock = {
emit: sinon.spy(),
Expand Down Expand Up @@ -147,7 +149,7 @@ describe('Prebid Video', function () {
before: callback_ => beforeBidRequestCallback = callback_
};

pbVideoFactory(null, null, { requestBids, setConfig: setConfigSpy });
pbVideoFactory(null, null, Object.assign({}, pbGlobalMock, { requestBids, setConfig: setConfigSpy }));
expect(beforeBidRequestCallback).to.not.be.undefined;
const nextFn = sinon.spy();
const adUnits = [{
Expand All @@ -172,9 +174,11 @@ describe('Prebid Video', function () {
let providers = [{ divId: 'div1', adServer: {} }, { divId: 'div2' }];
let getConfig = (propertyName, callbackFn) => {
if (propertyName === 'video') {
callbackFn({
video: { providers }
});
if (callbackFn) {
callbackFn({ video: { providers } });
} else {
return { providers };
}
}
};

Expand Down Expand Up @@ -271,7 +275,7 @@ describe('Prebid Video', function () {
};
const auctionResults = { adUnits: [ expectedAdUnit, {} ] };

pbVideoFactory(null, null, pbGlobal, pbEvents);
pbVideoFactory(null, () => ({ providers: [] }), pbGlobal, pbEvents);
beforeBidRequestCallback(() => {}, {});
auctionEndCallback(auctionResults);
expect(videoCoreMock.setAdTagUrl.calledOnce).to.be.true;
Expand Down Expand Up @@ -320,6 +324,7 @@ describe('Prebid Video', function () {
const payload = pbEvents.emit.getCall(0).args[1];
expect(payload.bid).to.be.equal(expectedBid);
expect(payload.adEvent).to.be.equal(expectedAdEventPayload);
expect(pbGlobal.markWinningBidAsUsed.calledOnce).to.be.true;
});

it('should trigger video bid error when the bid matched', function () {
Expand All @@ -334,6 +339,7 @@ describe('Prebid Video', function () {
const payload = pbEvents.emit.getCall(0).args[1];
expect(payload.bid).to.be.equal(expectedBid);
expect(payload.adEvent).to.be.equal(expectedAdEventPayload);
expect(pbGlobal.markWinningBidAsUsed.calledOnce).to.be.true;
});

it('should not trigger a bid impression when the bid did not match', function () {
Expand Down

0 comments on commit 128b718

Please sign in to comment.