From da20594db1078053039fc7622a143e3d045d718b Mon Sep 17 00:00:00 2001 From: Andrew Andrew Bowman Date: Thu, 23 Aug 2018 19:41:54 +0000 Subject: [PATCH 1/3] push for testing --- modules/appnexusBidAdapter.js | 55 ++++++++++++++++++++ test/spec/modules/appnexusBidAdapter_spec.js | 43 +++++++++++++++ 2 files changed, 98 insertions(+) diff --git a/modules/appnexusBidAdapter.js b/modules/appnexusBidAdapter.js index 7dac4b8b182..5d969a14998 100644 --- a/modules/appnexusBidAdapter.js +++ b/modules/appnexusBidAdapter.js @@ -11,6 +11,7 @@ const VIDEO_TARGETING = ['id', 'mimes', 'minduration', 'maxduration', 'startdelay', 'skippable', 'playback_method', 'frameworks']; const USER_PARAMS = ['age', 'external_uid', 'segments', 'gender', 'dnt', 'language']; const APP_DEVICE_PARAMS = ['geo', 'device_id']; // appid is collected separately +const AST_DEBUG = ['ast_debug', 'ast_dongle', 'ast_debug_member', 'ast_debug_timeout'] const NATIVE_MAPPING = { body: 'description', cta: 'ctatext', @@ -77,6 +78,28 @@ export const spec = { }; } + const debugObjParams = getURLparams(); + let debugObj = {}; + if (debugObjParams && debugObjParams.params) { + Object.keys(debugObjParams.params) + .filter(param => includes(AST_DEBUG, param)) + .forEach(param => { + debugObj['debug'] = debugObj['debug'] || { + 'enabled': true + } + if (param == 'ast_dongle'){ + debugObj['debug']['dongle'] = debugObjParams.params[param]; + } + if (param == 'ast_debug_member'){ + debugObj['debug']['member_id'] = 958 ? parseInt(debugObjParams.params[param], 10) : 0; + } + if (param == 'ast_debug_timeout'){ + debugObj['debug']['debug_timeout'] = 3000 ? parseInt(debugObjParams.params[param], 10) : 0; + } + } + ); + } + const memberIdBid = find(bidRequests, hasMemberId); const member = memberIdBid ? parseInt(memberIdBid.params.member, 10) : 0; @@ -99,6 +122,10 @@ export const spec = { payload.app = appIdObj; } + if (debugObj && debugObj.debug) { + payload.debug = debugObj.debug + } + if (bidderRequest && bidderRequest.gdprConsent) { // note - objects for impbus use underscore instead of camelCase payload.gdpr_consent = { @@ -144,6 +171,21 @@ export const spec = { } }); } + + if (serverResponse.debug && serverResponse.debug.debug_info) { + let title = 'AppNexus Debug Auction for Prebid' + let debugHTML = '' +title+ '

' + title + '

