Skip to content

Commit

Permalink
Admixer Bid Adapter : adding floor module support and new alias (preb…
Browse files Browse the repository at this point in the history
…id#9427)

* add floor module support

* bidFloor update

* Update admixerBidAdapter.md

* Update admixerBidAdapter.js

* remove tests

* tests

* floor test

* Update admixerBidAdapter_spec.js

* Update admixerBidAdapter_spec.js

* Update admixerBidAdapter.js

* https endpoint

* lint bugs fix
  • Loading branch information
dariaboyko authored and JacobKlein26 committed Feb 8, 2023
1 parent 95c9001 commit ef83694
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 64 deletions.
30 changes: 26 additions & 4 deletions modules/admixerBidAdapter.js
@@ -1,12 +1,14 @@
import { logError } from '../src/utils.js';
import {logError} from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {config} from '../src/config.js';
import {BANNER, VIDEO, NATIVE} from '../src/mediaTypes.js';
import { convertOrtbRequestToProprietaryNative } from '../src/native.js';
import {convertOrtbRequestToProprietaryNative} from '../src/native.js';

const BIDDER_CODE = 'admixer';
const ALIASES = ['go2net', 'adblender', 'adsyield', 'futureads', 'smn'];
const BIDDER_CODE_ADX = 'admixeradx';
const ALIASES = ['go2net', 'adblender', 'adsyield', 'futureads', 'admixeradx'];
const ENDPOINT_URL = 'https://inv-nets.admixer.net/prebid.1.2.aspx';
const ADX_ENDPOINT_URL = 'https://inv-nets.admixer.net/adxprebid.1.2.aspx';
export const spec = {
code: BIDDER_CODE,
aliases: ALIASES,
Expand Down Expand Up @@ -57,6 +59,10 @@ export const spec = {
if (bidderRequest.uspConsent) {
payload.uspConsent = bidderRequest.uspConsent;
}
let bidFloor = getBidFloor(bidderRequest);
if (bidFloor) {
payload.bidFloor = bidFloor;
}
}
validRequest.forEach((bid) => {
let imp = {};
Expand All @@ -65,7 +71,11 @@ export const spec = {
});
return {
method: 'POST',
url: endpointUrl || ENDPOINT_URL,
url:
endpointUrl ||
(bidderRequest.bidderCode === BIDDER_CODE_ADX
? ADX_ENDPOINT_URL
: ENDPOINT_URL),
data: payload,
};
},
Expand Down Expand Up @@ -96,4 +106,16 @@ export const spec = {
return pixels;
}
};
function getBidFloor(bid) {
try {
const bidFloor = bid.getFloor({
currency: 'USD',
mediaType: '*',
size: '*',
});
return bidFloor.floor;
} catch (_) {
return 0;
}
}
registerBidder(spec);
200 changes: 140 additions & 60 deletions test/spec/modules/admixerBidAdapter_spec.js
Expand Up @@ -4,8 +4,10 @@ import {newBidder} from 'src/adapters/bidderFactory.js';
import {config} from '../../../src/config.js';

const BIDDER_CODE = 'admixer';
const BIDDER_CODE_ADX = 'admixeradx';
const ENDPOINT_URL = 'https://inv-nets.admixer.net/prebid.1.2.aspx';
const ENDPOINT_URL_CUSTOM = 'https://custom.admixer.net/prebid.aspx';
const ENDPOINT_URL_ADX = 'https://inv-nets.admixer.net/adxprebid.1.2.aspx';
const ZONE_ID = '2eb6bd58-865c-47ce-af7f-a918108c3fd2';

describe('AdmixerAdapter', function () {
Expand All @@ -16,18 +18,22 @@ describe('AdmixerAdapter', function () {
expect(adapter.callBids).to.be.exist.and.to.be.a('function');
});
});
// inv-nets.admixer.net/adxprebid.1.2.aspx

describe('isBidRequestValid', function () {
let bid = {
'bidder': BIDDER_CODE,
'params': {
'zone': ZONE_ID
bidder: BIDDER_CODE,
params: {
zone: ZONE_ID,
},
'adUnitCode': 'adunit-code',
'sizes': [[300, 250], [300, 600]],
'bidId': '30b31c1838de1e',
'bidderRequestId': '22edbae2733bf6',
'auctionId': '1d1a030790a475',
adUnitCode: 'adunit-code',
sizes: [
[300, 250],
[300, 600],
],
bidId: '30b31c1838de1e',
bidderRequestId: '22edbae2733bf6',
auctionId: '1d1a030790a475',
};

it('should return true when required params found', function () {
Expand All @@ -38,7 +44,7 @@ describe('AdmixerAdapter', function () {
let bid = Object.assign({}, bid);
delete bid.params;
bid.params = {
'placementId': 0
placementId: 0,
};
expect(spec.isBidRequestValid(bid)).to.equal(false);
});
Expand All @@ -47,22 +53,25 @@ describe('AdmixerAdapter', function () {
describe('buildRequests', function () {
let validRequest = [
{
'bidder': BIDDER_CODE,
'params': {
'zone': ZONE_ID
bidder: BIDDER_CODE,
params: {
zone: ZONE_ID,
},
'adUnitCode': 'adunit-code',
'sizes': [[300, 250], [300, 600]],
'bidId': '30b31c1838de1e',
'bidderRequestId': '22edbae2733bf6',
'auctionId': '1d1a030790a475',
}
adUnitCode: 'adunit-code',
sizes: [
[300, 250],
[300, 600],
],
bidId: '30b31c1838de1e',
bidderRequestId: '22edbae2733bf6',
auctionId: '1d1a030790a475',
},
];
let bidderRequest = {
bidderCode: BIDDER_CODE,
refererInfo: {
page: 'https://example.com'
}
page: 'https://example.com',
},
};

it('should add referrer and imp to be equal bidRequest', function () {
Expand All @@ -81,49 +90,122 @@ describe('AdmixerAdapter', function () {
it('sends bid request to CUSTOM_ENDPOINT via GET', function () {
config.setBidderConfig({
bidders: [BIDDER_CODE], // one or more bidders
config: {[BIDDER_CODE]: {endpoint_url: ENDPOINT_URL_CUSTOM}}
config: { [BIDDER_CODE]: { endpoint_url: ENDPOINT_URL_CUSTOM } },
});
const request = config.runWithBidder(BIDDER_CODE, () => spec.buildRequests(validRequest, bidderRequest));
const request = config.runWithBidder(BIDDER_CODE, () =>
spec.buildRequests(validRequest, bidderRequest)
);
expect(request.url).to.equal(ENDPOINT_URL_CUSTOM);
expect(request.method).to.equal('POST');
});
});

describe('buildRequestsAdmixerADX', function () {
let validRequest = [
{
bidder: BIDDER_CODE_ADX,
params: {
zone: ZONE_ID,
},
adUnitCode: 'adunit-code',
sizes: [
[300, 250],
[300, 600],
],
bidId: '30b31c1838de1e',
bidderRequestId: '22edbae2733bf6',
auctionId: '1d1a030790a475',
},
];
let bidderRequest = {
bidderCode: BIDDER_CODE_ADX,
refererInfo: {
page: 'https://example.com',
},
};

it('sends bid request to ADX ENDPOINT', function () {
const request = spec.buildRequests(validRequest, bidderRequest);
expect(request.url).to.equal(ENDPOINT_URL_ADX);
expect(request.method).to.equal('POST');
});
});

describe('checkFloorGetting', function () {
let validRequest = [
{
bidder: BIDDER_CODE,
params: {
zone: ZONE_ID,
},
adUnitCode: 'adunit-code',
sizes: [[300, 250]],
bidId: '30b31c1838de1e',
bidderRequestId: '22edbae2733bf6',
auctionId: '1d1a030790a475',
},
];
let bidderRequest = {
bidderCode: BIDDER_CODE,
refererInfo: {
page: 'https://example.com',
},
};
it('gets floor', function () {
bidderRequest.getFloor = () => {
return { floor: 0.6 };
};
const request = spec.buildRequests(validRequest, bidderRequest);
const payload = request.data;
expect(payload.bidFloor).to.deep.equal(0.6);
});
});

describe('interpretResponse', function () {
let response = {
body: {
ads: [{
'currency': 'USD',
'cpm': 6.210000,
'ad': '<div>ad</div>',
'width': 300,
'height': 600,
'creativeId': 'ccca3e5e-0c54-4761-9667-771322fbdffc',
'ttl': 360,
'netRevenue': false,
'requestId': '5e4e763b6bc60b',
'dealId': 'asd123',
'meta': {'advertiserId': 123, 'networkId': 123, 'advertiserDomains': ['test.com']}
}]
}
ads: [
{
currency: 'USD',
cpm: 6.21,
ad: '<div>ad</div>',
width: 300,
height: 600,
creativeId: 'ccca3e5e-0c54-4761-9667-771322fbdffc',
ttl: 360,
netRevenue: false,
requestId: '5e4e763b6bc60b',
dealId: 'asd123',
meta: {
advertiserId: 123,
networkId: 123,
advertiserDomains: ['test.com'],
},
},
],
},
};

it('should get correct bid response', function () {
const ads = response.body.ads;
let expectedResponse = [
{
'requestId': ads[0].requestId,
'cpm': ads[0].cpm,
'creativeId': ads[0].creativeId,
'width': ads[0].width,
'height': ads[0].height,
'ad': ads[0].ad,
'currency': ads[0].currency,
'netRevenue': ads[0].netRevenue,
'ttl': ads[0].ttl,
'dealId': ads[0].dealId,
'meta': {'advertiserId': 123, 'networkId': 123, 'advertiserDomains': ['test.com']}
}
requestId: ads[0].requestId,
cpm: ads[0].cpm,
creativeId: ads[0].creativeId,
width: ads[0].width,
height: ads[0].height,
ad: ads[0].ad,
currency: ads[0].currency,
netRevenue: ads[0].netRevenue,
ttl: ads[0].ttl,
dealId: ads[0].dealId,
meta: {
advertiserId: 123,
networkId: 123,
advertiserDomains: ['test.com'],
},
},
];

let result = spec.interpretResponse(response);
Expand All @@ -141,18 +223,16 @@ describe('AdmixerAdapter', function () {
describe('getUserSyncs', function () {
let imgUrl = 'https://example.com/img1';
let frmUrl = 'https://example.com/frm2';
let responses = [{
body: {
cm: {
pixels: [
imgUrl
],
iframes: [
frmUrl
],
}
}
}];
let responses = [
{
body: {
cm: {
pixels: [imgUrl],
iframes: [frmUrl],
},
},
},
];

it('Returns valid values', function () {
let userSyncAll = spec.getUserSyncs({pixelEnabled: true, iframeEnabled: true}, responses);
Expand Down

0 comments on commit ef83694

Please sign in to comment.