Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Digital adapter: set dealID based on buying type #3182

Merged
merged 6 commits into from
Oct 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions modules/improvedigitalBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { config } from 'src/config';
const BIDDER_CODE = 'improvedigital';

export const spec = {
version: '4.3.0',
version: '4.4.0',
code: BIDDER_CODE,
aliases: ['id'],

Expand Down Expand Up @@ -78,11 +78,24 @@ export const spec = {
bid.cpm = parseFloat(bidObject.price);
bid.creativeId = bidObject.crid;
bid.currency = bidObject.currency ? bidObject.currency.toUpperCase() : 'USD';
if (utils.isNumber(bidObject.lid)) {

// Deal ID. Composite ads can have multiple line items and the ID of the first
// dealID line item will be used.
if (utils.isNumber(bidObject.lid) && bidObject.buying_type === 'deal_id') {
bid.dealId = bidObject.lid;
} else if (typeof bidObject.lid === 'object' && bidObject.lid['1']) {
bid.dealId = bidObject.lid['1'];
} else if (Array.isArray(bidObject.lid) &&
Array.isArray(bidObject.buying_type) &&
bidObject.lid.length === bidObject.buying_type.length) {
let isDeal = false;
bidObject.buying_type.forEach((bt, i) => {
if (isDeal) return;
if (bt === 'deal_id') {
isDeal = true;
bid.dealId = bidObject.lid[i];
}
});
}

bid.height = bidObject.h;
bid.netRevenue = bidObject.isNet ? bidObject.isNet : false;
bid.requestId = bidObject.id;
Expand Down
31 changes: 26 additions & 5 deletions test/spec/modules/improvedigitalBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,19 +264,40 @@ describe('Improve Digital Adapter Tests', function () {
let response = JSON.parse(JSON.stringify(serverResponse));
let bids;

response.body.bid[0].lid = 'xyz';
delete response.body.bid[0].lid;
response.body.bid[0].buying_type = 'deal_id';
bids = spec.interpretResponse(response);
expect(bids[0].dealId).to.not.exist;

response.body.bid[0].lid = 268515;
delete response.body.bid[0].buying_type;
bids = spec.interpretResponse(response);
expect(bids[0].dealId).to.equal(268515);
expect(bids[0].dealId).to.not.exist;

response.body.bid[0].lid = {
1: 268515
};
response.body.bid[0].lid = 268515;
response.body.bid[0].buying_type = 'classic';
bids = spec.interpretResponse(response);
expect(bids[0].dealId).to.not.exist;

response.body.bid[0].lid = 268515;
response.body.bid[0].buying_type = 'deal_id';
bids = spec.interpretResponse(response);
expect(bids[0].dealId).to.equal(268515);

response.body.bid[0].lid = [ 268515, 12456, 34567 ];
response.body.bid[0].buying_type = 'deal_id';
bids = spec.interpretResponse(response);
expect(bids[0].dealId).to.not.exist;

response.body.bid[0].lid = [ 268515, 12456, 34567 ];
response.body.bid[0].buying_type = [ 'deal_id', 'classic' ];
bids = spec.interpretResponse(response);
expect(bids[0].dealId).to.not.exist;

response.body.bid[0].lid = [ 268515, 12456, 34567 ];
response.body.bid[0].buying_type = [ 'classic', 'deal_id', 'deal_id' ];
bids = spec.interpretResponse(response);
expect(bids[0].dealId).to.equal(12456);
});

it('should set currency', function () {
Expand Down