Skip to content

Commit

Permalink
read dealid from openrtb first, then fallback to ext
Browse files Browse the repository at this point in the history
  • Loading branch information
punkiller authored and umakajan committed May 21, 2021
1 parent 1fee420 commit 2d1d439
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 11 deletions.
6 changes: 5 additions & 1 deletion modules/ixBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ function _applyFloor(bid, imp, mediaType) {
function parseBid(rawBid, currency, bidRequest) {
const bid = {};
const isValidExpiry = !!((utils.deepAccess(rawBid, 'exp') && Number.isInteger(rawBid.exp)));
const dealID = utils.deepAccess(rawBid, 'dealid') || utils.deepAccess(rawBid, 'ext.dealid');

if (PRICE_TO_DOLLAR_FACTOR.hasOwnProperty(currency)) {
bid.cpm = rawBid.price / PRICE_TO_DOLLAR_FACTOR[currency];
Expand All @@ -216,7 +217,10 @@ function parseBid(rawBid, currency, bidRequest) {

bid.requestId = rawBid.impid;

bid.dealId = utils.deepAccess(rawBid, 'ext.dealid');
if (dealID) {
bid.dealId = dealID;
}

bid.netRevenue = NET_REVENUE;
bid.currency = currency;
bid.creativeId = rawBid.hasOwnProperty('crid') ? rawBid.crid : '-';
Expand Down
71 changes: 61 additions & 10 deletions test/spec/modules/ixBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1976,7 +1976,6 @@ describe('IndexexchangeAdapter', function () {
currency: 'USD',
ttl: 300,
netRevenue: true,
dealId: undefined,
meta: {
networkId: 50,
brandId: 303325,
Expand All @@ -2002,7 +2001,6 @@ describe('IndexexchangeAdapter', function () {
currency: 'USD',
ttl: 300,
netRevenue: true,
dealId: undefined,
meta: {
networkId: 50,
brandId: 303325,
Expand All @@ -2029,7 +2027,6 @@ describe('IndexexchangeAdapter', function () {
currency: 'USD',
ttl: 300,
netRevenue: true,
dealId: undefined,
meta: {
networkId: 50,
brandId: 303325,
Expand All @@ -2056,7 +2053,6 @@ describe('IndexexchangeAdapter', function () {
currency: 'JPY',
ttl: 300,
netRevenue: true,
dealId: undefined,
meta: {
networkId: 50,
brandId: 303325,
Expand All @@ -2069,9 +2065,38 @@ describe('IndexexchangeAdapter', function () {
expect(result[0]).to.deep.equal(expectedParse[0]);
});

it('should set dealId correctly', function () {
it('should prioritize bid[].dealid over bid[].ext.dealid ', function () {
const bidResponse = utils.deepClone(DEFAULT_BANNER_BID_RESPONSE);
bidResponse.seatbid[0].bid[0].ext.dealid = 'ext-deal';
bidResponse.seatbid[0].bid[0].dealid = 'outter-deal';
const expectedParse = [
{
requestId: '1a2b3c4d',
cpm: 1,
creativeId: '12345',
width: 300,
height: 250,
mediaType: 'banner',
ad: '<a target="_blank" href="https://www.indexexchange.com"></a>',
currency: 'USD',
ttl: 300,
netRevenue: true,
dealId: 'outter-deal',
meta: {
networkId: 50,
brandId: 303325,
brandName: 'OECTA',
advertiserDomains: ['www.abc.com']
}
}
];
const result = spec.interpretResponse({ body: bidResponse }, { data: DEFAULT_BIDDER_REQUEST_DATA });

expect(result[0].dealId).to.equal(expectedParse[0].dealId);
});

it('should not set bid[].dealid if dealid is not present', function () {
const bidResponse = utils.deepClone(DEFAULT_BANNER_BID_RESPONSE);
bidResponse.seatbid[0].bid[0].ext.dealid = 'deal';
const expectedParse = [
{
requestId: '1a2b3c4d',
Expand All @@ -2084,7 +2109,6 @@ describe('IndexexchangeAdapter', function () {
currency: 'USD',
ttl: 300,
netRevenue: true,
dealId: 'deal',
meta: {
networkId: 50,
brandId: 303325,
Expand All @@ -2097,6 +2121,34 @@ describe('IndexexchangeAdapter', function () {
expect(result[0]).to.deep.equal(expectedParse[0]);
});

it('should use set bid[].ext.dealid if bid[].dealid is not present', function () {
const bidResponse = utils.deepClone(DEFAULT_BANNER_BID_RESPONSE);
bidResponse.seatbid[0].bid[0].ext.dealid = 'ext-deal';
const expectedParse = [
{
requestId: '1a2b3c4d',
cpm: 1,
creativeId: '12345',
width: 300,
height: 250,
mediaType: 'banner',
ad: '<a target="_blank" href="https://www.indexexchange.com"></a>',
currency: 'USD',
ttl: 300,
dealId: 'ext-deal',
netRevenue: true,
meta: {
networkId: 50,
brandId: 303325,
brandName: 'OECTA',
advertiserDomains: ['www.abc.com']
}
}
];
const result = spec.interpretResponse({ body: bidResponse }, { data: DEFAULT_BIDDER_REQUEST_DATA });
expect(result[0].dealId).to.deep.equal(expectedParse[0].dealId);
});

it('should get correct bid response for video ad', function () {
const expectedParse = [
{
Expand All @@ -2109,7 +2161,6 @@ describe('IndexexchangeAdapter', function () {
currency: 'USD',
ttl: 3600,
netRevenue: true,
dealId: undefined,
vastUrl: 'www.abcd.com/vast',
meta: {
networkId: 51,
Expand Down Expand Up @@ -2157,8 +2208,8 @@ describe('IndexexchangeAdapter', function () {
});

it('should set bid[].ttl to seatbid[].bid[].exp value from response', function () {
const BANNER_RESPONSE_WITH_EXP = JSON.parse(JSON.stringify(DEFAULT_BANNER_BID_RESPONSE));
const VIDEO_RESPONSE_WITH_EXP = JSON.parse(JSON.stringify(DEFAULT_VIDEO_BID_RESPONSE));
const BANNER_RESPONSE_WITH_EXP = utils.deepClone(DEFAULT_BANNER_BID_RESPONSE);
const VIDEO_RESPONSE_WITH_EXP = utils.deepClone(DEFAULT_VIDEO_BID_RESPONSE);
VIDEO_RESPONSE_WITH_EXP.seatbid[0].bid[0].exp = 200;
BANNER_RESPONSE_WITH_EXP.seatbid[0].bid[0].exp = 100;
const bannerResult = spec.interpretResponse({ body: BANNER_RESPONSE_WITH_EXP }, { data: DEFAULT_BIDDER_REQUEST_DATA });
Expand Down

0 comments on commit 2d1d439

Please sign in to comment.