Skip to content

Commit

Permalink
Adpone Bid Adapter: remove usersync and pass gpdr via querystring (#6326
Browse files Browse the repository at this point in the history
)

* remove usersync and add gpdr via querystring

* wrap tests under describe adponeBidAdapter

* remove bid.meta.advertiserDomains

* support adomain

* fix adpone advertiserDomains

* fix test
  • Loading branch information
seergiioo6 authored and idettman committed May 21, 2021
1 parent a883da5 commit 063a455
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 136 deletions.
56 changes: 28 additions & 28 deletions modules/adponeBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,20 @@ import {triggerPixel} from '../src/utils.js';

const ADPONE_CODE = 'adpone';
const ADPONE_ENDPOINT = 'https://rtb.adpone.com/bid-request';
const ADPONE_SYNC_ENDPOINT = 'https://eu-ads.adpone.com';
const ADPONE_REQUEST_METHOD = 'POST';
const ADPONE_CURRENCY = 'EUR';

function _createSync() {
return {
type: 'iframe',
url: ADPONE_SYNC_ENDPOINT
}
}

function getUserSyncs(syncOptions) {
return (syncOptions && syncOptions.iframeEnabled) ? _createSync() : ([]);
}

export const spec = {
code: ADPONE_CODE,
supportedMediaTypes: [BANNER],

getUserSyncs,

isBidRequestValid: bid => {
return !!bid.params.placementId && !!bid.bidId && bid.bidder === 'adpone'
},

buildRequests: bidRequests => {
buildRequests: (bidRequests, bidderRequest) => {
return bidRequests.map(bid => {
const url = ADPONE_ENDPOINT + '?pid=' + bid.params.placementId;
let url = ADPONE_ENDPOINT + '?pid=' + bid.params.placementId;
const data = {
at: 1,
id: bid.bidId,
Expand All @@ -49,6 +35,11 @@ export const spec = {
withCredentials: true
};

if (bidderRequest && bidderRequest.gdprConsent) {
url += '&gdpr_applies=' + bidderRequest.gdprConsent.gdprApplies;
url += '&consentString=' + bidderRequest.gdprConsent.consentString;
}

return {
method: ADPONE_REQUEST_METHOD,
url,
Expand All @@ -67,18 +58,27 @@ export const spec = {

serverResponse.body.seatbid.forEach(seatbid => {
if (seatbid.bid.length) {
answer = [...answer, ...seatbid.bid.filter(bid => bid.price > 0).map(bid => ({
id: bid.id,
requestId: bidRequest.data.id,
cpm: bid.price,
ad: bid.adm,
width: bid.w || 0,
height: bid.h || 0,
currency: serverResponse.body.cur || ADPONE_CURRENCY,
netRevenue: true,
ttl: 300,
creativeId: bid.crid || 0
}))];
answer = [...answer, ...seatbid.bid.filter(bid => bid.price > 0).map(adponeBid => {
const bid = {
id: adponeBid.id,
requestId: bidRequest.data.id,
cpm: adponeBid.price,
ad: adponeBid.adm,
width: adponeBid.w || 0,
height: adponeBid.h || 0,
currency: serverResponse.body.cur || ADPONE_CURRENCY,
netRevenue: true,
ttl: 300,
creativeId: adponeBid.crid || 0
};

if (adponeBid.meta && adponeBid.meta.adomain && adponeBid.meta.adomain.length > 0) {
bid.meta = {};
bid.meta.advertiserDomains = adponeBid.meta.adomain;
}

return bid
})];
}
});

Expand Down
203 changes: 95 additions & 108 deletions test/spec/modules/adponeBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,122 +110,109 @@ describe('adponeBidAdapter', function () {
expect(spec.isBidRequestValid(invalidBid)).to.be.false;
});
});
});

describe('interpretResponse', function () {
let serverResponse;
let bidRequest = { data: {id: '1234'} };

beforeEach(function () {
serverResponse = {
body: {
id: '2579e20c0bb89',
seatbid: [
{
bid: [
{
id: '613673EF-A07C-4486-8EE9-3FC71A7DC73D',
impid: '2579e20c0bb89_0',
price: 1,
adm: '<html><a href="https://www.adpone.com" target="_blank"><img src ="https://placehold.it/300x250" /></a></html>',
adomain: [
'www.addomain.com'
],
iurl: 'https://localhost11',
crid: 'creative111',
h: 250,
w: 300,
ext: {
dspid: 6
describe('interpretResponse', function () {
let serverResponse;
let bidRequest = { data: {id: '1234'} };

beforeEach(function () {
serverResponse = {
body: {
id: '2579e20c0bb89',
seatbid: [
{
bid: [
{
id: '613673EF-A07C-4486-8EE9-3FC71A7DC73D',
impid: '2579e20c0bb89_0',
price: 1,
adm: '<html><a href="https://www.adpone.com" target="_blank"><img src ="https://placehold.it/300x250" /></a></html>',
meta: {
adomain: [
'adpone.com'
]
},
iurl: 'https://localhost11',
crid: 'creative111',
h: 250,
w: 300,
ext: {
dspid: 6
}
}
}
],
seat: 'adpone'
}
],
cur: 'USD'
},
};
});

it('validate_response_params', function() {
const newResponse = spec.interpretResponse(serverResponse, bidRequest);
expect(newResponse[0].id).to.be.equal('613673EF-A07C-4486-8EE9-3FC71A7DC73D');
expect(newResponse[0].requestId).to.be.equal('1234');
expect(newResponse[0].cpm).to.be.equal(1);
expect(newResponse[0].width).to.be.equal(300);
expect(newResponse[0].height).to.be.equal(250);
expect(newResponse[0].currency).to.be.equal('USD');
expect(newResponse[0].netRevenue).to.be.equal(true);
expect(newResponse[0].ttl).to.be.equal(300);
expect(newResponse[0].ad).to.be.equal('<html><a href="https://www.adpone.com" target="_blank"><img src ="https://placehold.it/300x250" /></a></html>');
});
],
seat: 'adpone'
}
],
cur: 'USD'
},
};
});

it('should correctly reorder the server response', function () {
const newResponse = spec.interpretResponse(serverResponse, bidRequest);
expect(newResponse.length).to.be.equal(1);
expect(newResponse[0]).to.deep.equal({
id: '613673EF-A07C-4486-8EE9-3FC71A7DC73D',
requestId: '1234',
cpm: 1,
width: 300,
height: 250,
creativeId: 'creative111',
currency: 'USD',
netRevenue: true,
ttl: 300,
ad: '<html><a href="https://www.adpone.com" target="_blank"><img src ="https://placehold.it/300x250" /></a></html>'
it('validate_response_params', function() {
const newResponse = spec.interpretResponse(serverResponse, bidRequest);
expect(newResponse[0].id).to.be.equal('613673EF-A07C-4486-8EE9-3FC71A7DC73D');
expect(newResponse[0].requestId).to.be.equal('1234');
expect(newResponse[0].cpm).to.be.equal(1);
expect(newResponse[0].width).to.be.equal(300);
expect(newResponse[0].height).to.be.equal(250);
expect(newResponse[0].currency).to.be.equal('USD');
expect(newResponse[0].netRevenue).to.be.equal(true);
expect(newResponse[0].ttl).to.be.equal(300);
expect(newResponse[0].ad).to.be.equal('<html><a href="https://www.adpone.com" target="_blank"><img src ="https://placehold.it/300x250" /></a></html>');
});
});

it('should not add responses if the cpm is 0 or null', function () {
serverResponse.body.seatbid[0].bid[0].price = 0;
let response = spec.interpretResponse(serverResponse, bidRequest);
expect(response).to.deep.equal([]);
it('should correctly reorder the server response', function () {
const newResponse = spec.interpretResponse(serverResponse, bidRequest);
expect(newResponse.length).to.be.equal(1);
expect(newResponse[0]).to.deep.equal({
id: '613673EF-A07C-4486-8EE9-3FC71A7DC73D',
meta: {
advertiserDomains: [
'adpone.com'
]
},
requestId: '1234',
cpm: 1,
width: 300,
height: 250,
creativeId: 'creative111',
currency: 'USD',
netRevenue: true,
ttl: 300,
ad: '<html><a href="https://www.adpone.com" target="_blank"><img src ="https://placehold.it/300x250" /></a></html>'
});
});

serverResponse.body.seatbid[0].bid[0].price = null;
response = spec.interpretResponse(serverResponse, bidRequest);
expect(response).to.deep.equal([])
});
it('should add responses if the cpm is valid', function () {
serverResponse.body.seatbid[0].bid[0].price = 0.5;
let response = spec.interpretResponse(serverResponse, bidRequest);
expect(response).to.not.deep.equal([]);
});
});
it('should not add responses if the cpm is 0 or null', function () {
serverResponse.body.seatbid[0].bid[0].price = 0;
let response = spec.interpretResponse(serverResponse, bidRequest);
expect(response).to.deep.equal([]);

describe('getUserSyncs', function () {
it('Verifies that getUserSyncs is a function', function () {
expect((typeof (spec.getUserSyncs)).should.equals('function'));
});
it('Verifies getUserSyncs returns expected result', function () {
expect((typeof (spec.getUserSyncs)).should.equals('function'));
expect(spec.getUserSyncs({iframeEnabled: true})).to.deep.equal({
type: 'iframe',
url: 'https://eu-ads.adpone.com'
serverResponse.body.seatbid[0].bid[0].price = null;
response = spec.interpretResponse(serverResponse, bidRequest);
expect(response).to.deep.equal([])
});
it('should add responses if the cpm is valid', function () {
serverResponse.body.seatbid[0].bid[0].price = 0.5;
let response = spec.interpretResponse(serverResponse, bidRequest);
expect(response).to.not.deep.equal([]);
});
});
it('Verifies that iframeEnabled: false returns an empty array', function () {
expect(spec.getUserSyncs({iframeEnabled: false})).to.deep.equal(EMPTY_ARRAY);
});
it('Verifies that iframeEnabled: null returns an empty array', function () {
expect(spec.getUserSyncs(null)).to.deep.equal(EMPTY_ARRAY);
});
});

describe('test onBidWon function', function () {
beforeEach(function() {
sinon.stub(utils, 'triggerPixel');
});
afterEach(function() {
utils.triggerPixel.restore();
});
it('exists and is a function', () => {
expect(spec.onBidWon).to.exist.and.to.be.a('function');
});
it('should return nothing', function () {
var response = spec.onBidWon({});
expect(response).to.be.an('undefined')
expect(utils.triggerPixel.called).to.equal(true);
describe('test onBidWon function', function () {
beforeEach(function() {
sinon.stub(utils, 'triggerPixel');
});
afterEach(function() {
utils.triggerPixel.restore();
});
it('exists and is a function', () => {
expect(spec.onBidWon).to.exist.and.to.be.a('function');
});
it('should return nothing', function () {
var response = spec.onBidWon({});
expect(response).to.be.an('undefined')
expect(utils.triggerPixel.called).to.equal(true);
});
});
});

0 comments on commit 063a455

Please sign in to comment.