Skip to content

Commit

Permalink
quantcast: Update endpoint (#2828)
Browse files Browse the repository at this point in the history
  • Loading branch information
soarez authored and idettman committed Jul 20, 2018
1 parent b0cda1c commit a60bf5f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 59 deletions.
35 changes: 14 additions & 21 deletions modules/quantcastBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@ import { registerBidder } from 'src/adapters/bidderFactory';
const BIDDER_CODE = 'quantcast';
const DEFAULT_BID_FLOOR = 0.0000000001;

export const QUANTCAST_CALLBACK_URL = 'global.qc.rtb.quantserve.com';
export const QUANTCAST_CALLBACK_URL_TEST = 's2s-canary.quantserve.com';
export const QUANTCAST_DOMAIN = 'qcx.quantserve.com';
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';

/**
* The documentation for Prebid.js Adapter 1.0 can be found at link below,
Expand Down Expand Up @@ -51,21 +59,6 @@ export const spec = {
const loc = utils.getTopWindowLocation();
const domain = loc.hostname;

let publisherTagURL;
let publisherTagURLTest;

// Switch the callback URL to Quantcast Canary Endpoint for testing purpose
// `//` is not used because we have different port setting at our end
switch (window.location.protocol) {
case 'https:':
publisherTagURL = `https://${QUANTCAST_CALLBACK_URL}:8443/qchb`;
publisherTagURLTest = `https://${QUANTCAST_CALLBACK_URL_TEST}:8443/qchb`;
break;
default:
publisherTagURL = `http://${QUANTCAST_CALLBACK_URL}:8080/qchb`;
publisherTagURLTest = `http://${QUANTCAST_CALLBACK_URL_TEST}:8080/qchb`;
}

const bidRequestsList = bids.map(bid => {
const bidSizes = [];

Expand Down Expand Up @@ -104,10 +97,10 @@ export const spec = {

const data = JSON.stringify(requestData);

const url =
bid.params.publisherId === QUANTCAST_TEST_PUBLISHER
? publisherTagURLTest
: publisherTagURL;
const qcDomain = bid.params.publisherId === QUANTCAST_TEST_PUBLISHER
? QUANTCAST_TEST_DOMAIN
: QUANTCAST_DOMAIN;
const url = `${QUANTCAST_PROTOCOL}://${qcDomain}:${QUANTCAST_PORT}/qchb`;

return {
data,
Expand Down
64 changes: 26 additions & 38 deletions test/spec/modules/quantcastBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import * as utils from 'src/utils';
import { expect } from 'chai';
import {
QUANTCAST_CALLBACK_URL_TEST,
QUANTCAST_CALLBACK_URL,
QUANTCAST_DOMAIN,
QUANTCAST_TEST_DOMAIN,
QUANTCAST_NET_REVENUE,
QUANTCAST_TTL,
QUANTCAST_TEST_PUBLISHER,
QUANTCAST_PROTOCOL,
QUANTCAST_PORT,
spec as qcSpec
} from '../../../modules/quantcastBidAdapter';
import { newBidder } from '../../../src/adapters/bidderFactory';
Expand All @@ -21,7 +24,7 @@ describe('Quantcast adapter', () => {
bidderRequestId: '1cc026909c24c8',
placementCode: 'div-gpt-ad-1438287399331-0',
params: {
publisherId: 'test-publisher', // REQUIRED - Publisher ID provided by Quantcast
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]]
Expand Down Expand Up @@ -53,50 +56,35 @@ describe('Quantcast adapter', () => {
});

describe('`buildRequests`', () => {
it('sends bid requests to Quantcast Canary Endpoint if `publisherId` is `test-publisher`', () => {
const requests = qcSpec.buildRequests([bidRequest]);

it('selects protocol and port', () => {
switch (window.location.protocol) {
case 'https:':
expect(requests[0]['url']).to.equal(
`https://${QUANTCAST_CALLBACK_URL_TEST}:8443/qchb`
);
expect(QUANTCAST_PROTOCOL).to.equal('https');
expect(QUANTCAST_PORT).to.equal('8443');
break;
default:
expect(requests[0]['url']).to.equal(
`http://${QUANTCAST_CALLBACK_URL_TEST}:8080/qchb`
);
expect(QUANTCAST_PROTOCOL).to.equal('http');
expect(QUANTCAST_PORT).to.equal('8080');
break;
}
});

it('sends bid requests to Quantcast Global Endpoint for regular `publisherId`', () => {
const bidRequest = {
bidder: 'quantcast',
bidId: '2f7b179d443f14',
auctionId: '595ffa73-d78a-46c9-b18e-f99548a5be6b',
bidderRequestId: '1cc026909c24c8',
placementCode: 'div-gpt-ad-1438287399331-0',
params: {
publisherId: 'regular-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]]
};
it('sends bid requests to Quantcast Canary Endpoint if `publisherId` is `test-publisher`', () => {
const requests = qcSpec.buildRequests([bidRequest]);
const url = new URL(requests[0]['url']);
expect(url.hostname).to.equal(QUANTCAST_TEST_DOMAIN);
});

switch (window.location.protocol) {
case 'https:':
expect(requests[0]['url']).to.equal(
`https://${QUANTCAST_CALLBACK_URL}:8443/qchb`
);
break;
default:
expect(requests[0]['url']).to.equal(
`http://${QUANTCAST_CALLBACK_URL}:8080/qchb`
);
break;
}
it('sends bid requests to default endpoint for non standard publisher IDs', () => {
const modifiedBidRequest = Object.assign({}, bidRequest, {
params: Object.assign({}, bidRequest.params, {
publisherId: 'foo-bar',
}),
});
const requests = qcSpec.buildRequests([modifiedBidRequest]);
expect(requests[0]['url']).to.equal(
`${QUANTCAST_PROTOCOL}://${QUANTCAST_DOMAIN}:${QUANTCAST_PORT}/qchb`
);
});

it('sends bid requests to Quantcast Header Bidding Endpoints via POST', () => {
Expand All @@ -112,7 +100,7 @@ describe('Quantcast adapter', () => {

const requests = qcSpec.buildRequests([bidRequest]);
const expectedBidRequest = {
publisherId: 'test-publisher',
publisherId: QUANTCAST_TEST_PUBLISHER,
requestId: '2f7b179d443f14',
imp: [
{
Expand Down

0 comments on commit a60bf5f

Please sign in to comment.