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

Improve Digital adapter: minor improvements #8346

Merged
merged 1 commit into from
Apr 29, 2022
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
16 changes: 10 additions & 6 deletions modules/improvedigitalBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,20 @@ export const spec = {
if (additionalConsent && additionalConsent.indexOf('~') !== -1) {
// Google Ad Tech Provider IDs
const atpIds = additionalConsent.substring(additionalConsent.indexOf('~') + 1);
deepSetValue(
request,
'user.ext.consented_providers_settings.consented_providers',
atpIds.split('.').map(id => parseInt(id, 10))
);
if (atpIds) {
deepSetValue(
request,
'user.ext.consented_providers_settings.consented_providers',
atpIds.split('.').map(id => parseInt(id, 10))
);
}
}
}

// Timeout
deepSetValue(request, 'tmax', bidderRequest.timeout);
if (bidderRequest.timeout) {
request.tmax = parseInt(bidderRequest.timeout);
}
// US Privacy
if (typeof bidderRequest.uspConsent !== typeof undefined) {
deepSetValue(request, 'regs.ext.us_privacy', bidderRequest.uspConsent);
Expand Down
32 changes: 27 additions & 5 deletions test/spec/modules/improvedigitalBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';
import { spec } from 'modules/improvedigitalBidAdapter.js';
import { config } from 'src/config.js';
import * as utils from 'src/utils.js';
import { deepClone } from 'src/utils.js';
import {BANNER, VIDEO} from '../../../src/mediaTypes';

describe('Improve Digital Adapter Tests', function () {
Expand Down Expand Up @@ -34,23 +34,23 @@ describe('Improve Digital Adapter Tests', function () {
skipafter: 30
}

const instreamBidRequest = utils.deepClone(simpleBidRequest);
const instreamBidRequest = deepClone(simpleBidRequest);
instreamBidRequest.mediaTypes = {
video: {
context: 'instream',
playerSize: [640, 480]
}
};

const outstreamBidRequest = utils.deepClone(simpleBidRequest);
const outstreamBidRequest = deepClone(simpleBidRequest);
outstreamBidRequest.mediaTypes = {
video: {
context: 'outstream',
playerSize: [640, 480]
}
};

const multiFormatBidRequest = utils.deepClone(simpleBidRequest);
const multiFormatBidRequest = deepClone(simpleBidRequest);
multiFormatBidRequest.mediaTypes = {
banner: {
sizes: [[300, 250], [160, 600]]
Expand Down Expand Up @@ -294,6 +294,14 @@ describe('Improve Digital Adapter Tests', function () {
expect(payload.user.ext.consented_providers_settings.consented_providers).to.exist.and.to.deep.equal([1, 35, 41, 101]);
});

it('should not add consented providers when empty', function () {
const bidderRequestGdprEmptyAddtl = deepClone(bidderRequestGdpr);
bidderRequestGdprEmptyAddtl.gdprConsent.addtlConsent = '1~';
const bidRequest = Object.assign({}, simpleBidRequest);
const payload = JSON.parse(spec.buildRequests([bidRequest], bidderRequestGdprEmptyAddtl)[0].data);
expect(payload.user.ext.consented_providers_settings).to.not.exist;
});

it('should add CCPA consent string', function () {
const bidRequest = Object.assign({}, simpleBidRequest);
const request = spec.buildRequests([bidRequest], {...bidderRequest, ...{ uspConsent: '1YYY' }});
Expand All @@ -308,6 +316,20 @@ describe('Improve Digital Adapter Tests', function () {
expect(payload.site.page).to.equal('https://blah.com/test.html');
});

it('should add timeout', function () {
const bidderRequestTimeout = deepClone(bidderRequest);
// Int
bidderRequestTimeout.timeout = 300;
const bidRequest = Object.assign({}, simpleBidRequest);
let request = spec.buildRequests([bidRequest], bidderRequestTimeout)[0];
expect(JSON.parse(request.data).tmax).to.equal(300);

// String
bidderRequestTimeout.timeout = '500';
request = spec.buildRequests([bidRequest], bidderRequestTimeout)[0];
expect(JSON.parse(request.data).tmax).to.equal(500);
});

it('should not add video params for banner', function () {
const bidRequest = JSON.parse(JSON.stringify(simpleBidRequest));
bidRequest.params.video = videoParams;
Expand Down Expand Up @@ -916,7 +938,7 @@ describe('Improve Digital Adapter Tests', function () {
}
];

const expectedBidOutstreamVideo = utils.deepClone(expectedBidInstreamVideo);
const expectedBidOutstreamVideo = deepClone(expectedBidInstreamVideo);
expectedBidOutstreamVideo[0].adResponse = {
content: expectedBidOutstreamVideo[0].vastXml
};
Expand Down