Skip to content

Commit

Permalink
Telaria Bid Adapter: add adCode & srcPageUrl query string param only …
Browse files Browse the repository at this point in the history
…once. (prebid#4833)

* Set srcPageUrl only once.

* Set adCode only once.
  • Loading branch information
vseventer authored and hellsingblack committed Mar 5, 2020
1 parent e959532 commit 5aa2f09
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
16 changes: 11 additions & 5 deletions modules/telariaBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ export const spec = {
}
};

function getSrcPageUrl(params) {
return (params && params['srcPageUrl']) || encodeURIComponent(document.location.href);
function getDefaultSrcPageUrl() {
return encodeURIComponent(document.location.href);
}

function getEncodedValIfNotEmpty(val) {
Expand Down Expand Up @@ -175,7 +175,10 @@ export const getTimeoutUrl = function(timeoutData) {
if (!utils.isEmpty(params)) {
let url = `https://${EVENTS_ENDPOINT}`;

url += `?srcPageUrl=${getSrcPageUrl(params)}`;
params = Object.assign({
srcPageUrl: getDefaultSrcPageUrl()
}, params);

url += `${getUrlParams(params)}`;

url += '&hb=1&evt=TO';
Expand Down Expand Up @@ -221,9 +224,12 @@ function generateUrl(bid, bidderRequest) {
url += (`&playerHeight=${height}`);
}

url += `${getUrlParams(bid.params, bid.schain)}`;
const params = Object.assign({
srcPageUrl: getDefaultSrcPageUrl()
}, bid.params);
delete params.adCode;

url += `&srcPageUrl=${getSrcPageUrl(bid.params)}`;
url += `${getUrlParams(params, bid.schain)}`;

url += (`&transactionId=${bid.transactionId}`);

Expand Down
40 changes: 33 additions & 7 deletions test/spec/modules/telariaBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ describe('TelariaAdapter', () => {
});

describe('buildRequests', () => {
const stub = [{
const stub = () => ([{
mediaTypes: {
video: {
playerSize: [[640, 480]],
Expand All @@ -131,7 +131,7 @@ describe('TelariaAdapter', () => {
adCode: 'ssp-!demo!-lufip',
videoId: 'MyCoolVideo'
}
}];
}]);

const schainStub = REQUEST_WITH_SCHAIN;

Expand All @@ -140,12 +140,12 @@ describe('TelariaAdapter', () => {
});

it('requires supply code & ad code to make a request', () => {
const tempRequest = spec.buildRequests(stub, BIDDER_REQUEST);
const tempRequest = spec.buildRequests(stub(), BIDDER_REQUEST);
expect(tempRequest.length).to.equal(1);
});

it('generates an array of requests with 4 params, method, url, bidId and vastUrl', () => {
const tempRequest = spec.buildRequests(stub, BIDDER_REQUEST);
const tempRequest = spec.buildRequests(stub(), BIDDER_REQUEST);

expect(tempRequest.length).to.equal(1);
expect(tempRequest[0].method).to.equal('GET');
Expand All @@ -155,15 +155,15 @@ describe('TelariaAdapter', () => {
});

it('doesn\'t require player size but is highly recommended', () => {
let tempBid = stub;
let tempBid = stub();
tempBid[0].mediaTypes.video.playerSize = null;
const tempRequest = spec.buildRequests(tempBid, BIDDER_REQUEST);

expect(tempRequest.length).to.equal(1);
});

it('generates a valid request with sizes as an array of two elements', () => {
let tempBid = stub;
let tempBid = stub();
tempBid[0].mediaTypes.video.playerSize = [640, 480];
tempBid[0].params.adCode = 'ssp-!demo!-lufip';
tempBid[0].params.supplyCode = 'ssp-demo-rm6rh';
Expand All @@ -172,7 +172,7 @@ describe('TelariaAdapter', () => {
});

it('requires ad code and supply code to make a request', () => {
let tempBid = stub;
let tempBid = stub();
tempBid[0].params.adCode = null;
tempBid[0].params.supplyCode = null;

Expand All @@ -188,6 +188,32 @@ describe('TelariaAdapter', () => {
let builtRequests = spec.buildRequests(tempBid, BIDDER_REQUEST);
expect(builtRequests.length).to.equal(1);
});

it('adds adUnitCode to the request url', () => {
const builtRequests = spec.buildRequests(stub(), BIDDER_REQUEST);

expect(builtRequests.length).to.equal(1);
const parts = builtRequests[0].url.split('adCode=');
expect(parts.length).to.equal(2);
});

it('adds srcPageUrl to the request url', () => {
const builtRequests = spec.buildRequests(stub(), BIDDER_REQUEST);

expect(builtRequests.length).to.equal(1);
const parts = builtRequests[0].url.split('srcPageUrl=');
expect(parts.length).to.equal(2);
});

it('adds srcPageUrl from params to the request only once', () => {
const tempBid = stub();
tempBid[0].params.srcPageUrl = 'http://www.test.com';
const builtRequests = spec.buildRequests(tempBid, BIDDER_REQUEST);

expect(builtRequests.length).to.equal(1);
const parts = builtRequests[0].url.split('srcPageUrl=');
expect(parts.length).to.equal(2);
});
});

describe('interpretResponse', () => {
Expand Down

0 comments on commit 5aa2f09

Please sign in to comment.