Skip to content

Commit

Permalink
Added support for NURL and ADM as backup (prebid#2112)
Browse files Browse the repository at this point in the history
+ Updated unit tests to test code updates
+ Added version number (1.0.4) for optimatic records
  • Loading branch information
optimatic58 authored and dluxemburg committed Jul 17, 2018
1 parent b1576ab commit c945ed5
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
11 changes: 9 additions & 2 deletions modules/optimaticBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { registerBidder } from 'src/adapters/bidderFactory';
export const ENDPOINT = '//mg-bid.optimatic.com/adrequest/';

export const spec = {

version: '1.0.4',

code: 'optimatic',

supportedMediaTypes: ['video'],
Expand Down Expand Up @@ -33,7 +36,7 @@ export const spec = {
} catch (e) {
response = null;
}
if (!response || !bid || !bid.adm || !bid.price) {
if (!response || !bid || (!bid.adm && !bid.nurl) || !bid.price) {
utils.logWarn(`No valid bids from ${spec.code} bidder`);
return [];
}
Expand All @@ -43,14 +46,18 @@ export const spec = {
bidderCode: spec.code,
cpm: bid.price,
creativeId: bid.id,
vastXml: bid.adm,
width: size.width,
height: size.height,
mediaType: 'video',
currency: response.cur,
ttl: 300,
netRevenue: true
};
if (bid.nurl) {
bidResponse.vastUrl = bid.nurl;
} else if (bid.adm) {
bidResponse.vastXml = bid.adm;
}
return bidResponse;
}
};
Expand Down
42 changes: 40 additions & 2 deletions test/spec/modules/optimaticBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe('OptimaticBidAdapter', () => {
expect(bidResponse.length).to.equal(0);
});

it('should return no bids if the response "adm" is missing', () => {
it('should return no bids if the response "nurl" and "adm" are missing', () => {
const serverResponse = {seatbid: [{bid: [{price: 5.01}]}]};
const bidResponse = spec.interpretResponse({ body: serverResponse }, { bidRequest });
expect(bidResponse.length).to.equal(0);
Expand All @@ -118,7 +118,7 @@ describe('OptimaticBidAdapter', () => {
expect(bidResponse.length).to.equal(0);
});

it('should return a valid bid response', () => {
it('should return a valid bid response with just "adm"', () => {
const serverResponse = {seatbid: [{bid: [{id: 1, price: 5.01, adm: '<VAST></VAST>'}]}], cur: 'USD'};
const bidResponse = spec.interpretResponse({ body: serverResponse }, { bidRequest });
let o = {
Expand All @@ -136,5 +136,43 @@ describe('OptimaticBidAdapter', () => {
};
expect(bidResponse).to.deep.equal(o);
});

it('should return a valid bid response with just "nurl"', () => {
const serverResponse = {seatbid: [{bid: [{id: 1, price: 5.01, nurl: 'https://mg-bid-win.optimatic.com/win/134eb262-948a-463e-ad93-bc8b622d399c?wp=${AUCTION_PRICE}'}]}], cur: 'USD'};
const bidResponse = spec.interpretResponse({ body: serverResponse }, { bidRequest });
let o = {
requestId: bidRequest.bidId,
bidderCode: spec.code,
cpm: serverResponse.seatbid[0].bid[0].price,
creativeId: serverResponse.seatbid[0].bid[0].id,
vastUrl: serverResponse.seatbid[0].bid[0].nurl,
width: 640,
height: 480,
mediaType: 'video',
currency: 'USD',
ttl: 300,
netRevenue: true
};
expect(bidResponse).to.deep.equal(o);
});

it('should return a valid bid response with "nurl" when both nurl and adm exist', () => {
const serverResponse = {seatbid: [{bid: [{id: 1, price: 5.01, adm: '<VAST></VAST>', nurl: 'https://mg-bid-win.optimatic.com/win/134eb262-948a-463e-ad93-bc8b622d399c?wp=${AUCTION_PRICE}'}]}], cur: 'USD'};
const bidResponse = spec.interpretResponse({ body: serverResponse }, { bidRequest });
let o = {
requestId: bidRequest.bidId,
bidderCode: spec.code,
cpm: serverResponse.seatbid[0].bid[0].price,
creativeId: serverResponse.seatbid[0].bid[0].id,
vastUrl: serverResponse.seatbid[0].bid[0].nurl,
width: 640,
height: 480,
mediaType: 'video',
currency: 'USD',
ttl: 300,
netRevenue: true
};
expect(bidResponse).to.deep.equal(o);
});
});
});

0 comments on commit c945ed5

Please sign in to comment.