Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('marks the winning bid object as used for the given adUnitCode', function () {
// 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 = find($$PREBID_GLOBAL$$.getBidResponsesForAdUnitCode(adUnitCode).bids,
bid => bid.adId === winningBid.adId);
expect(markedBid.status).to.equal(CONSTANTS.BID_STATUS.RENDERED);
resetAuction();
});
let bidDuration = utils.deepAccess(bidResponse, 'video.durationSeconds');
let videoConfig = utils.deepAccess(bidderRequest, 'mediaTypes.video');
let adUnitRanges = videoConfig.durationRangeSec;
adUnitRanges.sort((a, b) => a - b); // ensure the ranges are sorted in numeric order
if (!videoConfig.requireExactDuration) {
let max = Math.max(...adUnitRanges);
if (bidDuration <= (max + buffer)) {
let nextHighestRange = find(adUnitRanges, range => (range + buffer) >= bidDuration);
bidResponse.video.durationBucket = nextHighestRange;
} else {
utils.logWarn(`Detected a bid with a duration value outside the accepted ranges specified in adUnit.mediaTypes.video.durationRangeSec. Rejecting bid: `, bidResponse);
return false;
}
} else {
if (find(adUnitRanges, range => range === bidDuration)) {
bidResponse.video.durationBucket = bidDuration;
} else {
utils.logWarn(`Detected a bid with a duration value not part of the list of accepted ranges specified in adUnit.mediaTypes.video.durationRangeSec. Exact match durations must be used for this adUnit. Rejecting bid: `, bidResponse);
return false;
}
}
return true;
}
it('should not filter bids w/ no labels', function () {
let bidRequests = adapterManager.makeBidRequests(
adUnits,
Date.now(),
utils.getUniqueIdentifierStr(),
function callback() {},
[]
);
expect(bidRequests.length).to.equal(2);
let rubiconBidRequests = find(bidRequests, bidRequest => bidRequest.bidderCode === 'rubicon');
expect(rubiconBidRequests.bids.length).to.equal(1);
expect(rubiconBidRequests.bids[0].sizes).to.deep.equal(find(adUnits, adUnit => adUnit.code === rubiconBidRequests.bids[0].adUnitCode).sizes);
let appnexusBidRequests = find(bidRequests, bidRequest => bidRequest.bidderCode === 'appnexus');
expect(appnexusBidRequests.bids.length).to.equal(2);
expect(appnexusBidRequests.bids[0].sizes).to.deep.equal(find(adUnits, adUnit => adUnit.code === appnexusBidRequests.bids[0].adUnitCode).sizes);
expect(appnexusBidRequests.bids[1].sizes).to.deep.equal(find(adUnits, adUnit => adUnit.code === appnexusBidRequests.bids[1].adUnitCode).sizes);
});
export function addBidToAuction(auctionInstance, bidResponse) {
let bidderRequests = auctionInstance.getBidRequests();
let bidderRequest = find(bidderRequests, bidderRequest => bidderRequest.bidderCode === bidResponse.bidderCode);
setupBidTargeting(bidResponse, bidderRequest);
events.emit(CONSTANTS.EVENTS.BID_RESPONSE, bidResponse);
auctionInstance.addBidReceived(bidResponse);
doCallbacksIfTimedout(auctionInstance, bidResponse);
}
[TARGETING_KEYS.UUID, TARGETING_KEYS.CACHE_ID].forEach(targetingKeyVal => {
if (typeof find(adserverTargeting, kvPair => kvPair.key === targetingKeyVal) === 'undefined') {
adserverTargeting.push(createKeyVal(targetingKeyVal, 'videoCacheKey'));
}
});
return rtbBids.map(rtbBid => {
let imp = find(rtbImps, imp => imp.id === rtbBid.impid);
let prBid = {
requestId: rtbBid.impid,
cpm: rtbBid.price,
creativeId: rtbBid.crid,
currency: 'USD',
ttl: 360,
netRevenue: true
};
if ('banner' in imp) {
prBid.mediaType = BANNER;
prBid.width = rtbBid.w;
prBid.height = rtbBid.h;
prBid.ad = formatAdMarkup(rtbBid);
}
return prBid;
});
export function attachIdSystem(submodule) {
if (!find(submoduleRegistry, i => i.name === submodule.name)) {
submoduleRegistry.push(submodule);
updateSubmodules();
}
}
findBid(event) {
const bidder = find(this.auction.requests, r => (r.bidderCode === event.bidderCode))
if (!bidder) {
this.auction.unsynced.push(JSON.parse(JSON.stringify(event)))
}
let bid = find(bidder.bids, b => (b.bidId === event.requestId))
if (!bid) {
event.unmatched = true
bidder.bids.push(JSON.parse(JSON.stringify(event)))
}
return bid
}