Skip to content

Commit

Permalink
Changed bidder to read segments from ortb2.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikael-lundin committed May 31, 2021
1 parent 24c4230 commit 21a1cb1
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 9 deletions.
11 changes: 9 additions & 2 deletions modules/adnuntiusBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ const BIDDER_CODE = 'adnuntius';
const ENDPOINT_URL = 'https://delivery.adnuntius.com/i?tzo=';
const GVLID = 855;

const checkSegment = function (segment) {
if (utils.isStr(segment)) return segment;
if (segment.id) return segment.id
}

const getSegmentsFromOrtb = function (ortb2) {
const userData = utils.deepAccess(ortb2, 'user.data');
let segments;
let segments = [];
if (userData) {
userData.forEach(userdat => {
segments = (userdat.segment) ? userdat.segment.map(segment => segment.id) : undefined
if (userdat.segment) {
segments.push(...userdat.segment.filter(checkSegment).map(checkSegment));
}
});
}
return segments
Expand Down
56 changes: 49 additions & 7 deletions test/spec/modules/adnuntiusBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { newBidder } from 'src/adapters/bidderFactory.js';
import { config } from 'src/config.js';

describe('adnuntiusBidAdapter', function () {
beforeEach(function () {
config.setConfig({ segments: [] });
afterEach(function () {
config.resetConfig();
});
const tzo = new Date().getTimezoneOffset();
const ENDPOINT_URL = `https://delivery.adnuntius.com/i?tzo=${tzo}&format=json`;
// const ENDPOINT_URL_SEGMENTS = `https://delivery.adnuntius.com/i?tzo=${tzo}&format=json&segments=segment1,segment2`;
const ENDPOINT_URL_SEGMENTS = `https://delivery.adnuntius.com/i?tzo=${tzo}&format=json`;
// const ENDPOINT_URL_SEGMENTS_ = `https://delivery.adnuntius.com/i?tzo=${tzo}&format=json`;
const ENDPOINT_URL_SEGMENTS = `https://delivery.adnuntius.com/i?tzo=${tzo}&format=json&segments=segment1,segment2,segment3`;
const ENDPOINT_URL_CONSENT = `https://delivery.adnuntius.com/i?tzo=${tzo}&format=json&consentString=consentString`;
const adapter = newBidder(spec);

Expand Down Expand Up @@ -125,10 +125,52 @@ describe('adnuntiusBidAdapter', function () {
});

it('should pass segments if available in config', function () {
config.setConfig({
segments: ['segment1', 'segment2']
config.setBidderConfig({
bidders: ['adnuntius', 'other'],
config: {
ortb2: {
user: {
data: [{
name: 'adnuntius',
segment: [{ id: 'segment1' }, { id: 'segment2' }]
},
{
name: 'other',
segment: ['segment3']
}],
}
}
}
});
const request = spec.buildRequests(bidRequests);

const request = config.runWithBidder('adnuntius', () => spec.buildRequests(bidRequests));
expect(request.length).to.equal(1);
expect(request[0]).to.have.property('url')
expect(request[0].url).to.equal(ENDPOINT_URL_SEGMENTS);
});

it('should skip segments in config if not either id or array of strings', function () {
config.setBidderConfig({
bidders: ['adnuntius', 'other'],
config: {
ortb2: {
user: {
data: [{
name: 'adnuntius',
segment: [{ id: 'segment1' }, { id: 'segment2' }, { id: 'segment3' }]
},
{
name: 'other',
segment: [{
notright: 'segment4'
}]
}],
}
}
}
});

const request = config.runWithBidder('adnuntius', () => spec.buildRequests(bidRequests));
expect(request.length).to.equal(1);
expect(request[0]).to.have.property('url')
expect(request[0].url).to.equal(ENDPOINT_URL_SEGMENTS);
Expand Down

0 comments on commit 21a1cb1

Please sign in to comment.