Skip to content

Commit

Permalink
Switch Adhese adapter to POST method
Browse files Browse the repository at this point in the history
  • Loading branch information
mefjush committed Aug 5, 2020
1 parent c3a193c commit 746f70b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 18 deletions.
29 changes: 18 additions & 11 deletions modules/adheseBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,28 @@ export const spec = {
}
const { gdprConsent, refererInfo } = bidderRequest;

const account = getAccount(validBidRequests);
const targets = validBidRequests.map(bid => bid.params.data).reduce(mergeTargets, {});
const gdprParams = (gdprConsent && gdprConsent.consentString) ? [`xt${gdprConsent.consentString}`] : [];
const refererParams = (refererInfo && refererInfo.referer) ? [`xf${base64urlEncode(refererInfo.referer)}`] : [];
const id5Params = (getId5Id(validBidRequests)) ? [`x5${getId5Id(validBidRequests)}`] : [];
const targetsParams = Object.keys(targets).map(targetCode => targetCode + targets[targetCode].join(';'));
const slotsParams = validBidRequests.map(bid => 'sl' + bidToSlotName(bid));
const params = [...slotsParams, ...targetsParams, ...gdprParams, ...refererParams, ...id5Params].map(s => `/${s}`).join('');
const cacheBuster = '?t=' + new Date().getTime();
const uri = 'https://ads-' + account + '.adhese.com/json' + params + cacheBuster;
const gdprParams = (gdprConsent && gdprConsent.consentString) ? { xt: [gdprConsent.consentString] } : {};
const refererParams = (refererInfo && refererInfo.referer) ? { xf: [base64urlEncode(refererInfo.referer)] } : {};
const id5Params = (getId5Id(validBidRequests)) ? { x5: [getId5Id(validBidRequests)] } : {};
const slots = validBidRequests.map(bid => ({ slotname: bidToSlotName(bid) }));

const payload = {
slots: slots,
parameters: { ...targets, ...gdprParams, ...refererParams, ...id5Params }
}

const account = getAccount(validBidRequests);
const uri = 'https://ads-' + account + '.adhese.com/json';

return {
method: 'GET',
method: 'POST',
url: uri,
bids: validBidRequests
data: JSON.stringify(payload),
bids: validBidRequests,
options: {
contentType: 'application/json'
}
};
},

Expand Down
33 changes: 26 additions & 7 deletions test/spec/modules/adheseBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {expect} from 'chai';
import {spec} from 'modules/adheseBidAdapter.js';
import {server} from 'test/mocks/xhr.js';

const BID_ID = 456;
const TTL = 360;
Expand Down Expand Up @@ -71,40 +72,46 @@ describe('AdheseAdapter', function () {
}
};

it('should include requested slots', function () {
let req = spec.buildRequests([ minimalBid() ], bidderRequest);

expect(JSON.parse(req.data).slots).to.deep.include({ 'slotname': '_main_page_-leaderboard' });
});

it('should include all extra bid params', function () {
let req = spec.buildRequests([ bidWithParams({ 'ag': '25' }) ], bidderRequest);

expect(req.url).to.contain('/sl_main_page_-leaderboard/ag25');
expect(JSON.parse(req.data).parameters).to.deep.include({ 'ag': [ '25' ] });
});

it('should include duplicate bid params once', function () {
let req = spec.buildRequests([ bidWithParams({ 'ag': '25' }), bidWithParams({ 'ag': '25', 'ci': 'gent' }) ], bidderRequest);

expect(req.url).to.contain('/sl_main_page_-leaderboard/ag25/cigent');
expect(JSON.parse(req.data).parameters).to.deep.include({'ag': ['25']}).and.to.deep.include({ 'ci': [ 'gent' ] });
});

it('should split multiple target values', function () {
let req = spec.buildRequests([ bidWithParams({ 'ci': 'london' }), bidWithParams({ 'ci': 'gent' }) ], bidderRequest);

expect(req.url).to.contain('/sl_main_page_-leaderboard/cilondon;gent');
expect(JSON.parse(req.data).parameters).to.deep.include({ 'ci': [ 'london', 'gent' ] });
});

it('should include gdpr consent param', function () {
let req = spec.buildRequests([ minimalBid() ], bidderRequest);

expect(req.url).to.contain('/xtCONSENT_STRING');
expect(JSON.parse(req.data).parameters).to.deep.include({ 'xt': [ 'CONSENT_STRING' ] });
});

it('should include referer param in base64url format', function () {
let req = spec.buildRequests([ minimalBid() ], bidderRequest);

expect(req.url).to.contain('/xfaHR0cDovL3ByZWJpZC5vcmcvZGV2LWRvY3Mvc3ViamVjdHM_X2Q9MQ');
expect(JSON.parse(req.data).parameters).to.deep.include({ 'xf': [ 'aHR0cDovL3ByZWJpZC5vcmcvZGV2LWRvY3Mvc3ViamVjdHM_X2Q9MQ' ] });
});

it('should include id5 id as /x5 param', function () {
let req = spec.buildRequests([ bidWithParams({}, {'id5id': 'ID5-1234567890'}) ], bidderRequest);
let req = spec.buildRequests([ bidWithParams({}, { 'id5id': 'ID5-1234567890' }) ], bidderRequest);

expect(req.url).to.contain('/x5ID5-1234567890');
expect(JSON.parse(req.data).parameters).to.deep.include({ 'x5': [ 'ID5-1234567890' ] });
});

it('should include bids', function () {
Expand All @@ -113,6 +120,18 @@ describe('AdheseAdapter', function () {

expect(req.bids).to.deep.equal([ bid ]);
});

it('should make a POST request', function () {
let req = spec.buildRequests([ minimalBid() ], bidderRequest);

expect(req.method).to.equal('POST');
});

it('should request the json endpoint', function () {
let req = spec.buildRequests([ minimalBid() ], bidderRequest);

expect(req.url).to.equal('https://ads-demo.adhese.com/json');
});
});

describe('interpretResponse', () => {
Expand Down

0 comments on commit 746f70b

Please sign in to comment.