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

Prebid 3 Admixer #4615

Merged
merged 9 commits into from
Jan 2, 2020
Merged
Show file tree
Hide file tree
Changes from 8 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
65 changes: 65 additions & 0 deletions modules/admixerBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import * as utils from '../src/utils';
import {registerBidder} from '../src/adapters/bidderFactory';

const BIDDER_CODE = 'admixer';
const ALIASES = ['go2net'];
const ENDPOINT_URL = '//inv-nets.admixer.net/prebid.1.0.aspx';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be hard-coded to https to be compliant with prebid 3.0

export const spec = {
code: BIDDER_CODE,
aliases: ALIASES,
supportedMediaTypes: ['banner', 'video'],
/**
* Determines whether or not the given bid request is valid.
*/
isBidRequestValid: function (bid) {
return !!bid.params.zone;
},
/**
* Make a server request from the list of BidRequests.
*/
buildRequests: function (validRequest, bidderRequest) {
console.log(arguments);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still needed?

const payload = {
imps: [],
referrer: encodeURIComponent(bidderRequest.refererInfo.referer),
};
validRequest.forEach((bid) => {
payload.imps.push(bid);
});
const payloadString = JSON.stringify(payload);
return {
method: 'GET',
url: ENDPOINT_URL,
data: `data=${payloadString}`,
};
},
/**
* Unpack the response from the server into a list of bids.
*/
interpretResponse: function (serverResponse, bidRequest) {
const bidResponses = [];
// loop through serverResponses {
try {
serverResponse = serverResponse.body;
serverResponse.forEach((bidResponse) => {
const bidResp = {
requestId: bidResponse.bidId,
cpm: bidResponse.cpm,
width: bidResponse.width,
height: bidResponse.height,
ad: bidResponse.ad,
ttl: bidResponse.ttl,
creativeId: bidResponse.creativeId,
netRevenue: bidResponse.netRevenue,
currency: bidResponse.currency,
vastUrl: bidResponse.vastUrl,
};
bidResponses.push(bidResp);
});
} catch (e) {
utils.logError(e);
}
return bidResponses;
}
};
registerBidder(spec);
122 changes: 122 additions & 0 deletions test/spec/modules/admixerBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import {expect} from 'chai';
import {spec} from 'modules/admixerBidAdapter';
import {newBidder} from 'src/adapters/bidderFactory';

const BIDDER_CODE = 'admixer';
const ENDPOINT_URL = '//inv-nets.admixer.net/prebid.1.0.aspx';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This URL should be updated to https to match the corresponding request in the bidAdapter.js file.

const ZONE_ID = '2eb6bd58-865c-47ce-af7f-a918108c3fd2';

describe('AdmixerAdapter', function () {
const adapter = newBidder(spec);

describe('inherited functions', function () {
it('exists and is a function', function () {
expect(adapter.callBids).to.be.exist.and.to.be.a('function');
});
});

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

it('should return true when required params found', function () {
expect(spec.isBidRequestValid(bid)).to.equal(true);
});

it('should return false when required params are not passed', function () {
let bid = Object.assign({}, bid);
delete bid.params;
bid.params = {
'placementId': 0
};
expect(spec.isBidRequestValid(bid)).to.equal(false);
});
});

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

it('should add referrer and imp to be equal bidRequest', function () {
const request = spec.buildRequests(validRequest, bidderRequest);
const payload = JSON.parse(request.data.substr(5));
expect(payload.referrer).to.not.be.undefined;
expect(payload.imps[0]).to.deep.equal(validRequest[0]);
});

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

describe('interpretResponse', function () {
let response = {
body: [{
'currency': 'USD',
'cpm': 6.210000,
'ad': '<div>ad</div>',
'width': 300,
'height': 600,
'creativeId': 'ccca3e5e-0c54-4761-9667-771322fbdffc',
'ttl': 360,
'netRevenue': false,
'bidId': '5e4e763b6bc60b'
}]
};

it('should get correct bid response', function () {
const body = response.body;
let expectedResponse = [
{
'requestId': body[0].bidId,
'cpm': body[0].cpm,
'creativeId': body[0].creativeId,
'width': body[0].width,
'height': body[0].height,
'ad': body[0].ad,
'vastUrl': undefined,
'currency': body[0].currency,
'netRevenue': body[0].netRevenue,
'ttl': body[0].ttl,
}
];

let result = spec.interpretResponse(response);
expect(result[0]).to.deep.equal(expectedResponse[0]);
});

it('handles nobid responses', function () {
let response = [];

let result = spec.interpretResponse(response);
expect(result.length).to.equal(0);
});
});
});