From be6f32efe1f45f00f9c5dc27efa33eb1fde049dc Mon Sep 17 00:00:00 2001 From: Faisal Islam Date: Mon, 28 Mar 2022 17:30:00 +0600 Subject: [PATCH 1/2] HBT-170: Fixed a couple of code issue --- modules/improvedigitalBidAdapter.js | 38 +++++++---- .../modules/improvedigitalBidAdapter_spec.js | 64 +++++++++++++++++++ 2 files changed, 88 insertions(+), 14 deletions(-) diff --git a/modules/improvedigitalBidAdapter.js b/modules/improvedigitalBidAdapter.js index a7ae3c7be58..96574c0ee55 100644 --- a/modules/improvedigitalBidAdapter.js +++ b/modules/improvedigitalBidAdapter.js @@ -131,22 +131,9 @@ export const spec = { if (typeof bidderRequest.uspConsent !== typeof undefined) { deepSetValue(request, 'regs.ext.us_privacy', bidderRequest.uspConsent); } - // Site - const url = config.getConfig('pageUrl') || deepAccess(bidderRequest, 'refererInfo.referer'); - const urlObj = parseUrl(url); - deepSetValue(request, 'site.page', url); - deepSetValue(request, 'site.domain', urlObj && urlObj.hostname); } - // First party data - const fpd = config.getConfig('ortb2'); - if (fpd) { - if (fpd.site) { - request.site = request.site ? {...request.site, ...fpd.site} : fpd.site; - } else if (fpd.app) { - request.app = fpd.app; - } - } + ID_REQUEST.buildSiteOrApp(request, bidderRequest); const bidRequest0 = bidRequests[0]; @@ -422,6 +409,29 @@ const ID_REQUEST = { } return null; }, + + buildSiteOrApp(request, bidderRequest) { + const app = {}; + const configAppSettings = config.getConfig('app') || {}; + const fpdAppSettings = config.getConfig('ortb2.app') || {}; + mergeDeep(app, configAppSettings, fpdAppSettings); + + if (Object.keys(app).length !== 0) { + request.app = app; + } else { + const site = {}; + const url = config.getConfig('pageUrl') || deepAccess(bidderRequest, 'refererInfo.referer'); + if (url) { + site['page'] = url; + const urlObj = parseUrl(url); + site['domain'] = urlObj.hostname; + } + const configSiteSettings = config.getConfig('site') || {}; + const fpdSiteSettings = config.getConfig('ortb2.site') || {}; + mergeDeep(site, configSiteSettings, fpdSiteSettings); + request.site = site; + } + }, }; const ID_RESPONSE = { diff --git a/test/spec/modules/improvedigitalBidAdapter_spec.js b/test/spec/modules/improvedigitalBidAdapter_spec.js index 63972f6f7d6..8ee40c6c514 100644 --- a/test/spec/modules/improvedigitalBidAdapter_spec.js +++ b/test/spec/modules/improvedigitalBidAdapter_spec.js @@ -566,6 +566,70 @@ describe('Improve Digital Adapter Tests', function () { expect(payload.imp[0].ext.gpid).to.not.exist; expect(payload.imp[0].instl).to.not.exist; }); + + it('should not set site when app is defined in FPD', function () { + const getConfigStub = sinon.stub(config, 'getConfig'); + getConfigStub.withArgs('ortb2.app').returns({ content: 'XYZ' }); + let request = spec.buildRequests([simpleBidRequest], bidderRequest)[0]; + let payload = JSON.parse(request.data); + expect(payload.site).does.not.exist; + expect(payload.app).does.exist; + expect(payload.app.content).does.exist.and.equal('XYZ'); + getConfigStub.restore(); + }); + + it('should not set site when app is defined in CONFIG', function () { + const getConfigStub = sinon.stub(config, 'getConfig'); + getConfigStub.withArgs('app').returns({ content: 'XYZ' }); + let request = spec.buildRequests([simpleBidRequest], bidderRequest)[0]; + let payload = JSON.parse(request.data); + expect(payload.site).does.not.exist; + expect(payload.app).does.exist; + expect(payload.app.content).does.exist.and.equal('XYZ'); + getConfigStub.restore(); + }); + + it('validate site object', function () { + let getConfigStub = sinon.stub(config, 'getConfig'); + getConfigStub.withArgs('site').returns({ + content: 'XYZ', + page: 'https://improveditigal.com/', + domain: 'improveditigal.com' + }); + let request = spec.buildRequests([simpleBidRequest], bidderRequestReferrer)[0]; + let payload = JSON.parse(request.data); + expect(payload.site.content).does.exist.and.equal('XYZ'); + expect(payload.site.page).does.exist.and.equal('https://improveditigal.com/'); + expect(payload.site.domain).does.exist.and.equal('improveditigal.com'); + getConfigStub.restore(); + + request = spec.buildRequests([simpleBidRequest], bidderRequestReferrer)[0]; + payload = JSON.parse(request.data); + expect(payload.site.content).does.not.exist; + expect(payload.site.page).does.exist.and.equal('https://blah.com/test.html'); + expect(payload.site.domain).does.exist.and.equal('blah.com'); + + getConfigStub = sinon.stub(config, 'getConfig'); + getConfigStub.withArgs('ortb2.site').returns({ + content: 'ZZZ', + }); + request = spec.buildRequests([simpleBidRequest], bidderRequestReferrer)[0]; + payload = JSON.parse(request.data); + expect(payload.site.content).does.exist.and.equal('ZZZ'); + expect(payload.site.page).does.exist.and.equal('https://blah.com/test.html'); + expect(payload.site.domain).does.exist.and.equal('blah.com'); + getConfigStub.restore(); + }); + + it('should set site when app not available', function () { + const getConfigStub = sinon.stub(config, 'getConfig'); + getConfigStub.withArgs('app').returns(undefined); + let request = spec.buildRequests([simpleBidRequest], bidderRequest)[0]; + let payload = JSON.parse(request.data); + expect(payload.site).does.exist; + expect(payload.app).does.not.exist; + getConfigStub.restore(); + }); }); const serverResponse = { From 857e4c9c86fd47276e847a04ce9a480e4eb3f99b Mon Sep 17 00:00:00 2001 From: Faisal Islam Date: Wed, 30 Mar 2022 12:57:29 +0600 Subject: [PATCH 2/2] Code refactored and added test case for pageUrl --- modules/improvedigitalBidAdapter.js | 5 ++--- .../modules/improvedigitalBidAdapter_spec.js | 20 ++++++++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/modules/improvedigitalBidAdapter.js b/modules/improvedigitalBidAdapter.js index 96574c0ee55..c696dabc64a 100644 --- a/modules/improvedigitalBidAdapter.js +++ b/modules/improvedigitalBidAdapter.js @@ -422,9 +422,8 @@ const ID_REQUEST = { const site = {}; const url = config.getConfig('pageUrl') || deepAccess(bidderRequest, 'refererInfo.referer'); if (url) { - site['page'] = url; - const urlObj = parseUrl(url); - site['domain'] = urlObj.hostname; + site.page = url; + site.domain = parseUrl(url).hostname; } const configSiteSettings = config.getConfig('site') || {}; const fpdSiteSettings = config.getConfig('ortb2.site') || {}; diff --git a/test/spec/modules/improvedigitalBidAdapter_spec.js b/test/spec/modules/improvedigitalBidAdapter_spec.js index 8ee40c6c514..7b199b28531 100644 --- a/test/spec/modules/improvedigitalBidAdapter_spec.js +++ b/test/spec/modules/improvedigitalBidAdapter_spec.js @@ -589,7 +589,7 @@ describe('Improve Digital Adapter Tests', function () { getConfigStub.restore(); }); - it('validate site object', function () { + it('should set correct site params', function () { let getConfigStub = sinon.stub(config, 'getConfig'); getConfigStub.withArgs('site').returns({ content: 'XYZ', @@ -621,6 +621,24 @@ describe('Improve Digital Adapter Tests', function () { getConfigStub.restore(); }); + it('should set pageUrl as site param', function () { + let getConfigStub = sinon.stub(config, 'getConfig'); + getConfigStub.withArgs('pageUrl').returns('https://improvidigital.com/test-page'); + let request = spec.buildRequests([simpleBidRequest], bidderRequestReferrer)[0]; + let payload = JSON.parse(request.data); + expect(payload.site.page).does.exist.and.equal('https://improvidigital.com/test-page'); + expect(payload.site.domain).does.exist.and.equal('improvidigital.com'); + getConfigStub.restore(); + + getConfigStub = sinon.stub(config, 'getConfig'); + getConfigStub.withArgs('pageUrl').returns(undefined); + request = spec.buildRequests([simpleBidRequest], bidderRequestReferrer)[0]; + payload = JSON.parse(request.data); + expect(payload.site.page).does.exist.and.equal('https://blah.com/test.html'); + expect(payload.site.domain).does.exist.and.equal('blah.com'); + getConfigStub.restore(); + }); + it('should set site when app not available', function () { const getConfigStub = sinon.stub(config, 'getConfig'); getConfigStub.withArgs('app').returns(undefined);