Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch Adhese adapter to POST method #5574

Merged
merged 1 commit into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
35 changes: 27 additions & 8 deletions test/spec/modules/adheseBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,40 +71,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 +119,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 Expand Up @@ -211,7 +229,8 @@ describe('AdheseAdapter', function () {
adhese: {
origin: 'RUBICON',
originInstance: '',
originData: {} }
originData: {}
}
}];
expect(spec.interpretResponse(sspVideoResponse, bidRequest)).to.deep.equal(expectedResponse);
});
Expand Down