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

No bid version 1.2.8 #5630

Merged
merged 11 commits into from
Sep 21, 2020
34 changes: 19 additions & 15 deletions modules/nobidBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getStorageManager } from '../src/storageManager.js';

const storage = getStorageManager();
const BIDDER_CODE = 'nobid';
window.nobidVersion = '1.2.6';
window.nobidVersion = '1.2.8';
window.nobid = window.nobid || {};
window.nobid.bidResponses = window.nobid.bidResponses || {};
window.nobid.timeoutTotal = 0;
Expand All @@ -24,6 +24,15 @@ function nobidSetCookie(cname, cvalue, hours) {
function nobidGetCookie(cname) {
return storage.getCookie(cname);
}
function nobidHasPurpose1Consent(bidderRequest) {
let result = true;
if (bidderRequest && bidderRequest.gdprConsent) {
if (bidderRequest.gdprConsent.gdprApplies && bidderRequest.gdprConsent.apiVersion === 2) {
result = !!(utils.deepAccess(bidderRequest.gdprConsent, 'vendorData.purpose.consents.1') === true);
}
}
return result;
}
function nobidBuildRequests(bids, bidderRequest) {
var serializeState = function(divIds, siteId, adunits) {
var filterAdUnitsByIds = function(divIds, adUnits) {
Expand Down Expand Up @@ -296,19 +305,7 @@ window.addEventListener('message', function (event) {
if (window.nobid && window.nobid.bidResponses) {
var bid = window.nobid.bidResponses['' + adId];
if (bid && bid.adm2) {
var markup = null;
if (bid.is_combo && bid.adm_combo) {
for (var i in bid.adm_combo) {
var combo = bid.adm_combo[i];
if (!combo.done) {
markup = combo.adm;
combo.done = true;
break;
}
}
} else {
markup = bid.adm2;
}
var markup = bid.adm2;
if (markup) {
event.source.postMessage('nbTagRenderer.renderAdInSafeFrame|' + markup, '*');
}
Expand Down Expand Up @@ -358,11 +355,18 @@ export const spec = {
window.nobid.refreshCount++;
const payloadString = JSON.stringify(payload).replace(/'|&|#/g, '')
const endpoint = buildEndpoint();

let options = {};
if (!nobidHasPurpose1Consent(bidderRequest)) {
options = { withCredentials: false };
}

return {
method: 'POST',
url: endpoint,
data: payloadString,
bidderRequest
bidderRequest,
options
};
},
/**
Expand Down
71 changes: 70 additions & 1 deletion test/spec/modules/nobidBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ describe('Nobid Adapter', function () {
expect(payload.a).to.exist;
expect(payload.t).to.exist;
expect(payload.tz).to.exist;
expect(payload.r).to.exist;
expect(payload.r).to.exist.and.to.equal('100x100');
expect(payload.lang).to.exist;
expect(payload.ref).to.exist;
expect(payload.a[0].d).to.exist.and.to.equal('adunit-code');
Expand Down Expand Up @@ -264,6 +264,38 @@ describe('Nobid Adapter', function () {
expect(payload.gdpr).to.exist;
});

it('sends bid request to ad size', function () {
const request = spec.buildRequests(bidRequests);
const payload = JSON.parse(request.data);
expect(payload.a).to.exist;
expect(payload.a.length).to.exist.and.to.equal(1);
expect(payload.a[0].z[0][0]).to.equal(300);
expect(payload.a[0].z[0][1]).to.equal(250);
});

it('sends bid request to div id', function () {
const request = spec.buildRequests(bidRequests);
const payload = JSON.parse(request.data);
expect(payload.a).to.exist;
expect(payload.a[0].d).to.equal('adunit-code');
});

it('sends bid request to site id', function () {
const request = spec.buildRequests(bidRequests);
const payload = JSON.parse(request.data);
expect(payload.a).to.exist;
expect(payload.a[0].sid).to.equal(2);
expect(payload.a[0].at).to.equal('banner');
expect(payload.a[0].params.siteId).to.equal(2);
});

it('sends bid request to ad type', function () {
const request = spec.buildRequests(bidRequests);
const payload = JSON.parse(request.data);
expect(payload.a).to.exist;
expect(payload.a[0].at).to.equal('banner');
});

it('sends bid request to ENDPOINT via POST', function () {
const request = spec.buildRequests(bidRequests);
expect(request.url).to.contain('ads.servenobid.com/adreq');
Expand Down Expand Up @@ -291,6 +323,43 @@ describe('Nobid Adapter', function () {
expect(payload.gdpr.consentString).to.exist.and.to.equal(consentString);
expect(payload.gdpr.consentRequired).to.exist.and.to.be.true;
});

it('should add gdpr consent information to the request', function () {
let bidderRequest = {
'bidderCode': 'nobid',
'auctionId': '1d1a030790a475',
'bidderRequestId': '22edbae2733bf6',
'timeout': 3000,
'gdprConsent': {
gdprApplies: false
}
};
bidderRequest.bids = bidRequests;

const request = spec.buildRequests(bidRequests, bidderRequest);
const payload = JSON.parse(request.data);

expect(payload.gdpr).to.exist;
expect(payload.gdpr.consentString).to.not.exist;
expect(payload.gdpr.consentRequired).to.exist.and.to.be.false;
});

it('should add usp consent information to the request', function () {
let bidderRequest = {
'bidderCode': 'nobid',
'auctionId': '1d1a030790a475',
'bidderRequestId': '22edbae2733bf6',
'timeout': 3000,
'uspConsent': '1Y-N'
};
bidderRequest.bids = bidRequests;

const request = spec.buildRequests(bidRequests, bidderRequest);
const payload = JSON.parse(request.data);

expect(payload.usp).to.exist;
expect(payload.usp).to.exist.and.to.equal('1Y-N');
});
});

describe('buildRequestsRefreshCount', function () {
Expand Down