Skip to content

Commit

Permalink
Restore pbjs_api_spec.js
Browse files Browse the repository at this point in the history
  • Loading branch information
AlessandroDG committed Oct 24, 2018
1 parent 10a4656 commit fc76379
Showing 1 changed file with 0 additions and 254 deletions.
254 changes: 0 additions & 254 deletions test/spec/unit/pbjs_api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -763,260 +763,6 @@ describe('Unit: Prebid Module', function () {
});
});

describe('getAdserverTargeting with `mediaTypePriceGranularity` set for media type', function() {
let currentPriceBucket;
let auction;
let ajaxStub;
let response;
let cbTimeout = 3000;
let auctionManagerInstance;
let targeting;

const bannerResponse = {
'version': '0.0.1',
'tags': [{
'uuid': '4d0a6829338a07',
'tag_id': 4799418,
'auction_id': '2256922143947979797',
'no_ad_url': 'http://lax1-ib.adnxs.com/no-ad',
'timeout_ms': 2500,
'ads': [{
'content_source': 'rtb',
'ad_type': 'banner',
'buyer_member_id': 958,
'creative_id': 33989846,
'media_type_id': 1,
'media_subtype_id': 1,
'cpm': 1.99,
'cpm_publisher_currency': 0.500000,
'publisher_currency_code': '$',
'client_initiated_ad_counting': true,
'rtb': {
'banner': {
'width': 300,
'height': 250,
'content': '<!-- Creative -->'
},
'trackers': [{
'impression_urls': ['http://lax1-ib.adnxs.com/impression']
}]
}
}]
}]
};
const videoResponse = {
'version': '0.0.1',
'tags': [{
'uuid': '4d0a6829338a07',
'tag_id': 4799418,
'auction_id': '2256922143947979797',
'no_ad_url': 'http://lax1-ib.adnxs.com/no-ad',
'timeout_ms': 2500,
'ads': [{
'content_source': 'rtb',
'ad_type': 'video',
'buyer_member_id': 958,
'creative_id': 33989846,
'media_type_id': 1,
'media_subtype_id': 1,
'cpm': 1.99,
'cpm_publisher_currency': 0.500000,
'publisher_currency_code': '$',
'client_initiated_ad_counting': true,
'rtb': {
'video': {
'width': 300,
'height': 250,
'content': '<!-- Creative -->'
},
'trackers': [{
'impression_urls': ['http://lax1-ib.adnxs.com/impression']
}]
}
}]
}]
};

const createAdUnit = (code, mediaTypes) => {
if (!mediaTypes) {
mediaTypes = ['banner'];
} else if (typeof mediaTypes === 'string') {
mediaTypes = [mediaTypes];
}

const adUnit = {
code: code,
sizes: [[300, 250], [300, 600]],
bids: [{
bidder: 'appnexus',
params: {
placementId: '10433394'
}
}]
};

let _mediaTypes = {};
if (mediaTypes.indexOf('banner') !== -1) {
_mediaTypes['banner'] = {
'banner': {}
};
}
if (mediaTypes.indexOf('video') !== -1) {
_mediaTypes['video'] = {
'video': {
context: 'instream',
playerSize: [300, 250]
}
};
}
if (mediaTypes.indexOf('native') !== -1) {
_mediaTypes['native'] = {
'native': {}
};
}

if (Object.keys(_mediaTypes).length > 0) {
adUnit['mediaTypes'] = _mediaTypes;
// if video type, add video to every bid.param object
if (_mediaTypes.video) {
adUnit.bids.forEach(bid => {
bid.params['video'] = {
width: 300,
height: 250,
vastUrl: '',
ttl: 3600
};
});
}
}
return adUnit;
}
const initTestConfig = (data) => {
$$PREBID_GLOBAL$$.bidderSettings = {};

ajaxStub = sinon.stub(ajaxLib, 'ajaxBuilder').callsFake(function() {
return function(url, callback) {
const fakeResponse = sinon.stub();
fakeResponse.returns('headerContent');
callback.success(JSON.stringify(response), { getResponseHeader: fakeResponse });
}
});
auctionManagerInstance = newAuctionManager();
targeting = newTargeting(auctionManagerInstance)

configObj.setConfig({
'priceGranularity': {
'buckets': [
{ 'precision': 2, 'min': 0, 'max': 5, 'increment': 0.01 },
{ 'precision': 2, 'min': 5, 'max': 8, 'increment': 0.05 },
{ 'precision': 2, 'min': 8, 'max': 20, 'increment': 0.5 },
{ 'precision': 2, 'min': 20, 'max': 25, 'increment': 1 }
]
},
'mediaTypePriceGranularity': {
'banner': {
'buckets': [
{ 'precision': 2, 'min': 0, 'max': 5, 'increment': 0.25 },
{ 'precision': 2, 'min': 6, 'max': 20, 'increment': 0.5 },
{ 'precision': 2, 'min': 21, 'max': 100, 'increment': 1 }
]
},
'video': 'low',
'native': 'high'
}
});

auction = auctionManagerInstance.createAuction({
adUnits: data.adUnits,
adUnitCodes: data.adUnitCodes
});
};

before(() => {
currentPriceBucket = configObj.getConfig('priceGranularity');
sinon.stub(adaptermanager, 'makeBidRequests').callsFake(() => ([{
'bidderCode': 'appnexus',
'auctionId': '20882439e3238c',
'bidderRequestId': '331f3cf3f1d9c8',
'bids': [
{
'bidder': 'appnexus',
'params': {
'placementId': '10433394'
},
'adUnitCode': 'div-gpt-ad-1460505748561-0',
'sizes': [
[
300,
250
],
[
300,
600
]
],
'bidId': '4d0a6829338a07',
'bidderRequestId': '331f3cf3f1d9c8',
'auctionId': '20882439e3238c'
}
],
'auctionStart': 1505250713622,
'timeout': 3000
}]));
});

after(() => {
configObj.setConfig({ priceGranularity: currentPriceBucket });
adaptermanager.makeBidRequests.restore();
})

afterEach(() => {
ajaxStub.restore();
});

it('should get correct hb_pb with cpm between 0 - 5', () => {
initTestConfig({
adUnits: [createAdUnit('div-gpt-ad-1460505748561-0')],
adUnitCodes: ['div-gpt-ad-1460505748561-0']
});

response = bannerResponse;
response.tags[0].ads[0].cpm = 3.4288;

auction.callBids(cbTimeout);
let bidTargeting = targeting.getAllTargeting();
expect(bidTargeting['div-gpt-ad-1460505748561-0']['hb_pb']).to.equal('3.25');
});

it('should get correct hb_pb with cpm between 21 - 100', () => {
initTestConfig({
adUnits: [createAdUnit('div-gpt-ad-1460505748561-0')],
adUnitCodes: ['div-gpt-ad-1460505748561-0']
});

response = bannerResponse;
response.tags[0].ads[0].cpm = 43.4288;

auction.callBids(cbTimeout);
let bidTargeting = targeting.getAllTargeting();
expect(bidTargeting['div-gpt-ad-1460505748561-0']['hb_pb']).to.equal('43.00');
});

it('should only apply price granularity if bid media type matches', () => {
initTestConfig({
adUnits: [ createAdUnit('div-gpt-ad-1460505748561-0', 'video') ],
adUnitCodes: ['div-gpt-ad-1460505748561-0']
});

response = videoResponse;
response.tags[0].ads[0].cpm = 3.4288;

auction.callBids(cbTimeout);
let bidTargeting = targeting.getAllTargeting();
expect(bidTargeting['div-gpt-ad-1460505748561-0']['hb_pb']).to.equal('3.00');
});
});

describe('getBidResponses', function () {
it('should return expected bid responses when not passed an adunitCode', function () {
var result = $$PREBID_GLOBAL$$.getBidResponses();
Expand Down

0 comments on commit fc76379

Please sign in to comment.