Skip to content

Commit

Permalink
Make string with single quote
Browse files Browse the repository at this point in the history
  • Loading branch information
Li Xinyang authored and Li Xinyang committed Oct 20, 2017
1 parent 553b34d commit abf387a
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 68 deletions.
24 changes: 12 additions & 12 deletions modules/quantcastBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import adapterManager from "src/adaptermanager";
import * as utils from "src/utils";
import { registerBidder } from "src/adapters/bidderFactory";
import adapterManager from 'src/adaptermanager';
import * as utils from 'src/utils';
import { registerBidder } from 'src/adapters/bidderFactory';

const BIDDER_CODE = "quantcast";
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_TEST_PUBLISHER = "test-publisher";
export const QUANTCAST_CALLBACK_URL = 'global.qc.rtb.quantserve.com';
export const QUANTCAST_CALLBACK_URL_TEST = 's2s-canary.quantserve.com';
export const QUANTCAST_TEST_PUBLISHER = 'test-publisher';

/**
* The documentation for Prebid.js Adapter 1.0 can be found at link below,
Expand Down Expand Up @@ -35,7 +35,7 @@ export const spec = {
return false;
}

if (bid.mediaType === "video") {
if (bid.mediaType === 'video') {
return false;
}

Expand All @@ -62,7 +62,7 @@ export const spec = {
// 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:":
case 'https:':
publisherTagURL = `https://${QUANTCAST_CALLBACK_URL}:8443/qchb`;
publisherTagURLTest = `https://${QUANTCAST_CALLBACK_URL_TEST}:8443/qchb`;
break;
Expand Down Expand Up @@ -112,7 +112,7 @@ export const spec = {

return {
data,
method: "POST",
method: 'POST',
url,
withCredentials: true
};
Expand All @@ -137,10 +137,10 @@ export const spec = {

if (
response === undefined ||
!response.hasOwnProperty("bids") ||
!response.hasOwnProperty('bids') ||
utils.isEmpty(response.bids)
) {
utils.logError("Sub-optimal JSON received from Quantcast server");
utils.logError('Sub-optimal JSON received from Quantcast server');
return [];
}

Expand Down
112 changes: 56 additions & 56 deletions test/spec/modules/quantcastBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,130 +1,130 @@
import * as utils from "src/utils";
import { expect } from "chai";
import * as utils from 'src/utils';
import { expect } from 'chai';
import {
spec as qcSpec,
QUANTCAST_CALLBACK_URL,
QUANTCAST_CALLBACK_URL_TEST
} from "../../../modules/quantcastBidAdapter";
import { newBidder } from "../../../src/adapters/bidderFactory";
} from '../../../modules/quantcastBidAdapter';
import { newBidder } from '../../../src/adapters/bidderFactory';

describe("Quantcast adapter", () => {
describe('Quantcast adapter', () => {
const quantcastAdapter = newBidder(qcSpec);
let bidRequest;

beforeEach(() => {
bidRequest = {
bidder: "quantcast",
bidId: "2f7b179d443f14",
requestId: "595ffa73-d78a-46c9-b18e-f99548a5be6b",
bidderRequestId: "1cc026909c24c8",
placementCode: "div-gpt-ad-1438287399331-0",
bidder: 'quantcast',
bidId: '2f7b179d443f14',
requestId: '595ffa73-d78a-46c9-b18e-f99548a5be6b',
bidderRequestId: '1cc026909c24c8',
placementCode: 'div-gpt-ad-1438287399331-0',
params: {
publisherId: "test-publisher", // REQUIRED - Publisher ID provided by Quantcast
publisherId: '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]]
};
});

describe("inherited functions", () => {
it("exists and is a function", () => {
expect(quantcastAdapter.callBids).to.exist.and.to.be.a("function");
describe('inherited functions', () => {
it('exists and is a function', () => {
expect(quantcastAdapter.callBids).to.exist.and.to.be.a('function');
});
});

describe("`isBidRequestValid`", () => {
it("should return `false` when bid is not passed", () => {
describe('`isBidRequestValid`', () => {
it('should return `false` when bid is not passed', () => {
expect(qcSpec.isBidRequestValid()).to.equal(false);
});

it("should return `false` when bid `mediaType` is `video`", () => {
const bidRequest = { mediaType: "video" };
it('should return `false` when bid `mediaType` is `video`', () => {
const bidRequest = { mediaType: 'video' };

expect(qcSpec.isBidRequestValid(bidRequest)).to.equal(false);
});

it("should return `true` when bid contains required params", () => {
const bidRequest = { mediaType: "banner" };
it('should return `true` when bid contains required params', () => {
const bidRequest = { mediaType: 'banner' };

expect(qcSpec.isBidRequestValid(bidRequest)).to.equal(true);
});
});

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

switch (window.location.protocol) {
case "https:":
expect(requests[0]["url"]).to.equal(
case 'https:':
expect(requests[0]['url']).to.equal(
`https://${QUANTCAST_CALLBACK_URL_TEST}:8443/qchb`
);
break;
default:
expect(requests[0]["url"]).to.equal(
expect(requests[0]['url']).to.equal(
`http://${QUANTCAST_CALLBACK_URL_TEST}:8080/qchb`
);
break;
}
});

it("sends bid requests to Quantcast Global Endpoint for regular `publisherId`", () => {
it('sends bid requests to Quantcast Global Endpoint for regular `publisherId`', () => {
const bidRequest = {
bidder: "quantcast",
bidId: "2f7b179d443f14",
requestId: "595ffa73-d78a-46c9-b18e-f99548a5be6b",
bidderRequestId: "1cc026909c24c8",
placementCode: "div-gpt-ad-1438287399331-0",
bidder: 'quantcast',
bidId: '2f7b179d443f14',
requestId: '595ffa73-d78a-46c9-b18e-f99548a5be6b',
bidderRequestId: '1cc026909c24c8',
placementCode: 'div-gpt-ad-1438287399331-0',
params: {
publisherId: "regular-publisher", // REQUIRED - Publisher ID provided by Quantcast
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]]
};
const requests = qcSpec.buildRequests([bidRequest]);

switch (window.location.protocol) {
case "https:":
expect(requests[0]["url"]).to.equal(
case 'https:':
expect(requests[0]['url']).to.equal(
`https://${QUANTCAST_CALLBACK_URL}:8443/qchb`
);
break;
default:
expect(requests[0]["url"]).to.equal(
expect(requests[0]['url']).to.equal(
`http://${QUANTCAST_CALLBACK_URL}:8080/qchb`
);
break;
}
});

it("sends bid requests to Quantcast Header Bidding Endpoints via POST", () => {
it('sends bid requests to Quantcast Header Bidding Endpoints via POST', () => {
const requests = qcSpec.buildRequests([bidRequest]);

expect(requests[0].method).to.equal("POST");
expect(requests[0].method).to.equal('POST');
});

it("sends bid requests with `withCredentials` enabled", () => {
it('sends bid requests with `withCredentials` enabled', () => {
const requests = qcSpec.buildRequests([bidRequest]);

expect(requests[0].withCredentials).to.equal(true);
});

it("sends bid requests contains all the required parameters", () => {
it('sends bid requests contains all the required parameters', () => {
const referrer = utils.getTopWindowUrl();
const loc = utils.getTopWindowLocation();
const domain = loc.hostname;

const requests = qcSpec.buildRequests([bidRequest]);
const expectedBidRequest = {
publisherId: "test-publisher",
requestId: "2f7b179d443f14",
publisherId: 'test-publisher',
requestId: '2f7b179d443f14',
imp: [
{
banner: {
battr: [1, 2],
size: [{ width: 300, height: 250 }]
},
placementCode: "div-gpt-ad-1438287399331-0",
placementCode: 'div-gpt-ad-1438287399331-0',
bidFloor: 1e-10
}
],
Expand All @@ -133,22 +133,22 @@ describe("Quantcast adapter", () => {
referrer,
domain
},
bidId: "2f7b179d443f14"
bidId: '2f7b179d443f14'
};

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

describe("`interpretResponse`", () => {
describe('`interpretResponse`', () => {
// The sample response is from https://wiki.corp.qc/display/adinf/QCX
const response = {
bidderCode: "qcx", // Renaming it to use CamelCase since that is what is used in the Prebid.js variable name
requestId: "erlangcluster@qa-rtb002.us-ec.adtech.com-11417780270886458", // Added this field. This is not used now but could be useful in troubleshooting later on. Specially for sites using iFrames
bidderCode: 'qcx', // Renaming it to use CamelCase since that is what is used in the Prebid.js variable name
requestId: 'erlangcluster@qa-rtb002.us-ec.adtech.com-11417780270886458', // Added this field. This is not used now but could be useful in troubleshooting later on. Specially for sites using iFrames
bids: [
{
statusCode: 1,
placementCode: "imp1", // Changing this to placementCode to be reflective
placementCode: 'imp1', // Changing this to placementCode to be reflective
cpm: 4.5,
ad:
'<!DOCTYPE html><div style="height: 250; width: 300; display: table-cell; vertical-align: middle;"><div style="width: 300px; margin-left: auto; margin-right: auto;"><script src="https://adserver.adtechus.com/addyn/3.0/5399.1/2394397/0/-1/QUANTCAST;size=300x250;target=_blank;alias=;kvp36=;sub1=;kvl=;kvc=;kvs=300x250;kvi=;kva=;sub2=;rdclick=http://exch.quantserve.com/r?a=;labels=_qc.clk,_click.adserver.rtb,_click.rand.;rtbip=;rtbdata2=;redirecturl2=" type="text/javascript"></script><img src="https://exch.quantserve.com/pixel/p_12345.gif?media=ad&p=&r=&rand=&labels=_qc.imp,_imp.adserver.rtb&rtbip=&rtbdata2=" style="display: none;" border="0" height="1" width="1" alt="Quantcast"/></div></div>',
Expand All @@ -158,43 +158,43 @@ describe("Quantcast adapter", () => {
]
};

it("should return an empty array if `serverResponse` is `undefined`", () => {
it('should return an empty array if `serverResponse` is `undefined`', () => {
const interpretedResponse = qcSpec.interpretResponse();

expect(interpretedResponse.length).to.equal(0);
});

it("should return an empty array if the parsed response does NOT include `bids`", () => {
it('should return an empty array if the parsed response does NOT include `bids`', () => {
const interpretedResponse = qcSpec.interpretResponse({});

expect(interpretedResponse.length).to.equal(0);
});

it("should return an empty array if the parsed response has an empty `bids`", () => {
it('should return an empty array if the parsed response has an empty `bids`', () => {
const interpretedResponse = qcSpec.interpretResponse({ bids: [] });

expect(interpretedResponse.length).to.equal(0);
});

it("should get correct bid response", () => {
it('should get correct bid response', () => {
const expectedResponse = {
ad:
'<!DOCTYPE html><div style="height: 250; width: 300; display: table-cell; vertical-align: middle;"><div style="width: 300px; margin-left: auto; margin-right: auto;"><script src="https://adserver.adtechus.com/addyn/3.0/5399.1/2394397/0/-1/QUANTCAST;size=300x250;target=_blank;alias=;kvp36=;sub1=;kvl=;kvc=;kvs=300x250;kvi=;kva=;sub2=;rdclick=http://exch.quantserve.com/r?a=;labels=_qc.clk,_click.adserver.rtb,_click.rand.;rtbip=;rtbdata2=;redirecturl2=" type="text/javascript"></script><img src="https://exch.quantserve.com/pixel/p_12345.gif?media=ad&p=&r=&rand=&labels=_qc.imp,_imp.adserver.rtb&rtbip=&rtbdata2=" style="display: none;" border="0" height="1" width="1" alt="Quantcast"/></div></div>',
cpm: 4.5,
width: 300,
height: 250,
requestId: "erlangcluster@qa-rtb002.us-ec.adtech.com-11417780270886458",
bidderCode: "qcx"
requestId: 'erlangcluster@qa-rtb002.us-ec.adtech.com-11417780270886458',
bidderCode: 'qcx'
};
const interpretedResponse = qcSpec.interpretResponse(response);

expect(interpretedResponse[0]).to.deep.equal(expectedResponse);
});

it("handles no bid response", () => {
it('handles no bid response', () => {
const response = {
bidderCode: "qcx", // Renaming it to use CamelCase since that is what is used in the Prebid.js variable name
requestId: "erlangcluster@qa-rtb002.us-ec.adtech.com-11417780270886458", // Added this field. This is not used now but could be useful in troubleshooting later on. Specially for sites using iFrames
bidderCode: 'qcx', // Renaming it to use CamelCase since that is what is used in the Prebid.js variable name
requestId: 'erlangcluster@qa-rtb002.us-ec.adtech.com-11417780270886458', // Added this field. This is not used now but could be useful in troubleshooting later on. Specially for sites using iFrames
bids: []
};
const expectedResponse = [];
Expand Down

0 comments on commit abf387a

Please sign in to comment.