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

add optional param to bridgewellBidAdapter #2289

Merged
merged 8 commits into from
Mar 21, 2018
Merged
Show file tree
Hide file tree
Changes from 6 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
23 changes: 21 additions & 2 deletions modules/bridgewellBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,25 @@ export const spec = {
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function(bid) {
return bid && bid.params && !!bid.params.ChannelID;
let valid = false;
let typeOfCpmWeight;

if (bid && bid.params) {
if (bid.params.ChannelID) {
// cpmWeight is optinal parameter and should above than zero
typeOfCpmWeight = typeof bid.params.cpmWeight;
if (typeOfCpmWeight === 'undefined') {
bid.params.cpmWeight = 1;
valid = true;
} else if (typeOfCpmWeight === 'number' && bid.params.cpmWeight > 0) {
valid = true;
} else {
valid = false;
}
}
}

return valid;
},

/**
Expand Down Expand Up @@ -82,7 +100,8 @@ export const spec = {
}

bidResponse.requestId = req.bidId;
bidResponse.cpm = matchedResponse.cpm;
bidResponse.requestId = req.bidId;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can remove this duplicate line.

bidResponse.cpm = matchedResponse.cpm * req.params.cpmWeight;
bidResponse.width = matchedResponse.width;
bidResponse.height = matchedResponse.height;
bidResponse.ad = matchedResponse.ad;
Expand Down
3 changes: 2 additions & 1 deletion modules/bridgewellBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Module that connects to Bridgewell demand source to fetch bids.
{
bidder: 'bridgewell',
params: {
ChannelID: 'CgUxMjMzOBIBNiIFcGVubnkqCQisAhD6ARoBOQ',
ChannelID: 'CgUxMjMzOBIBNiIFcGVubnkqCQisAhD6ARoBOQ'
}
}
]
Expand All @@ -30,6 +30,7 @@ Module that connects to Bridgewell demand source to fetch bids.
bidder: 'bridgewell',
params: {
ChannelID: 'CgUxMjMzOBIBNiIGcGVubnkzKggI2AUQWhoBOQ',
cpmWeight: 0.5
}
}
]
Expand Down
122 changes: 116 additions & 6 deletions test/spec/modules/bridgewellBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,30 @@ describe('bridgewellBidAdapter', function () {
'bidId': '42dbe3a7168a6a',
'bidderRequestId': '22edbae2733bf6',
'auctionId': '1d1a030790a475',
},
{
'bidder': 'bridgewell',
'params': {
'ChannelID': 'CgUxMjMzOBIBNiIFcGVubnkqCQisAhD6ARoBOQ',
'cpmWeight': 0.5
},
'adUnitCode': 'adunit-code-1',
'sizes': [[300, 250]],
'bidId': '42dbe3a7168a6a',
'bidderRequestId': '22edbae2733bf6',
'auctionId': '1d1a030790a475',
},
{
'bidder': 'bridgewell',
'params': {
'ChannelID': 'CgUxMjMzOBIBNiIGcGVubnkzKggI2AUQWhoBOQ',
'cpmWeight': -0.5
},
'adUnitCode': 'adunit-code-2',
'sizes': [[728, 90]],
'bidId': '3150ccb55da321',
'bidderRequestId': '22edbae2733bf6',
'auctionId': '1d1a030790a475',
}
];
const adapter = newBidder(spec);
Expand All @@ -48,7 +72,7 @@ describe('bridgewellBidAdapter', function () {
});

describe('isBidRequestValid', () => {
let bid = {
let bidWithoutCpmWeight = {
'bidder': 'bridgewell',
'params': {
'ChannelID': 'CLJgEAYYvxUiBXBlbm55KgkIrAIQ-gEaATk'
Expand All @@ -60,17 +84,83 @@ describe('bridgewellBidAdapter', function () {
'auctionId': '1d1a030790a475',
};

let bidWithCorrectCpmWeight = {
'bidder': 'bridgewell',
'params': {
'ChannelID': 'CLJgEAYYvxUiBXBlbm55KgkIrAIQ-gEaATk',
'cpmWeight': 0.5
},
'adUnitCode': 'adunit-code',
'sizes': [[300, 250], [300, 600]],
'bidId': '30b31c1838de1e',
'bidderRequestId': '22edbae2733bf6',
'auctionId': '1d1a030790a475',
};

let bidWithUncorrectCpmWeight = {
'bidder': 'bridgewell',
'params': {
'ChannelID': 'CLJgEAYYvxUiBXBlbm55KgkIrAIQ-gEaATk',
'cpmWeight': -1.0
},
'adUnitCode': 'adunit-code',
'sizes': [[300, 250], [300, 600]],
'bidId': '30b31c1838de1e',
'bidderRequestId': '22edbae2733bf6',
'auctionId': '1d1a030790a475',
};

let bidWithZeroCpmWeight = {
'bidder': 'bridgewell',
'params': {
'ChannelID': 'CLJgEAYYvxUiBXBlbm55KgkIrAIQ-gEaATk',
'cpmWeight': 0
},
'adUnitCode': 'adunit-code',
'sizes': [[300, 250], [300, 600]],
'bidId': '30b31c1838de1e',
'bidderRequestId': '22edbae2733bf6',
'auctionId': '1d1a030790a475',
};

it('should return true when required params found', () => {
expect(spec.isBidRequestValid(bid)).to.equal(true);
expect(spec.isBidRequestValid(bidWithoutCpmWeight)).to.equal(true);
expect(spec.isBidRequestValid(bidWithCorrectCpmWeight)).to.equal(true);
expect(spec.isBidRequestValid(bidWithUncorrectCpmWeight)).to.equal(false);
expect(spec.isBidRequestValid(bidWithZeroCpmWeight)).to.equal(false);
});

it('should return false when required params are not passed', () => {
let bid = Object.assign({}, bid);
delete bid.params;
bid.params = {
let bidWithoutCpmWeight = Object.assign({}, bidWithoutCpmWeight);
let bidWithCorrectCpmWeight = Object.assign({}, bidWithCorrectCpmWeight);
let bidWithUncorrectCpmWeight = Object.assign({}, bidWithUncorrectCpmWeight);
let bidWithZeroCpmWeight = Object.assign({}, bidWithZeroCpmWeight);

delete bidWithoutCpmWeight.params;
delete bidWithCorrectCpmWeight.params;
delete bidWithUncorrectCpmWeight.params;
delete bidWithZeroCpmWeight.params;

bidWithoutCpmWeight.params = {
'ChannelID': 0
};
expect(spec.isBidRequestValid(bid)).to.equal(false);

bidWithCorrectCpmWeight.params = {
'ChannelID': 0
};

bidWithUncorrectCpmWeight.params = {
'ChannelID': 0
};

bidWithZeroCpmWeight.params = {
'ChannelID': 0
};

expect(spec.isBidRequestValid(bidWithoutCpmWeight)).to.equal(false);
expect(spec.isBidRequestValid(bidWithCorrectCpmWeight)).to.equal(false);
expect(spec.isBidRequestValid(bidWithUncorrectCpmWeight)).to.equal(false);
expect(spec.isBidRequestValid(bidWithZeroCpmWeight)).to.equal(false);
});
});

Expand Down Expand Up @@ -129,6 +219,26 @@ describe('bridgewellBidAdapter', function () {
'ttl': 360,
'net_revenue': 'true',
'currency': 'NTD'
}, {
'id': '8f12c646-3b87-4326-a837-c2a76999f168',
'bidder_code': 'bridgewell',
'cpm': 5.0,
'width': 300,
'height': 250,
'ad': '<div>test 300x250</div>',
'ttl': 360,
'net_revenue': 'true',
'currency': 'NTD'
}, {
'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d',
'bidder_code': 'bridgewell',
'cpm': 5.0,
'width': 728,
'height': 90,
'ad': '<div>test 728x90</div>',
'ttl': 360,
'net_revenue': 'true',
'currency': 'NTD'
}];

it('should return all required parameters', () => {
Expand Down