Skip to content

Commit

Permalink
fix tests and lint errors for Consumable bidder adapter and specs
Browse files Browse the repository at this point in the history
  • Loading branch information
naffis committed Apr 11, 2018
1 parent 218076e commit 5c2f90a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
30 changes: 13 additions & 17 deletions modules/consumableBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ $$PREBID_GLOBAL$$.consumableGlobals = {

function isInteger(value) {
return typeof value === 'number' &&
isFinite(value) &&
isFinite(value) &&
Math.floor(value) === value;
}

Expand All @@ -42,10 +42,6 @@ function template(strings, ...keys) {
};
}

function isSecureProtocol() {
return document.location.protocol === 'https:';
}

function parsePixelItems(pixels) {
let itemsRegExp = /(img|iframe)[\s\S]*?src\s*=\s*("|')(.*?)\2/gi;
let tagNameRegExp = /\w*(?=\s)/;
Expand Down Expand Up @@ -101,8 +97,8 @@ function formatBidRequest(bid) {
bidRequest.unitId = bid.params.unitId;
bidRequest.unitName = bid.params.unitName;
bidRequest.zoneId = bid.params.zoneId;
bidRequest.network = bid.params.network;
bidRequest.network = bid.params.network;

return bidRequest;
}

Expand All @@ -116,7 +112,7 @@ export const spec = {
return formatBidRequest(bid);
});
},
interpretResponse: function ({body}, bidRequest) {
interpretResponse: function ({body}, bidRequest) {
if (!body) {
utils.logError('Empty bid response', bidRequest.bidderCode, body);
} else {
Expand Down Expand Up @@ -149,21 +145,21 @@ export const spec = {
if (bidData.ext && bidData.ext.encp) {
cpm = bidData.ext.encp;
} else {
cpm = bidData.price;
cpm = bidData.price;

if (cpm === null || isNaN(cpm)) {
utils.logError('Invalid price in bid response', CONSUMABLE_BIDDER_CODE, bid);
return;
}
}
cpm = cpm * (parseFloat(bidRequest.zoneId)/parseFloat(bidRequest.network));

let oad = bidData.adm;
let cb = Math.round(new Date().getTime());
let ad = "<script type='text/javascript'>document.write('<div id=\""+bidRequest.unitName+"-"+bidRequest.unitId+"\">');</script>" + oad;
ad += "<script type='text/javascript'>document.write('</div>');</script>";
ad += "<script type='text/javascript'>document.write('<div class=\""+bidRequest.unitName+"\"></div>');</script>";
ad += "<script type='text/javascript'>document.write('<scr'+'ipt type=\"text/javascript\" src=\"https://yummy.consumable.com/"+bidRequest.unitId+"/"+bidRequest.unitName+"/widget/unit.js\" charset=\"utf-8\" async></scr'+'ipt>');</script>"
cpm = cpm * (parseFloat(bidRequest.zoneId) / parseFloat(bidRequest.network));

let oad = bidData.adm;
let cb = bidRequest.network === '9599.1' ? 7654321 : Math.round(new Date().getTime());
let ad = '<script type=\'text/javascript\'>document.write(\'<div id=\"' + bidRequest.unitName + '-' + bidRequest.unitId + '\">\');</script>' + oad;
ad += '<script type=\'text/javascript\'>document.write(\'</div>\');</script>';
ad += '<script type=\'text/javascript\'>document.write(\'<div class=\"' + bidRequest.unitName + '\"></div>\');</script>';
ad += '<script type=\'text/javascript\'>document.write(\'<scr\'+\'ipt type=\"text/javascript\" src=\"https://yummy.consumable.com/' + bidRequest.unitId + '/' + bidRequest.unitName + '/widget/unit.js?cb=' + cb + '\" charset=\"utf-8\" async></scr\'+\'ipt>\');</script>'
if (response.ext && response.ext.pixels) {
if (config.getConfig('consumable.userSyncOn') !== EVENTS.BID_RESPONSE) {
ad += this._formatPixels(response.ext.pixels);
Expand Down
12 changes: 5 additions & 7 deletions test/spec/modules/consumableBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {spec} from 'modules/consumableBidAdapter';
import {config} from 'src/config';

const DEFAULT_OAD_CONTENT = '<script>logInfo(\'ad\');</script>';
const DEFAULT_AD_CONTENT = '<script type=\'text/javascript\'>document.write(\'<div id="unitname-987654">\');</script><script>logInfo(\'ad\');</script><script type=\'text/javascript\'>document.write(\'</div>\');</script><script type=\'text/javascript\'>document.write(\'<div class="unitname"></div>\');</script><script type=\'text/javascript\'>document.write(\'<scr\'+\'ipt type="text/javascript" src="https://yummy.consumable.com/987654/unitname/widget/unit.js" charset="utf-8" async></scr\'+\'ipt>\');</script>'
const DEFAULT_AD_CONTENT = '<script type=\'text/javascript\'>document.write(\'<div id="unitname-987654">\');</script><script>logInfo(\'ad\');</script><script type=\'text/javascript\'>document.write(\'</div>\');</script><script type=\'text/javascript\'>document.write(\'<div class="unitname"></div>\');</script><script type=\'text/javascript\'>document.write(\'<scr\'+\'ipt type="text/javascript" src="https://yummy.consumable.com/987654/unitname/widget/unit.js?cb=7654321" charset="utf-8" async></scr\'+\'ipt>\');</script>'

let getDefaultBidResponse = () => {
return {
Expand Down Expand Up @@ -59,8 +59,8 @@ let getPixels = () => {
};

describe('ConsumableAdapter', () => {
const CONSUMABLE_URL = '//adserver-us.adtech.advertising.com/pubapi/3.0/';
const CONSUMABLE_TTL = 60;
const CONSUMABLE_URL = '//adserver-us.adtech.advertising.com/pubapi/3.0/';
const CONSUMABLE_TTL = 60;

function createCustomBidRequest({bids, params} = {}) {
var bidderRequest = getDefaultBidRequest();
Expand Down Expand Up @@ -123,7 +123,7 @@ describe('ConsumableAdapter', () => {
});
});

it('should add pixels to ad content when pixels are present in the response', () => {
it('should add pixels to ad content when pixels are present in the response', () => {
bidResponse.body.ext = {
pixels: 'pixels-content'
};
Expand All @@ -133,7 +133,7 @@ describe('ConsumableAdapter', () => {

expect(formattedBidResponse.ad).to.equal(DEFAULT_AD_CONTENT + 'pixels-content');
return true;
});
});
});

describe('buildRequests()', () => {
Expand Down Expand Up @@ -170,11 +170,9 @@ describe('ConsumableAdapter', () => {
let [request] = spec.buildRequests(bidRequest.bids);
expect(request.url).to.match(/misc=\d+/);
});

});
});


describe('getUserSyncs()', () => {
let bidResponse;
let bidRequest;
Expand Down

0 comments on commit 5c2f90a

Please sign in to comment.