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

New function markWinningBidAsUsed for marking video bids #2777

Merged
merged 8 commits into from
Jul 20, 2018
12 changes: 12 additions & 0 deletions src/prebid.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,18 @@ $$PREBID_GLOBAL$$.getHighestCpmBids = function (adUnitCode) {
.map(removeRequestId);
};

/**
* Mark the winning bid as used, should only be used in conjunction with video
* @param {string} adUnitCode - required ad unit code
* @alias module:pbjs.markWinningBidAsUsed
*/
$$PREBID_GLOBAL$$.markWinningBidAsUsed = function (adUnitCode) {
Copy link
Member

Choose a reason for hiding this comment

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

@Caspervw
Can you make this accept an object instead of a string?
I'm thinking we would also want to match against a bidId as well as a adUnitCode.
example:

{
  adUnitCode : <code>,
  bidId : <id>
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing

const bids = targeting.getWinningBids(adUnitCode);
if (bids.length > 0) {
bids[0].status = RENDERED;
}
};

/**
* Get Prebid config options
* @param {Object} options
Expand Down
21 changes: 20 additions & 1 deletion test/spec/unit/pbjs_api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
createBidReceived
} from 'test/fixtures/fixtures';
import { auctionManager, newAuctionManager } from 'src/auctionManager';
import { targeting, newTargeting } from 'src/targeting';
import { targeting, newTargeting, RENDERED } from 'src/targeting';
import { config as configObj } from 'src/config';
import * as ajaxLib from 'src/ajax';
import * as auctionModule from 'src/auction';
Expand Down Expand Up @@ -1829,6 +1829,25 @@ describe('Unit: Prebid Module', function () {
});
});

describe('markWinningBidAsUsed', () => {
it('marks the winning bid object as used for the given adUnitCode', () => {
// make sure the auction has "state" and does not reload the fixtures
const adUnitCode = '/19968336/header-bid-tag-0';
const bidsReceived = $$PREBID_GLOBAL$$.getBidResponsesForAdUnitCode(adUnitCode);
auction.getBidsReceived = function() { return bidsReceived.bids };

// mark the bid and verify the state has changed to RENDERED
const winningBid = targeting.getWinningBids(adUnitCode)[0];
$$PREBID_GLOBAL$$.markWinningBidAsUsed(adUnitCode);
const markedBid = $$PREBID_GLOBAL$$.getBidResponsesForAdUnitCode(adUnitCode)
.bids
.find(bid => bid.adId === winningBid.adId);

expect(markedBid.status).to.equal(RENDERED);
resetAuction();
});
});

describe('setTargetingForAst', () => {
let targeting;
let auctionManagerInstance;
Expand Down