Skip to content

Commit

Permalink
Update bridgewell bid adapter (prebid#4920)
Browse files Browse the repository at this point in the history
* Add consumed to bid response

* Modify test

* Use include instead of containAllKeys

* Use adUnitCode to match response and request

* Add test

* Restore packageLock
  • Loading branch information
lawliet1995 authored and rjvelicaria committed Apr 9, 2020
1 parent 6c713ec commit 4c8475a
Show file tree
Hide file tree
Showing 2 changed files with 213 additions and 2 deletions.
10 changes: 8 additions & 2 deletions modules/bridgewellBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const spec = {
utils._each(validBidRequests, function (bid) {
adUnits.push({
ChannelID: bid.params.ChannelID,
adUnitCode: bid.adUnitCode,
mediaTypes: bid.mediaTypes || {
banner: {
sizes: bid.sizes
Expand Down Expand Up @@ -89,9 +90,12 @@ export const spec = {
let matchedResponse = find(serverResponse.body, function (res) {
let valid = false;

if (res) {
if (res && !res.consumed) {
let mediaTypes = req.mediaTypes;
if (res.width && res.height && mediaTypes) {
let adUnitCode = req.adUnitCode;
if (res.adUnitCode) {
return res.adUnitCode === adUnitCode;
} else if (res.width && res.height && mediaTypes) {
if (mediaTypes.native) { // dont care native sizes
valid = true;
} else if (mediaTypes.banner) {
Expand All @@ -116,6 +120,8 @@ export const spec = {
});

if (matchedResponse) {
matchedResponse.consumed = true;

// check required parameters
if (typeof matchedResponse.cpm !== 'number') {
return;
Expand Down
205 changes: 205 additions & 0 deletions test/spec/modules/bridgewellBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ describe('bridgewellBidAdapter', function () {
expect(payload.url).to.exist.and.to.equal('https://www.bridgewell.com/');
for (let i = 0, max_i = payload.adUnits.length; i < max_i; i++) {
expect(payload.adUnits[i]).to.have.property('ChannelID').that.is.a('string');
expect(payload.adUnits[i]).to.have.property('adUnitCode').and.to.equal('adunit-code-2');
}
});

Expand Down Expand Up @@ -1010,5 +1011,209 @@ describe('bridgewellBidAdapter', function () {
const result = spec.interpretResponse({ 'body': response }, nativeBidRequests);
expect(result).to.deep.equal([]);
});

it('should contain every request bid id in responses', function () {
const request = {
validBidRequests: [
{
'mediaTypes': {
'banner': {
'sizes': [300, 250]
}
},
'bidId': '3150ccb55da321',
},
{
'mediaTypes': {
'banner': {
'sizes': [300, 250]
}
},
'bidId': '3150ccb55da322',
}
],
};
const response = [{
'id': '0cd250f4-f40e-4a78-90f5-5168eb0a97e9',
'bidder_code': 'bridgewell',
'cpm': 7.0,
'width': 300,
'height': 250,
'mediaType': 'banner',
'ad': '<div>test 300x250</div>',
'ttl': 400,
'netRevenue': true,
'currency': 'NTD'
}, {
'id': '8a740063-6820-45e4-b01f-34ce9b38e858',
'bidder_code': 'bridgewell',
'cpm': 7.0,
'width': 300,
'height': 250,
'mediaType': 'banner',
'ad': '<div>test 300x250</div>',
'ttl': 400,
'netRevenue': true,
'currency': 'NTD'
}];
const result = spec.interpretResponse({ 'body': response }, request);
let actualBidId = result.map(obj => obj.requestId);
let expectedBidId = ['3150ccb55da321', '3150ccb55da322'];

expect(actualBidId).to.include(expectedBidId[0]).and.to.include(expectedBidId[1]);
});

it('should have 2 consumed responses when two requests with same sizes are given', function () {
const request = {
validBidRequests: [
{
'mediaTypes': {
'banner': {
'sizes': [300, 250]
}
},
'bidId': '3150ccb55da321',
},
{
'mediaTypes': {
'banner': {
'sizes': [300, 250]
}
},
'bidId': '3150ccb55da322',
}
],
};
const response = [{
'id': '0cd250f4-f40e-4a78-90f5-5168eb0a97e9',
'bidder_code': 'bridgewell',
'cpm': 7.0,
'width': 300,
'height': 250,
'mediaType': 'banner',
'ad': '<div>test 300x250</div>',
'ttl': 400,
'netRevenue': true,
'currency': 'NTD'
}, {
'id': '8a740063-6820-45e4-b01f-34ce9b38e858',
'bidder_code': 'bridgewell',
'cpm': 7.0,
'width': 300,
'height': 250,
'mediaType': 'banner',
'ad': '<div>test 300x250</div>',
'ttl': 400,
'netRevenue': true,
'currency': 'NTD'
}];
const reducer = function(accumulator, currentValue) {
if (currentValue.consumed) accumulator++;
return accumulator;
};

spec.interpretResponse({ 'body': response }, request);
expect(response.reduce(reducer, 0)).to.equal(2);
});

it('should use adUnitCode to build bidResponses', function () {
const request = {
validBidRequests: [
{
'adUnitCode': 'div-gpt-ad-1564632520056-0',
'bidId': '3150ccb55da321',
},
{
'adUnitCode': 'div-gpt-ad-1564632520056-1',
'bidId': '3150ccb55da322',
}
],
};
const response = [{
'id': '0cd250f4-f40e-4a78-90f5-5168eb0a97e9',
'bidder_code': 'bridgewell',
'adUnitCode': 'div-gpt-ad-1564632520056-0',
'cpm': 7.0,
'width': 300,
'height': 250,
'mediaType': 'banner',
'ad': '<div>test 300x250</div>',
'ttl': 400,
'netRevenue': true,
'currency': 'NTD'
}, {
'id': '8a740063-6820-45e4-b01f-34ce9b38e858',
'bidder_code': 'bridgewell',
'adUnitCode': 'div-gpt-ad-1564632520056-1',
'cpm': 7.0,
'width': 300,
'height': 250,
'mediaType': 'banner',
'ad': '<div>test 300x250</div>',
'ttl': 400,
'netRevenue': true,
'currency': 'NTD'
}];
const result = spec.interpretResponse({ 'body': response }, request);
let actualBidId = result.map(obj => obj.requestId);
let expectedBidId = ['3150ccb55da321', '3150ccb55da322'];

expect(actualBidId).to.include(expectedBidId[0]).and.to.include(expectedBidId[1]);
});

it('should use size to match when adUnitCode is empty string in server response', function () {
const request = {
validBidRequests: [
{
'mediaTypes': {
'banner': {
'sizes': [300, 250]
}
},
'adUnitCode': 'div-gpt-ad-1564632520056-0',
'bidId': '3150ccb55da321',
},
{
'mediaTypes': {
'banner': {
'sizes': [300, 250]
}
},
'adUnitCode': 'div-gpt-ad-1564632520056-1',
'bidId': '3150ccb55da322',
}
],
};
const response = [{
'id': '0cd250f4-f40e-4a78-90f5-5168eb0a97e9',
'bidder_code': 'bridgewell',
'adUnitCode': '',
'cpm': 7.0,
'width': 300,
'height': 250,
'mediaType': 'banner',
'ad': '<div>test 300x250</div>',
'ttl': 400,
'netRevenue': true,
'currency': 'NTD'
}, {
'id': '8a740063-6820-45e4-b01f-34ce9b38e858',
'bidder_code': 'bridgewell',
'adUnitCode': '',
'cpm': 7.0,
'width': 300,
'height': 250,
'mediaType': 'banner',
'ad': '<div>test 300x250</div>',
'ttl': 400,
'netRevenue': true,
'currency': 'NTD'
}];
const result = spec.interpretResponse({ 'body': response }, request);
let actualBidId = result.map(obj => obj.requestId);
let expectedBidId = ['3150ccb55da321', '3150ccb55da322'];

expect(actualBidId).to.include(expectedBidId[0]).and.to.include(expectedBidId[1]);
});
});
});

0 comments on commit 4c8475a

Please sign in to comment.