' + serverResponse.debug.debug_info + ''; + debugHTML = debugHTML.replace(/(.*)([^>])$/gm,"$1$2
").replace(/(\t)/gm, ''); // Format newlines and tabs + let debugStream = debugHTML.split('\n'); + + utils.logMessage('AppNexus debug auction for prebid was opened in new tab'); + let debugWindow = window.open(); + for (var ln in debugStream){ + debugWindow.document.write(debugStream[ln]); + } + setTimeout(function() { debugWindow.document.close() }, 1000); // Close the debugStream + } + return bids; }, @@ -419,6 +461,19 @@ function hasAppId(bid) { return !!bid.params.app } +function getURLparams() { + let obj = {}; + if (utils.getTopWindowLocation() && utils.getTopWindowLocation().search){ + obj['params'] = {}; + utils.getTopWindowLocation().search.substr(1).split('&').forEach(keyvalue => { + let key = keyvalue.split('=')[0]; + let val = keyvalue.split('=')[1]; + obj['params'][key] = val + }); + } + return obj +} + function getRtbBid(tag) { return tag && tag.ads && tag.ads.length && find(tag.ads, ad => ad.rtb); } diff --git a/test/spec/modules/appnexusBidAdapter_spec.js b/test/spec/modules/appnexusBidAdapter_spec.js index b65988e3ec1..9bee2c0a0ea 100644 --- a/test/spec/modules/appnexusBidAdapter_spec.js +++ b/test/spec/modules/appnexusBidAdapter_spec.js @@ -370,6 +370,24 @@ describe('AppNexusAdapter', () => { lng: -75.3009142 }); }); + + it('sends a debug auction', () => { + sandbox = sinon.sandbox.create(); + sandbox.stub(utils, 'getTopWindowLocation').callsFake(() => { + return { + 'search': '?pbjs_debug=true&ast_debug=true&ast_dongle=QWERTY&ast_debug_member=958&ast_debug_timeout=1000' + }; + }); + const request = spec.buildRequests([bidRequests[0]]); + const payload = JSON.parse(request.data); + expect(payload.debug).to.exist; + expect(payload.debug).to.deep.equal({ + enabled: true, + dongle: 'QWERTY', + member_id: 958, + debug_timeout: 1000 + }); + }); }) describe('interpretResponse', () => { @@ -535,5 +553,30 @@ describe('AppNexusAdapter', () => { bidderRequest.bids[0].renderer.options ); }); + + it('returns a debug auction', () => { + describe('interpretResponse', () => { + let response = { + 'version': '0.0.1', + 'tags': [{ + 'uuid': '84ab500420319d', + 'tag_id': 5976557, + 'auction_id': '297492697822162468', + 'nobid': true + }], + 'debug': { + 'debug_info': 'Debug Auction HTML', + 'request_time' : 32786.428 + } + }; + let bidderRequest; + + let result = spec.interpretResponse({ body: response }, {bidderRequest}); + + expect(result[0].debug).to.exist; + /*expect(payload.app).to.deep.equal({ + appid: 'B1O2W3M4AN.com.prebid.webview' + });*/ + }); }); }); From 995e90cd3129fd1bf2e225e38d1eef93eb1200d2 Mon Sep 17 00:00:00 2001 From: Andrew Andrew Bowman Date: Mon, 27 Aug 2018 03:18:43 +0000 Subject: [PATCH 2/3] switch to console.log instead of window.open --- modules/appnexusBidAdapter.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/modules/appnexusBidAdapter.js b/modules/appnexusBidAdapter.js index 5d969a14998..ca3e0572205 100644 --- a/modules/appnexusBidAdapter.js +++ b/modules/appnexusBidAdapter.js @@ -173,17 +173,17 @@ export const spec = { } if (serverResponse.debug && serverResponse.debug.debug_info) { - let title = 'AppNexus Debug Auction for Prebid' - let debugHTML = '' +title+ '

' + title + '

