Skip to content

Commit

Permalink
added tests for debug auction
Browse files Browse the repository at this point in the history
  • Loading branch information
aneuway2 committed Aug 27, 2018
1 parent 995e90c commit 32c6c80
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 54 deletions.
59 changes: 37 additions & 22 deletions modules/appnexusBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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(/(?:<td>|<th>)*(<br>)(\n)/gm,'\n\t\t') // Table <br>
.replace(/(<td>|<th>)/gm,'\t') // Tables
.replace(/^<br>/gm,'') // Remove leading <br>
.replace(/(<br>\n|<br>)/gm,'\n') // <br>
.replace(/<h1>(.*)<\/h1>/gm,'\n\n===== $1 =====\n\n') // Header H1
.replace(/<h[2-6]>(.*)<\/h[2-6]>/gm,'\n\n*** $1 ***\n\n') // Headers
.replace(/(<td>|<th>)/gm, '\t') // Tables
.replace(/(<\/td>|<\/th>)/gm, '\n') // Tables
.replace(/^<br>/gm, '') // Remove leading <br>
.replace(/(<br>\n|<br>)/gm, '\n') // <br>
.replace(/<h1>(.*)<\/h1>/gm, '\n\n===== $1 =====\n\n') // Header H1
.replace(/<h[2-6]>(.*)<\/h[2-6]>/gm, '\n\n*** $1 ***\n\n') // Headers
.replace(/(<([^>]+)>)/igm, ''); // Remove any other tags
utils.logMessage(debugText);
}
Expand Down Expand Up @@ -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];
Expand Down
47 changes: 15 additions & 32 deletions test/spec/modules/appnexusBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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': '<html><body>Debug Auction HTML</body></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'
});*/
});
});
});

0 comments on commit 32c6c80

Please sign in to comment.