Skip to content

Commit

Permalink
Pubmatic bid adapter: improved site object handling (prebid#8820)
Browse files Browse the repository at this point in the history
* UOE-7836: Vanilla JS: Stop overwriting site.page site.ref and site.domain

* UOE-7836: Vanilla JS: Stop overwriting site.page site.ref and site.domain in PrebidServerBidAdapter

* Rename variable name

* Revert changes from PrebidServerBidAdapter file

* Test cases written for the ticket UOE-7666 - stop overriding page, domain, site
  • Loading branch information
pm-nitin-shirsat authored Aug 15, 2022
1 parent d836669 commit 9eda78a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 5 deletions.
6 changes: 5 additions & 1 deletion modules/pubmaticBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ _each(NATIVE_ASSETS, anAsset => { NATIVE_ASSET_ID_TO_KEY_MAP[anAsset.ID] = anAss
// loading NATIVE_ASSET_KEY_TO_ASSET_MAP
_each(NATIVE_ASSETS, anAsset => { NATIVE_ASSET_KEY_TO_ASSET_MAP[anAsset.KEY] = anAsset });

function _getDomainFromURL(url) {
export function _getDomainFromURL(url) {
let anchor = document.createElement('a');
anchor.href = url;
return anchor.hostname;
Expand Down Expand Up @@ -1162,7 +1162,11 @@ export const spec = {
// First Party Data
const commonFpd = (bidderRequest && bidderRequest.ortb2) || {};
if (commonFpd.site) {
const { page, domain, ref } = payload.site;
mergeDeep(payload, {site: commonFpd.site});
payload.site.page = page;
payload.site.domain = domain;
payload.site.ref = ref;
}
if (commonFpd.user) {
mergeDeep(payload, {user: commonFpd.user});
Expand Down
57 changes: 53 additions & 4 deletions test/spec/modules/pubmaticBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {expect} from 'chai';
import {spec, checkVideoPlacement} from 'modules/pubmaticBidAdapter.js';
import {spec, checkVideoPlacement, _getDomainFromURL} from 'modules/pubmaticBidAdapter.js';
import * as utils from 'src/utils.js';
import {config} from 'src/config.js';
import { createEidsArray } from 'modules/userId/eids.js';
Expand Down Expand Up @@ -1688,17 +1688,66 @@ describe('PubMatic adapter', function () {
describe('FPD', function() {
let newRequest;

it('ortb2.site should be merged in the request', function() {
describe('ortb2.site should not override page, domain & ref values', function() {
it('When above properties are present in ortb2.site', function() {
const ortb2 = {
site: {
domain: 'page.example.com',
page: 'https://page.example.com/here.html',
ref: 'https://page.example.com/here.html'
}
};
const request = spec.buildRequests(bidRequests, {ortb2});
let data = JSON.parse(request.data);
expect(data.site.domain).not.equal('page.example.com');
expect(data.site.page).not.equal('https://page.example.com/here.html');
expect(data.site.ref).not.equal('https://page.example.com/here.html');
});

it('When above properties are absent in ortb2.site', function () {
const ortb2 = {
site: {}
};
let request = spec.buildRequests(bidRequests, {
auctionId: 'new-auction-id',
ortb2
});
let data = JSON.parse(request.data);
let response = spec.interpretResponse(bidResponses, request);
expect(data.site.page).to.equal(bidRequests[0].params.kadpageurl);
expect(data.site.domain).to.equal(_getDomainFromURL(data.site.page));
expect(response[0].referrer).to.equal(data.site.ref);
});

it('With some extra properties in ortb2.site', function() {
const ortb2 = {
site: {
domain: 'page.example.com',
page: 'https://page.example.com/here.html',
ref: 'https://page.example.com/here.html',
cat: ['IAB2'],
sectioncat: ['IAB2-2']
}
};
const request = spec.buildRequests(bidRequests, {ortb2});
let data = JSON.parse(request.data);
expect(data.site.domain).not.equal('page.example.com');
expect(data.site.page).not.equal('https://page.example.com/here.html');
expect(data.site.ref).not.equal('https://page.example.com/here.html');
expect(data.site.cat).to.deep.equal(['IAB2']);
expect(data.site.sectioncat).to.deep.equal(['IAB2-2']);
});
});

it('ortb2.site should be merged except page, domain & ref in the request', function() {
const ortb2 = {
site: {
domain: 'page.example.com',
cat: ['IAB2'],
sectioncat: ['IAB2-2']
}
};
const request = spec.buildRequests(bidRequests, {ortb2});
let data = JSON.parse(request.data);
expect(data.site.domain).to.equal('page.example.com');
expect(data.site.cat).to.deep.equal(['IAB2']);
expect(data.site.sectioncat).to.deep.equal(['IAB2-2']);
});
Expand Down

0 comments on commit 9eda78a

Please sign in to comment.