Skip to content

Commit

Permalink
quantcastBidAdapter update for 3.0 (#4451)
Browse files Browse the repository at this point in the history
* Updated quantcastBidAdapter to always send secure requests.

* Ignore deprecated banner format.
  • Loading branch information
dpapworth-qc authored and Mike Chowla committed Dec 2, 2019
1 parent d08891d commit 84818c9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 57 deletions.
32 changes: 10 additions & 22 deletions modules/quantcastBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,8 @@ export const QUANTCAST_TEST_DOMAIN = 's2s-canary.quantserve.com';
export const QUANTCAST_NET_REVENUE = true;
export const QUANTCAST_TEST_PUBLISHER = 'test-publisher';
export const QUANTCAST_TTL = 4;
export const QUANTCAST_PROTOCOL =
window.location.protocol === 'http:'
? 'http'
: 'https';
export const QUANTCAST_PORT =
QUANTCAST_PROTOCOL === 'http'
? '8080'
: '8443';

function extractBidSizes(bid) {
const bidSizes = [];

bid.sizes.forEach(size => {
bidSizes.push({
width: size[0],
height: size[1]
});
});

return bidSizes;
}
export const QUANTCAST_PROTOCOL = 'https';
export const QUANTCAST_PORT = '8443';

function makeVideoImp(bid) {
const video = {};
Expand Down Expand Up @@ -67,10 +48,17 @@ function makeVideoImp(bid) {
}

function makeBannerImp(bid) {
const sizes = bid.sizes || bid.mediaTypes.banner.sizes;

return {
banner: {
battr: bid.params.battr,
sizes: extractBidSizes(bid),
sizes: sizes.map(size => {
return {
width: size[0],
height: size[1]
};
})
},
placementCode: bid.placementCode,
bidFloor: bid.params.bidFloor || DEFAULT_BID_FLOOR
Expand Down
75 changes: 40 additions & 35 deletions test/spec/modules/quantcastBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ describe('Quantcast adapter', function () {
publisherId: QUANTCAST_TEST_PUBLISHER, // REQUIRED - Publisher ID provided by Quantcast
battr: [1, 2] // OPTIONAL - Array of blocked creative attributes as per OpenRTB Spec List 5.3
},
sizes: [[300, 250]]
mediaTypes: {
banner: {
sizes: [[300, 250]]
}
}
};

bidderRequest = {
Expand Down Expand Up @@ -83,17 +87,10 @@ describe('Quantcast adapter', function () {
});

describe('`buildRequests`', function () {
it('selects protocol and port', function () {
switch (window.location.protocol) {
case 'https:':
expect(QUANTCAST_PROTOCOL).to.equal('https');
expect(QUANTCAST_PORT).to.equal('8443');
break;
default:
expect(QUANTCAST_PROTOCOL).to.equal('http');
expect(QUANTCAST_PORT).to.equal('8080');
break;
}
it('sends secure bid requests', function () {
const requests = qcSpec.buildRequests([bidRequest]);
const url = parse(requests[0]['url']);
expect(url.protocol).to.equal('https');
});

it('sends bid requests to Quantcast Canary Endpoint if `publisherId` is `test-publisher`', function () {
Expand All @@ -120,30 +117,39 @@ describe('Quantcast adapter', function () {
expect(requests[0].method).to.equal('POST');
});

const expectedBannerBidRequest = {
publisherId: QUANTCAST_TEST_PUBLISHER,
requestId: '2f7b179d443f14',
imp: [
{
banner: {
battr: [1, 2],
sizes: [{ width: 300, height: 250 }]
},
placementCode: 'div-gpt-ad-1438287399331-0',
bidFloor: 1e-10
}
],
site: {
page: 'http://example.com/hello.html',
referrer: 'http://example.com/hello.html',
domain: 'example.com'
},
bidId: '2f7b179d443f14',
gdprSignal: 0,
prebidJsVersion: '$prebid.version$'
};

it('sends banner bid requests contains all the required parameters', function () {
const requests = qcSpec.buildRequests([bidRequest], bidderRequest);
const expectedBannerBidRequest = {
publisherId: QUANTCAST_TEST_PUBLISHER,
requestId: '2f7b179d443f14',
imp: [
{
banner: {
battr: [1, 2],
sizes: [{ width: 300, height: 250 }]
},
placementCode: 'div-gpt-ad-1438287399331-0',
bidFloor: 1e-10
}
],
site: {
page: 'http://example.com/hello.html',
referrer: 'http://example.com/hello.html',
domain: 'example.com'
},
bidId: '2f7b179d443f14',
gdprSignal: 0,
prebidJsVersion: '$prebid.version$'
};

expect(requests[0].data).to.equal(JSON.stringify(expectedBannerBidRequest));
});

it('supports deprecated banner format', function () {
bidRequest.sizes = bidRequest.mediaTypes.banner.sizes;
delete bidRequest.mediaTypes;
const requests = qcSpec.buildRequests([bidRequest], bidderRequest);

expect(requests[0].data).to.equal(JSON.stringify(expectedBannerBidRequest));
});
Expand Down Expand Up @@ -297,7 +303,6 @@ describe('Quantcast adapter', function () {
playerSize: [[550, 310]]
}
};
bidRequest.sizes = [[300, 250], [728, 90], [250, 250], [468, 60], [320, 50]];

const requests = qcSpec.buildRequests([bidRequest], bidderRequest);
const expectedBidRequest = {
Expand Down

0 comments on commit 84818c9

Please sign in to comment.