' + serverResponse.debug.debug_info + ''; - debugHTML = debugHTML.replace(/(.*)([^>])$/gm,"$1$2
").replace(/(\t)/gm, ''); // Format newlines and tabs - let debugStream = debugHTML.split('\n'); - - utils.logMessage('AppNexus debug auction for prebid was opened in new tab'); - let debugWindow = window.open(); - for (var ln in debugStream){ - debugWindow.document.write(debugStream[ln]); - } - setTimeout(function() { debugWindow.document.close() }, 1000); // Close the debugStream + let debugHeader = 'AppNexus Debug Auction for Prebid\n\n' + let debugText = debugHeader + serverResponse.debug.debug_info + debugText = debugText + .replace(/(?:|)*(
)(\n)/gm,'\n\t\t') // Table
+ .replace(/(|)/gm,'\t') // Tables + .replace(/^
/gm,'') // Remove leading
+ .replace(/(
\n|
)/gm,'\n') //
+ .replace(/

(.*)<\/h1>/gm,'\n\n===== $1 =====\n\n') // Header H1 + .replace(/(.*)<\/h[2-6]>/gm,'\n\n*** $1 ***\n\n') // Headers + .replace(/(<([^>]+)>)/igm, ''); // Remove any other tags + utils.logMessage(debugText); } return bids; From 32c6c80327e30fb261ffff1e9bbdb07ced408d7c Mon Sep 17 00:00:00 2001 From: Andrew Bowman Date: Mon, 27 Aug 2018 14:44:54 -0400 Subject: [PATCH 3/3] added tests for debug auction --- modules/appnexusBidAdapter.js | 59 ++++++++++++-------- test/spec/modules/appnexusBidAdapter_spec.js | 47 +++++----------- 2 files changed, 52 insertions(+), 54 deletions(-) diff --git a/modules/appnexusBidAdapter.js b/modules/appnexusBidAdapter.js index ca3e0572205..01f45d30413 100644 --- a/modules/appnexusBidAdapter.js +++ b/modules/appnexusBidAdapter.js @@ -11,7 +11,8 @@ const VIDEO_TARGETING = ['id', 'mimes', 'minduration', 'maxduration', 'startdelay', 'skippable', 'playback_method', 'frameworks']; const USER_PARAMS = ['age', 'external_uid', 'segments', 'gender', 'dnt', 'language']; const APP_DEVICE_PARAMS = ['geo', 'device_id']; // appid is collected separately -const AST_DEBUG = ['ast_debug', 'ast_dongle', 'ast_debug_member', 'ast_debug_timeout'] +const AST_DEBUG_URL = ['ast_debug', 'ast_dongle', 'ast_debug_member', 'ast_debug_timeout'] +const AST_DEBUG_PARAMS = ['enabled', 'dongle', 'member_id', 'debug_timeout'] const NATIVE_MAPPING = { body: 'description', cta: 'ctatext', @@ -78,26 +79,36 @@ export const spec = { }; } - const debugObjParams = getURLparams(); let debugObj = {}; - if (debugObjParams && debugObjParams.params) { - Object.keys(debugObjParams.params) - .filter(param => includes(AST_DEBUG, param)) + const debugObjParams = find(bidRequests, hasDebug); + if (debugObjParams && debugObjParams.debug) { + Object.keys(debugObjParams.debug) + .filter(param => includes(AST_DEBUG_PARAMS, param)) .forEach(param => { - debugObj['debug'] = debugObj['debug'] || { - 'enabled': true + debugObj['debug'] = debugObj['debug'] || {}; + debugObj.debug[param] = debugObjParams.debug[param] + }); + } + + const debugUrlParams = getURLparams(); + if (debugUrlParams && debugUrlParams.params) { + Object.keys(debugUrlParams.params) + .filter(param => includes(AST_DEBUG_URL, param)) + .forEach(param => { + debugObj['debug'] = debugObj['debug'] || {}; + if (param == 'ast_debug') { + debugObj['debug']['enabled'] = (debugUrlParams.params[param] === 'true'); } - if (param == 'ast_dongle'){ - debugObj['debug']['dongle'] = debugObjParams.params[param]; + if (param == 'ast_dongle') { + debugObj['debug']['dongle'] = debugUrlParams.params[param]; } - if (param == 'ast_debug_member'){ - debugObj['debug']['member_id'] = 958 ? parseInt(debugObjParams.params[param], 10) : 0; + if (param == 'ast_debug_member') { + debugObj['debug']['member_id'] = parseInt(debugUrlParams.params[param], 10); } - if (param == 'ast_debug_timeout'){ - debugObj['debug']['debug_timeout'] = 3000 ? parseInt(debugObjParams.params[param], 10) : 0; + if (param == 'ast_debug_timeout') { + debugObj['debug']['debug_timeout'] = parseInt(debugUrlParams.params[param], 10); } - } - ); + }); } const memberIdBid = find(bidRequests, hasMemberId); @@ -176,12 +187,12 @@ export const spec = { let debugHeader = 'AppNexus Debug Auction for Prebid\n\n' let debugText = debugHeader + serverResponse.debug.debug_info debugText = debugText - .replace(/(?:|)*(
)(\n)/gm,'\n\t\t') // Table
- .replace(/(|)/gm,'\t') // Tables - .replace(/^
/gm,'') // Remove leading
- .replace(/(
\n|
)/gm,'\n') //
- .replace(/

(.*)<\/h1>/gm,'\n\n===== $1 =====\n\n') // Header H1 - .replace(/(.*)<\/h[2-6]>/gm,'\n\n*** $1 ***\n\n') // Headers + .replace(/(|)/gm, '\t') // Tables + .replace(/(<\/td>|<\/th>)/gm, '\n') // Tables + .replace(/^
/gm, '') // Remove leading
+ .replace(/(
\n|
)/gm, '\n') //
+ .replace(/

(.*)<\/h1>/gm, '\n\n===== $1 =====\n\n') // Header H1 + .replace(/(.*)<\/h[2-6]>/gm, '\n\n*** $1 ***\n\n') // Headers .replace(/(<([^>]+)>)/igm, ''); // Remove any other tags utils.logMessage(debugText); } @@ -461,9 +472,13 @@ function hasAppId(bid) { return !!bid.params.app } +function hasDebug(bid) { + return !!bid.debug +} + function getURLparams() { let obj = {}; - if (utils.getTopWindowLocation() && utils.getTopWindowLocation().search){ + if (utils.getTopWindowLocation() && utils.getTopWindowLocation().search) { obj['params'] = {}; utils.getTopWindowLocation().search.substr(1).split('&').forEach(keyvalue => { let key = keyvalue.split('=')[0]; diff --git a/test/spec/modules/appnexusBidAdapter_spec.js b/test/spec/modules/appnexusBidAdapter_spec.js index 9bee2c0a0ea..111d5ad91dd 100644 --- a/test/spec/modules/appnexusBidAdapter_spec.js +++ b/test/spec/modules/appnexusBidAdapter_spec.js @@ -372,13 +372,21 @@ describe('AppNexusAdapter', () => { }); it('sends a debug auction', () => { - sandbox = sinon.sandbox.create(); - sandbox.stub(utils, 'getTopWindowLocation').callsFake(() => { - return { - 'search': '?pbjs_debug=true&ast_debug=true&ast_dongle=QWERTY&ast_debug_member=958&ast_debug_timeout=1000' - }; - }); - const request = spec.buildRequests([bidRequests[0]]); + let debugRequest = Object.assign({}, + bidRequests[0], + { + params: { + placementId: '10433394' + }, + debug: { + enabled: true, + dongle: 'QWERTY', + member_id: 958, + debug_timeout: 1000 + } + } + ); + const request = spec.buildRequests([debugRequest]); const payload = JSON.parse(request.data); expect(payload.debug).to.exist; expect(payload.debug).to.deep.equal({ @@ -553,30 +561,5 @@ describe('AppNexusAdapter', () => { bidderRequest.bids[0].renderer.options ); }); - - it('returns a debug auction', () => { - describe('interpretResponse', () => { - let response = { - 'version': '0.0.1', - 'tags': [{ - 'uuid': '84ab500420319d', - 'tag_id': 5976557, - 'auction_id': '297492697822162468', - 'nobid': true - }], - 'debug': { - 'debug_info': 'Debug Auction HTML', - 'request_time' : 32786.428 - } - }; - let bidderRequest; - - let result = spec.interpretResponse({ body: response }, {bidderRequest}); - - expect(result[0].debug).to.exist; - /*expect(payload.app).to.deep.equal({ - appid: 'B1O2W3M4AN.com.prebid.webview' - });*/ - }); }); });