Skip to content

Commit

Permalink
Next Millennium Bid Adapter: update to comply with Prebid v5 (prebid#…
Browse files Browse the repository at this point in the history
…7209)

* Start

* nextMillenniumBidAdapter for v5

* add test page

* undo changes in hello_world

* manually kick off tests

Co-authored-by: Chris Huie <phoenixtechnerd@gmail.com>
  • Loading branch information
Mikhail Ivanchenko and ChrisHuie committed Aug 3, 2021
1 parent adb1731 commit ca7ab18
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 0 deletions.
85 changes: 85 additions & 0 deletions modules/nextMillenniumBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { registerBidder } from '../src/adapters/bidderFactory.js';
import * as utils from '../src/utils.js';
import { BANNER } from '../src/mediaTypes.js';

const BIDDER_CODE = 'nextMillennium';
const ENDPOINT = 'https://pbs.nextmillmedia.com/openrtb2/auction';
const TIME_TO_LIVE = 360;

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

isBidRequestValid: function(bid) {
return !!(
bid.params.placement_id && utils.isStr(bid.params.placement_id)
);
},

buildRequests: function(validBidRequests, bidderRequest) {
const requests = [];

utils._each(validBidRequests, function(bid) {
const postBody = {
'ext': {
'prebid': {
'storedrequest': {
'id': utils.getBidIdParameter('placement_id', bid.params)
}
}
}
}
const gdprConsent = bidderRequest && bidderRequest.gdprConsent;

if (gdprConsent) {
if (typeof gdprConsent.gdprApplies !== 'undefined') {
postBody.gdprApplies = !!gdprConsent.gdprApplies;
}
if (typeof gdprConsent.consentString !== 'undefined') {
postBody.consentString = gdprConsent.consentString;
}
}

requests.push({
method: 'POST',
url: ENDPOINT,
data: JSON.stringify(postBody),
options: {
contentType: 'application/json',
withCredentials: true
},
bidId: bid.bidId
});
});

return requests;
},

interpretResponse: function(serverResponse, bidRequest) {
const response = serverResponse.body;
const bidResponses = [];

utils._each(response.seatbid, (resp) => {
utils._each(resp.bid, (bid) => {
bidResponses.push({
requestId: bidRequest.bidId,
cpm: bid.price,
width: bid.w,
height: bid.h,
creativeId: bid.adid,
currency: response.cur,
netRevenue: false,
ttl: TIME_TO_LIVE,
meta: {
advertiserDomains: bid.adomain || []
},
ad: bid.adm
});
});
});

return bidResponses;
}
};

registerBidder(spec);
54 changes: 54 additions & 0 deletions test/spec/modules/nextMillenniumBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { expect } from 'chai';
import { spec } from 'modules/nextMillenniumBidAdapter.js';

describe('nextMillenniumBidAdapterTests', function() {
const bidRequestData = [
{
bidId: 'bid1234',
bidder: 'nextMillennium',
params: { placement_id: '-1' },
sizes: [[300, 250]]
}
];

it('validate_generated_params', function() {
const request = spec.buildRequests(bidRequestData);
expect(request[0].bidId).to.equal('bid1234');
});

it('validate_response_params', function() {
const serverResponse = {
body: {
id: 'f7b3d2da-e762-410c-b069-424f92c4c4b2',
seatbid: [
{
bid: [
{
id: '7457329903666272789',
price: 0.5,
adm: 'Hello! It\'s a test ad!',
adid: '96846035',
adomain: ['test.addomain.com'],
w: 300,
h: 250
}
]
}
],
cur: 'USD'
}
};

let bids = spec.interpretResponse(serverResponse, bidRequestData[0]);
expect(bids).to.have.lengthOf(1);

let bid = bids[0];

expect(bid.creativeId).to.equal('96846035');
expect(bid.ad).to.equal('Hello! It\'s a test ad!');
expect(bid.cpm).to.equal(0.5);
expect(bid.width).to.equal(300);
expect(bid.height).to.equal(250);
expect(bid.currency).to.equal('USD');
});
});

0 comments on commit ca7ab18

Please sign in to comment.