Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DFP video adserver module: set description_url to pub's URL by default; do not skip setting it if cache.url is set #9665

Merged
merged 1 commit into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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