Skip to content

Commit

Permalink
No bid version 1.2.8 (#5630)
Browse files Browse the repository at this point in the history
* Enable supplyChain support

* Added support for COPPA

* Added support for TCF 2.0

* Fixed the test coverage.

* Fixed lint issue.

Co-authored-by: Reda Guermas <reda.guermas@nobid.io>
  • Loading branch information
redaguermas and Reda Guermas authored Sep 21, 2020
1 parent 6480715 commit 743d6fc
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 16 deletions.
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

0 comments on commit 743d6fc

Please sign in to comment.