Skip to content

Commit

Permalink
DFP video adserver module: set description_url to pub's URL by defa…
Browse files Browse the repository at this point in the history
…ult; do not skip setting it if `cache.url` is set (prebid#9665)
  • Loading branch information
dgirardi authored and jorgeluisrocha committed May 18, 2023
1 parent 6e64b55 commit d8c0bad
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
16 changes: 8 additions & 8 deletions modules/dfpAdServerVideo.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { gdprDataHandler, uspDataHandler, gppDataHandler } from '../src/adapterM
import * as events from '../src/events.js';
import CONSTANTS from '../src/constants.json';
import {getPPID} from '../src/adserver.js';
import {getRefererInfo} from '../src/refererDetection.js';

/**
* @typedef {Object} DfpVideoParams
Expand Down Expand Up @@ -52,6 +53,10 @@ const defaultParamConstants = {

export const adpodUtils = {};

export const dep = {
ri: getRefererInfo
}

/**
* Merge all the bid data and publisher-supplied options into a single URL, and then return it.
*
Expand Down Expand Up @@ -259,14 +264,7 @@ function buildUrlFromAdserverUrlComponents(components, bid, options) {
* @return {string | undefined} The encoded vast url if it exists, or undefined
*/
function getDescriptionUrl(bid, components, prop) {
if (config.getConfig('cache.url')) { return; }

if (!deepAccess(components, `${prop}.description_url`)) {
const vastUrl = bid && bid.vastUrl;
if (vastUrl) { return encodeURIComponent(vastUrl); }
} else {
logError(`input cannnot contain description_url`);
}
return deepAccess(components, `${prop}.description_url`) || dep.ri().page;
}

/**
Expand All @@ -293,6 +291,8 @@ function getCustParams(bid, options, urlCustParams) {
allTargetingData,
adserverTargeting,
);

// TODO: WTF is this? just firing random events, guessing at the argument, hoping noone notices?
events.emit(CONSTANTS.EVENTS.SET_TARGETING, {[adUnit.code]: prebidTargetingSet});

// merge the prebid + publisher targeting sets
Expand Down
40 changes: 36 additions & 4 deletions test/spec/modules/dfpAdServerVideo_spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';

import parse from 'url-parse';
import { buildDfpVideoUrl, buildAdpodVideoUrl } from 'modules/dfpAdServerVideo.js';
import {buildDfpVideoUrl, buildAdpodVideoUrl, dep} from 'modules/dfpAdServerVideo.js';
import adUnit from 'test/fixtures/video/adUnit.json';
import * as utils from 'src/utils.js';
import { config } from 'src/config.js';
Expand All @@ -13,6 +13,7 @@ import { server } from 'test/mocks/xhr.js';
import * as adServer from 'src/adserver.js';
import {deepClone} from 'src/utils.js';
import {hook} from '../../../src/hook.js';
import {getRefererInfo} from '../../../src/refererDetection.js';

const bid = {
videoCacheKey: 'abc',
Expand All @@ -27,6 +28,40 @@ describe('The DFP video support module', function () {
hook.ready();
});

let sandbox;

beforeEach(() => {
sandbox = sinon.sandbox.create();
});

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

Object.entries({
params: {
params: {
'iu': 'my/adUnit'
}
},
url: {
url: 'https://some-example-url.com'
}
}).forEach(([t, options]) => {
describe(`when using ${t}`, () => {
it('should use page location as default for description_url', () => {
sandbox.stub(dep, 'ri').callsFake(() => ({page: 'example.com'}));

const url = parse(buildDfpVideoUrl(Object.assign({
adUnit: adUnit,
bid: bid,
}, options)));
const prm = utils.parseQS(url.query);
expect(prm.description_url).to.eql('example.com');
})
})
})

it('should make a legal request URL when given the required params', function () {
const url = parse(buildDfpVideoUrl({
adUnit: adUnit,
Expand Down Expand Up @@ -63,9 +98,6 @@ describe('The DFP video support module', function () {
}));

expect(url.host).to.equal('video.adserver.example');

const queryObject = utils.parseQS(url.query);
expect(queryObject.description_url).to.equal('vastUrl.example');
});

it('requires a params object or url', function () {
Expand Down

0 comments on commit d8c0bad

Please sign in to comment.