Skip to content

Commit

Permalink
Updated gdpr in adform adapter (#2589)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pupis authored and jaiminpanchal27 committed May 23, 2018
1 parent ebf0d30 commit da8bb94
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 14 deletions.
19 changes: 14 additions & 5 deletions modules/adformBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const spec = {
return !!(bid.params.mid);
},
buildRequests: function (validBidRequests, bidderRequest) {
var i, l, j, k, bid, _key, _value, reqParams, netRevenue;
var i, l, j, k, bid, _key, _value, reqParams, netRevenue, gdprObject;
var request = [];
var globalParams = [ [ 'adxDomain', 'adx.adform.net' ], [ 'fd', 1 ], [ 'url', null ], [ 'tid', null ] ];
var bids = JSON.parse(JSON.stringify(validBidRequests));
Expand All @@ -38,9 +38,13 @@ export const spec = {
request.push('pt=' + netRevenue);
request.push('stid=' + validBidRequests[0].auctionId);

if (bidderRequest && bidderRequest.gdprConsent) {
request.push('gdpr=' + bidderRequest.gdprConsent.gdprApplies);
request.push('gdpr_consent=' + bidderRequest.gdprConsent.consentString);
if (bidderRequest && bidderRequest.gdprConsent && bidderRequest.gdprConsent.gdprApplies) {
gdprObject = {
gdpr: bidderRequest.gdprConsent.gdprApplies,
gdpr_consent: bidderRequest.gdprConsent.consentString
};
request.push('gdpr=' + gdprObject.gdpr);
request.push('gdpr_consent=' + gdprObject.gdpr_consent);
}

for (i = 1, l = globalParams.length; i < l; i++) {
Expand All @@ -56,7 +60,8 @@ export const spec = {
url: request.join('&'),
bids: validBidRequests,
netRevenue: netRevenue,
bidder: 'adform'
bidder: 'adform',
gdpr: gdprObject
};

function formRequestUrl(reqData) {
Expand Down Expand Up @@ -102,6 +107,10 @@ export const spec = {
vastXml: response.vast_content,
mediaType: type
};
if (bidRequest.gdpr) {
bidObject.gdpr = bidRequest.gdpr.gdpr;
bidObject.gdpr_consent = bidRequest.gdpr.gdpr_consent;
}
bidRespones.push(bidObject);
}
}
Expand Down
64 changes: 55 additions & 9 deletions test/spec/modules/adformBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,6 @@ describe('Adform adapter', () => {
assert.deepEqual(resultBids, bids[0]);
});

it('should send GDPR Consent data to adform', () => {
var resultBids = JSON.parse(JSON.stringify(bids[0]));
let request = spec.buildRequests([bids[0]], {gdprConsent: {gdprApplies: 1, consentString: 'concentDataString'}});
let parsedUrl = parseUrl(request.url).query;

assert.equal(parsedUrl.gdpr, 1);
assert.equal(parsedUrl.gdpr_consent, 'concentDataString');
});

it('should set gross to the request, if there is any gross priceType', () => {
let request = spec.buildRequests([bids[5], bids[5]]);
let parsedUrl = parseUrl(request.url);
Expand All @@ -119,6 +110,42 @@ describe('Adform adapter', () => {

assert.equal(parsedUrl.query.pt, 'gross');
});

describe('gdpr', () => {
it('should send GDPR Consent data to adform if gdprApplies', () => {
let resultBids = JSON.parse(JSON.stringify(bids[0]));
let request = spec.buildRequests([bids[0]], {gdprConsent: {gdprApplies: true, consentString: 'concentDataString'}});
let parsedUrl = parseUrl(request.url).query;

assert.equal(parsedUrl.gdpr, 'true');
assert.equal(parsedUrl.gdpr_consent, 'concentDataString');
});

it('should not send GDPR Consent data to adform if gdprApplies is false or undefined', () => {
let resultBids = JSON.parse(JSON.stringify(bids[0]));
let request = spec.buildRequests([bids[0]], {gdprConsent: {gdprApplies: false, consentString: 'concentDataString'}});
let parsedUrl = parseUrl(request.url).query;

assert.ok(!parsedUrl.gdpr);
assert.ok(!parsedUrl.gdpr_consent);

request = spec.buildRequests([bids[0]], {gdprConsent: {gdprApplies: undefined, consentString: 'concentDataString'}});
assert.ok(!parsedUrl.gdpr);
assert.ok(!parsedUrl.gdpr_consent);
});

it('should return GDPR Consent data with request data', () => {
let request = spec.buildRequests([bids[0]], {gdprConsent: {gdprApplies: true, consentString: 'concentDataString'}});

assert.deepEqual(request.gdpr, {
gdpr: true,
gdpr_consent: 'concentDataString'
});

request = spec.buildRequests([bids[0]]);
assert.ok(!request.gdpr);
});
});
});

describe('interpretResponse', () => {
Expand Down Expand Up @@ -205,6 +232,25 @@ describe('Adform adapter', () => {
assert.equal(result[i].netRevenue, false);
}
});

it('should set gdpr if it exist in bidRequest', () => {
bidRequest.gdpr = {
gdpr: true,
gdpr_consent: 'ERW342EIOWT34234KMGds'
};
let result = spec.interpretResponse(serverResponse, bidRequest);
for (let i = 0; i < result.length; i++) {
assert.equal(result[i].gdpr, true);
assert.equal(result[i].gdpr_consent, 'ERW342EIOWT34234KMGds');
};

bidRequest.gdpr = undefined;
result = spec.interpretResponse(serverResponse, bidRequest);
for (let i = 0; i < result.length; i++) {
assert.ok(!result[i].gdpr);
assert.ok(!result[i].gdpr_consent);
};
})
});

beforeEach(() => {
Expand Down

0 comments on commit da8bb94

Please sign in to comment.