From ca7ab182558ed4dffb0c016c13b32805820abaf5 Mon Sep 17 00:00:00 2001 From: Mikhail Ivanchenko Date: Tue, 3 Aug 2021 11:03:49 +0300 Subject: [PATCH] Next Millennium Bid Adapter: update to comply with Prebid v5 (#7209) * Start * nextMillenniumBidAdapter for v5 * add test page * undo changes in hello_world * manually kick off tests Co-authored-by: Chris Huie --- modules/nextMillenniumBidAdapter.js | 85 +++++++++++++++++++ .../modules/nextMillenniumBidAdapter_spec.js | 54 ++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 modules/nextMillenniumBidAdapter.js create mode 100644 test/spec/modules/nextMillenniumBidAdapter_spec.js diff --git a/modules/nextMillenniumBidAdapter.js b/modules/nextMillenniumBidAdapter.js new file mode 100644 index 00000000000..7164a517569 --- /dev/null +++ b/modules/nextMillenniumBidAdapter.js @@ -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); diff --git a/test/spec/modules/nextMillenniumBidAdapter_spec.js b/test/spec/modules/nextMillenniumBidAdapter_spec.js new file mode 100644 index 00000000000..e9a49682605 --- /dev/null +++ b/test/spec/modules/nextMillenniumBidAdapter_spec.js @@ -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'); + }); +});