forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Next Millennium Bid Adapter: update to comply with Prebid v5 (prebid#…
…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
Showing
2 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); |