From e597bbe92581c1867ff4b4d860489b8896d0ff8d Mon Sep 17 00:00:00 2001 From: pm-nitin-shirsat <107102698+pm-nitin-shirsat@users.noreply.github.com> Date: Mon, 15 Aug 2022 19:28:30 +0530 Subject: [PATCH] Pubmatic bid adapter: improved site object handling (#8820) * 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 --- modules/pubmaticBidAdapter.js | 6 ++- test/spec/modules/pubmaticBidAdapter_spec.js | 57 ++++++++++++++++++-- 2 files changed, 58 insertions(+), 5 deletions(-) diff --git a/modules/pubmaticBidAdapter.js b/modules/pubmaticBidAdapter.js index 922fedd5092..b71fa5c8ed2 100644 --- a/modules/pubmaticBidAdapter.js +++ b/modules/pubmaticBidAdapter.js @@ -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; @@ -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}); diff --git a/test/spec/modules/pubmaticBidAdapter_spec.js b/test/spec/modules/pubmaticBidAdapter_spec.js index f3a49a6a925..688bec5b5e9 100644 --- a/test/spec/modules/pubmaticBidAdapter_spec.js +++ b/test/spec/modules/pubmaticBidAdapter_spec.js @@ -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'; @@ -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']); });