diff --git a/modules/nanointeractiveBidAdapter.js b/modules/nanointeractiveBidAdapter.js
index afcfef1f5b6..a1eab2cbbb2 100644
--- a/modules/nanointeractiveBidAdapter.js
+++ b/modules/nanointeractiveBidAdapter.js
@@ -12,6 +12,7 @@ export const CATEGORY = 'category';
export const CATEGORY_NAME = 'categoryName';
export const SUB_ID = 'subId';
export const REF = 'ref';
+export const LOCATION = 'loc';
export const spec = {
@@ -52,6 +53,7 @@ function createSingleBidRequest (bid) {
sizes: bid.sizes.map(value => value[0] + 'x' + value[1]),
bidId: bid.bidId,
cors: utils.getOrigin(),
+ [LOCATION]: createLocationParam(),
};
}
@@ -85,6 +87,10 @@ function createRefParam (bid) {
return bid.params[REF] ? null : utils.getTopWindowReferrer() || null;
}
+function createLocationParam () {
+ return utils.getTopWindowLocation().href;
+}
+
function isEngineResponseValid (response) {
return !!response.cpm && !!response.ad;
}
diff --git a/test/spec/modules/nanointeractiveBidAdapter_spec.js b/test/spec/modules/nanointeractiveBidAdapter_spec.js
index f93cc546859..1aecb8ab06b 100644
--- a/test/spec/modules/nanointeractiveBidAdapter_spec.js
+++ b/test/spec/modules/nanointeractiveBidAdapter_spec.js
@@ -20,7 +20,8 @@ describe('nanointeractive adapter tests', function () {
const BID_ID_PARAM = 'bidId';
const BID_ID_VALUE = '24a1c9ec270973';
const CORS_PARAM = 'cors';
- const DATA_PARTNER_PIXEL_ID_VALUE = 'pid1';
+ const LOC_PARAM = 'loc';
+ const DATA_PARTNER_PIXEL_ID_VALUE = 'testPID';
const NQ_VALUE = 'rumpelstiltskin';
const NQ_NAME_QUERY_PARAM = 'nqName';
const CATEGORY_VALUE = 'some category';
@@ -36,7 +37,7 @@ describe('nanointeractive adapter tests', function () {
const AD = ' ';
const CPM = 1;
- function getBidResponse (pid, nq, category, subId, cors, ref) {
+ function getBidResponse (pid, nq, category, subId, cors, ref, loc) {
return {
[DATA_PARTNER_PIXEL_ID]: pid,
[NQ]: nq,
@@ -46,8 +47,10 @@ describe('nanointeractive adapter tests', function () {
[SIZES_PARAM]: [WIDTH1 + 'x' + HEIGHT1, WIDTH2 + 'x' + HEIGHT2],
[BID_ID_PARAM]: BID_ID_VALUE,
[CORS_PARAM]: cors,
+ [LOC_PARAM]: loc,
};
}
+
function getBidRequest (params) {
return {
bidder: BIDDER_CODE,
@@ -187,12 +190,33 @@ describe('nanointeractive adapter tests', function () {
[SUB_ID]: SUB_ID_VALUE,
}))).to.equal(false);
});
- it('Test buildRequest() - pid', function () {
+
+ let sandbox;
+
+ function getMocks () {
+ let mockWindowLocationAddress = 'http://some-location.test';
let mockOriginAddress = 'http://localhost';
let mockRefAddress = 'http://some-ref.test';
- let sandbox = sinon.sandbox.create();
- sandbox.stub(utils, 'getOrigin').callsFake(() => mockOriginAddress);
- sandbox.stub(utils, 'getTopWindowReferrer').callsFake(() => mockRefAddress);
+ return {
+ 'windowLocationAddress': mockWindowLocationAddress,
+ 'originAddress': mockOriginAddress,
+ 'refAddress': mockRefAddress,
+ };
+ }
+
+ function setUpMocks (mockRefAddress = null) {
+ sandbox = sinon.sandbox.create();
+ sandbox.stub(utils, 'getOrigin').callsFake(() => getMocks()['originAddress']);
+ sandbox.stub(utils, 'getTopWindowLocation').callsFake(() => {
+ return {
+ 'href': getMocks()['windowLocationAddress']
+ };
+ });
+ if (mockRefAddress == null) {
+ sandbox.stub(utils, 'getTopWindowReferrer').callsFake(() => getMocks()['refAddress']);
+ } else {
+ sandbox.stub(utils, 'getTopWindowReferrer').callsFake(() => mockRefAddress);
+ }
sandbox.stub(utils, 'getParameterByName').callsFake((arg) => {
switch (arg) {
case CATEGORY_NAME_QUERY_PARAM:
@@ -201,520 +225,242 @@ describe('nanointeractive adapter tests', function () {
return NQ_VALUE;
}
});
- let testInput =
- {
- requestParams: {
- [DATA_PARTNER_PIXEL_ID]: DATA_PARTNER_PIXEL_ID_VALUE,
- },
- expectedPid: DATA_PARTNER_PIXEL_ID_VALUE,
- expectedNq: [null],
- expectedCategory: [null],
- expectedSubId: null,
- expectedCors: mockOriginAddress,
- expectedRef: mockRefAddress,
- };
- let request = nanoBidAdapter.buildRequests([
- getBidRequest(testInput.requestParams)]);
+ }
+
+ function assert (
+ request,
+ expectedPid,
+ expectedNq,
+ expectedCategory,
+ expectedSubId,
+ expectedRef = getMocks()['refAddress'],
+ expectedOrigin = getMocks()['originAddress'],
+ expectedLocation = getMocks()['windowLocationAddress']
+ ) {
expect(request.method).to.equal('POST');
expect(request.url).to.equal(ENGINE_BASE_URL);
expect(request.data).to.equal(JSON.stringify([
getBidResponse(
- testInput.expectedPid,
- testInput.expectedNq,
- testInput.expectedCategory,
- testInput.expectedSubId,
- testInput.expectedCors,
- testInput.expectedRef
+ expectedPid,
+ expectedNq,
+ expectedCategory,
+ expectedSubId,
+ expectedOrigin,
+ expectedRef,
+ expectedLocation,
),
]));
+ }
+
+ function tearDownMocks () {
sandbox.restore();
+ }
+
+ it('Test buildRequest() - pid', function () {
+ setUpMocks();
+ let requestParams = {
+ [DATA_PARTNER_PIXEL_ID]: DATA_PARTNER_PIXEL_ID_VALUE,
+ };
+ let expectedPid = DATA_PARTNER_PIXEL_ID_VALUE;
+ let expectedNq = [null];
+ let expectedCategory = [null];
+ let expectedSubId = null;
+
+ let request = nanoBidAdapter.buildRequests([getBidRequest(requestParams)]);
+
+ assert(request, expectedPid, expectedNq, expectedCategory, expectedSubId);
+ tearDownMocks();
});
it('Test buildRequest() - pid, nq', function () {
- let mockOriginAddress = 'http://localhost';
- let mockRefAddress = 'http://some-ref.test';
- let sandbox = sinon.sandbox.create();
- sandbox.stub(utils, 'getOrigin').callsFake(() => mockOriginAddress);
- sandbox.stub(utils, 'getTopWindowReferrer').callsFake(() => mockRefAddress);
- sandbox.stub(utils, 'getParameterByName').callsFake((arg) => {
- switch (arg) {
- case CATEGORY_NAME_QUERY_PARAM:
- return CATEGORY_VALUE;
- case NQ_NAME_QUERY_PARAM:
- return NQ_VALUE;
- }
- });
- let testInput =
- {
- requestParams: {
- [DATA_PARTNER_PIXEL_ID]: DATA_PARTNER_PIXEL_ID_VALUE,
- [NQ]: NQ_VALUE,
- },
- expectedPid: DATA_PARTNER_PIXEL_ID_VALUE,
- expectedNq: [NQ_VALUE],
- expectedCategory: [null],
- expectedSubId: null,
- expectedCors: mockOriginAddress,
- expectedRef: mockRefAddress,
- };
- let request = nanoBidAdapter.buildRequests([
- getBidRequest(testInput.requestParams)]);
- expect(request.method).to.equal('POST');
- expect(request.url).to.equal(ENGINE_BASE_URL);
- expect(request.data).to.equal(JSON.stringify([
- getBidResponse(
- testInput.expectedPid,
- testInput.expectedNq,
- testInput.expectedCategory,
- testInput.expectedSubId,
- testInput.expectedCors,
- testInput.expectedRef
- ),
- ]));
- sandbox.restore();
+ setUpMocks();
+ let requestParams = {
+ [DATA_PARTNER_PIXEL_ID]: DATA_PARTNER_PIXEL_ID_VALUE,
+ [NQ]: NQ_VALUE,
+ };
+ let expectedPid = DATA_PARTNER_PIXEL_ID_VALUE;
+ let expectedNq = [NQ_VALUE];
+ let expectedCategory = [null];
+ let expectedSubId = null;
+
+ let request = nanoBidAdapter.buildRequests([getBidRequest(requestParams)]);
+
+ assert(request, expectedPid, expectedNq, expectedCategory, expectedSubId);
+ tearDownMocks();
});
it('Test buildRequest() - pid, nq, category', function () {
- let mockOriginAddress = 'http://localhost';
- let mockRefAddress = 'http://some-ref.test';
- let sandbox = sinon.sandbox.create();
- sandbox.stub(utils, 'getOrigin').callsFake(() => mockOriginAddress);
- sandbox.stub(utils, 'getTopWindowReferrer').callsFake(() => mockRefAddress);
- sandbox.stub(utils, 'getParameterByName').callsFake((arg) => {
- switch (arg) {
- case CATEGORY_NAME_QUERY_PARAM:
- return CATEGORY_VALUE;
- case NQ_NAME_QUERY_PARAM:
- return NQ_VALUE;
- }
- });
- let testInput =
- {
- requestParams: {
- [DATA_PARTNER_PIXEL_ID]: DATA_PARTNER_PIXEL_ID_VALUE,
- [NQ]: NQ_VALUE,
- [CATEGORY]: CATEGORY_VALUE,
- },
- expectedPid: DATA_PARTNER_PIXEL_ID_VALUE,
- expectedNq: [NQ_VALUE],
- expectedCategory: [CATEGORY_VALUE],
- expectedSubId: null,
- expectedCors: mockOriginAddress,
- expectedRef: mockRefAddress,
- };
- let request = nanoBidAdapter.buildRequests([
- getBidRequest(testInput.requestParams)]);
- expect(request.method).to.equal('POST');
- expect(request.url).to.equal(ENGINE_BASE_URL);
- expect(request.data).to.equal(JSON.stringify([
- getBidResponse(
- testInput.expectedPid,
- testInput.expectedNq,
- testInput.expectedCategory,
- testInput.expectedSubId,
- testInput.expectedCors,
- testInput.expectedRef
- ),
- ]));
- sandbox.restore();
+ setUpMocks();
+ let requestParams = {
+ [DATA_PARTNER_PIXEL_ID]: DATA_PARTNER_PIXEL_ID_VALUE,
+ [NQ]: NQ_VALUE,
+ [CATEGORY]: CATEGORY_VALUE,
+ };
+ let expectedPid = DATA_PARTNER_PIXEL_ID_VALUE;
+ let expectedNq = [NQ_VALUE];
+ let expectedCategory = [CATEGORY_VALUE];
+ let expectedSubId = null;
+
+ let request = nanoBidAdapter.buildRequests([getBidRequest(requestParams)]);
+
+ assert(request, expectedPid, expectedNq, expectedCategory, expectedSubId);
+ tearDownMocks();
});
it('Test buildRequest() - pid, nq, categoryName', function () {
- let mockOriginAddress = 'http://localhost';
- let mockRefAddress = 'http://some-ref.test';
- let sandbox = sinon.sandbox.create();
- sandbox.stub(utils, 'getOrigin').callsFake(() => mockOriginAddress);
- sandbox.stub(utils, 'getTopWindowReferrer').callsFake(() => mockRefAddress);
- sandbox.stub(utils, 'getParameterByName').callsFake((arg) => {
- switch (arg) {
- case CATEGORY_NAME_QUERY_PARAM:
- return CATEGORY_VALUE;
- case NQ_NAME_QUERY_PARAM:
- return NQ_VALUE;
- }
- });
- let testInput =
- {
- requestParams: {
- [DATA_PARTNER_PIXEL_ID]: DATA_PARTNER_PIXEL_ID_VALUE,
- [NQ]: NQ_VALUE,
- [CATEGORY_NAME]: CATEGORY_NAME_QUERY_PARAM,
- },
- expectedPid: DATA_PARTNER_PIXEL_ID_VALUE,
- expectedNq: [NQ_VALUE],
- expectedCategory: [CATEGORY_VALUE],
- expectedSubId: null,
- expectedCors: mockOriginAddress,
- expectedRef: mockRefAddress,
- };
- let request = nanoBidAdapter.buildRequests([
- getBidRequest(testInput.requestParams)]);
- expect(request.method).to.equal('POST');
- expect(request.url).to.equal(ENGINE_BASE_URL);
- expect(request.data).to.equal(JSON.stringify([
- getBidResponse(
- testInput.expectedPid,
- testInput.expectedNq,
- testInput.expectedCategory,
- testInput.expectedSubId,
- testInput.expectedCors,
- testInput.expectedRef
- ),
- ]));
- sandbox.restore();
+ setUpMocks();
+
+ let requestParams = {
+ [DATA_PARTNER_PIXEL_ID]: DATA_PARTNER_PIXEL_ID_VALUE,
+ [NQ]: NQ_VALUE,
+ [CATEGORY_NAME]: CATEGORY_NAME_QUERY_PARAM,
+ };
+ let expectedPid = DATA_PARTNER_PIXEL_ID_VALUE;
+ let expectedNq = [NQ_VALUE];
+ let expectedCategory = [CATEGORY_VALUE];
+ let expectedSubId = null;
+
+ let request = nanoBidAdapter.buildRequests([getBidRequest(requestParams)]);
+
+ assert(request, expectedPid, expectedNq, expectedCategory, expectedSubId);
+ tearDownMocks();
});
it('Test buildRequest() - pid, nq, subId', function () {
- let mockOriginAddress = 'http://localhost';
- let mockRefAddress = 'http://some-ref.test';
- let sandbox = sinon.sandbox.create();
- sandbox.stub(utils, 'getOrigin').callsFake(() => mockOriginAddress);
- sandbox.stub(utils, 'getTopWindowReferrer').callsFake(() => mockRefAddress);
- sandbox.stub(utils, 'getParameterByName').callsFake((arg) => {
- switch (arg) {
- case CATEGORY_NAME_QUERY_PARAM:
- return CATEGORY_VALUE;
- case NQ_NAME_QUERY_PARAM:
- return NQ_VALUE;
- }
- });
- let testInput =
- {
- requestParams: {
- [DATA_PARTNER_PIXEL_ID]: DATA_PARTNER_PIXEL_ID_VALUE,
- [NQ]: NQ_VALUE,
- [SUB_ID]: SUB_ID_VALUE,
- },
- expectedPid: DATA_PARTNER_PIXEL_ID_VALUE,
- expectedNq: [NQ_VALUE],
- expectedCategory: [null],
- expectedSubId: SUB_ID_VALUE,
- expectedCors: mockOriginAddress,
- expectedRef: mockRefAddress,
- };
- let request = nanoBidAdapter.buildRequests([
- getBidRequest(testInput.requestParams)]);
- expect(request.method).to.equal('POST');
- expect(request.url).to.equal(ENGINE_BASE_URL);
- expect(request.data).to.equal(JSON.stringify([
- getBidResponse(
- testInput.expectedPid,
- testInput.expectedNq,
- testInput.expectedCategory,
- testInput.expectedSubId,
- testInput.expectedCors,
- testInput.expectedRef
- ),
- ]));
- sandbox.restore();
+ setUpMocks();
+ let requestParams = {
+ [DATA_PARTNER_PIXEL_ID]: DATA_PARTNER_PIXEL_ID_VALUE,
+ [NQ]: NQ_VALUE,
+ [SUB_ID]: SUB_ID_VALUE,
+ };
+ let expectedPid = DATA_PARTNER_PIXEL_ID_VALUE;
+ let expectedNq = [NQ_VALUE];
+ let expectedCategory = [null];
+ let expectedSubId = SUB_ID_VALUE;
+
+ let request = nanoBidAdapter.buildRequests([getBidRequest(requestParams)]);
+
+ assert(request, expectedPid, expectedNq, expectedCategory, expectedSubId);
+ tearDownMocks();
});
it('Test buildRequest() - pid, category', function () {
- let mockOriginAddress = 'http://localhost';
- let mockRefAddress = 'http://some-ref.test';
- let sandbox = sinon.sandbox.create();
- sandbox.stub(utils, 'getOrigin').callsFake(() => mockOriginAddress);
- sandbox.stub(utils, 'getTopWindowReferrer').callsFake(() => mockRefAddress);
- sandbox.stub(utils, 'getParameterByName').callsFake((arg) => {
- switch (arg) {
- case CATEGORY_NAME_QUERY_PARAM:
- return CATEGORY_VALUE;
- case NQ_NAME_QUERY_PARAM:
- return NQ_VALUE;
- }
- });
- let testInput =
- {
- requestParams: {
- [DATA_PARTNER_PIXEL_ID]: DATA_PARTNER_PIXEL_ID_VALUE,
- [CATEGORY]: CATEGORY_VALUE,
- },
- expectedPid: DATA_PARTNER_PIXEL_ID_VALUE,
- expectedNq: [null],
- expectedCategory: [CATEGORY_VALUE],
- expectedSubId: null,
- expectedCors: mockOriginAddress,
- expectedRef: mockRefAddress,
- };
- let request = nanoBidAdapter.buildRequests([
- getBidRequest(testInput.requestParams)]);
- expect(request.method).to.equal('POST');
- expect(request.url).to.equal(ENGINE_BASE_URL);
- expect(request.data).to.equal(JSON.stringify([
- getBidResponse(
- testInput.expectedPid,
- testInput.expectedNq,
- testInput.expectedCategory,
- testInput.expectedSubId,
- testInput.expectedCors,
- testInput.expectedRef
- ),
- ]));
- sandbox.restore();
+ setUpMocks();
+ let requestParams = {
+ [DATA_PARTNER_PIXEL_ID]: DATA_PARTNER_PIXEL_ID_VALUE,
+ [CATEGORY]: CATEGORY_VALUE,
+ };
+ let expectedPid = DATA_PARTNER_PIXEL_ID_VALUE;
+ let expectedNq = [null];
+ let expectedCategory = [CATEGORY_VALUE];
+ let expectedSubId = null;
+
+ let request = nanoBidAdapter.buildRequests([getBidRequest(requestParams)]);
+
+ assert(request, expectedPid, expectedNq, expectedCategory, expectedSubId);
+ tearDownMocks();
});
it('Test buildRequest() - pid, category, subId', function () {
- let mockOriginAddress = 'http://localhost';
- let mockRefAddress = 'http://some-ref.test';
- let sandbox = sinon.sandbox.create();
- sandbox.stub(utils, 'getOrigin').callsFake(() => mockOriginAddress);
- sandbox.stub(utils, 'getTopWindowReferrer').callsFake(() => mockRefAddress);
- sandbox.stub(utils, 'getParameterByName').callsFake((arg) => {
- switch (arg) {
- case CATEGORY_NAME_QUERY_PARAM:
- return CATEGORY_VALUE;
- case NQ_NAME_QUERY_PARAM:
- return NQ_VALUE;
- }
- });
- let testInput =
- {
- requestParams: {
- [DATA_PARTNER_PIXEL_ID]: DATA_PARTNER_PIXEL_ID_VALUE,
- [CATEGORY]: CATEGORY_VALUE,
- [SUB_ID]: SUB_ID_VALUE,
- },
- expectedPid: DATA_PARTNER_PIXEL_ID_VALUE,
- expectedNq: [null],
- expectedCategory: [CATEGORY_VALUE],
- expectedSubId: SUB_ID_VALUE,
- expectedCors: mockOriginAddress,
- expectedRef: mockRefAddress,
- };
- let request = nanoBidAdapter.buildRequests([
- getBidRequest(testInput.requestParams)]);
- expect(request.method).to.equal('POST');
- expect(request.url).to.equal(ENGINE_BASE_URL);
- expect(request.data).to.equal(JSON.stringify([
- getBidResponse(
- testInput.expectedPid,
- testInput.expectedNq,
- testInput.expectedCategory,
- testInput.expectedSubId,
- testInput.expectedCors,
- testInput.expectedRef
- ),
- ]));
- sandbox.restore();
+ setUpMocks();
+ let requestParams = {
+ [DATA_PARTNER_PIXEL_ID]: DATA_PARTNER_PIXEL_ID_VALUE,
+ [CATEGORY]: CATEGORY_VALUE,
+ [SUB_ID]: SUB_ID_VALUE,
+ };
+ let expectedPid = DATA_PARTNER_PIXEL_ID_VALUE;
+ let expectedNq = [null];
+ let expectedCategory = [CATEGORY_VALUE];
+ let expectedSubId = SUB_ID_VALUE;
+
+ let request = nanoBidAdapter.buildRequests([getBidRequest(requestParams)]);
+
+ assert(request, expectedPid, expectedNq, expectedCategory, expectedSubId);
+ tearDownMocks();
});
it('Test buildRequest() - pid, subId', function () {
- let mockOriginAddress = 'http://localhost';
- let mockRefAddress = 'http://some-ref.test';
- let sandbox = sinon.sandbox.create();
- sandbox.stub(utils, 'getOrigin').callsFake(() => mockOriginAddress);
- sandbox.stub(utils, 'getTopWindowReferrer').callsFake(() => mockRefAddress);
- sandbox.stub(utils, 'getParameterByName').callsFake((arg) => {
- switch (arg) {
- case CATEGORY_NAME_QUERY_PARAM:
- return CATEGORY_VALUE;
- case NQ_NAME_QUERY_PARAM:
- return NQ_VALUE;
- }
- });
- let testInput =
- {
- requestParams: {
- [DATA_PARTNER_PIXEL_ID]: DATA_PARTNER_PIXEL_ID_VALUE,
- [SUB_ID]: SUB_ID_VALUE,
- },
- expectedPid: DATA_PARTNER_PIXEL_ID_VALUE,
- expectedNq: [null],
- expectedCategory: [null],
- expectedSubId: SUB_ID_VALUE,
- expectedCors: mockOriginAddress,
- expectedRef: mockRefAddress,
- };
- let request = nanoBidAdapter.buildRequests([
- getBidRequest(testInput.requestParams)]);
- expect(request.method).to.equal('POST');
- expect(request.url).to.equal(ENGINE_BASE_URL);
- expect(request.data).to.equal(JSON.stringify([
- getBidResponse(
- testInput.expectedPid,
- testInput.expectedNq,
- testInput.expectedCategory,
- testInput.expectedSubId,
- testInput.expectedCors,
- testInput.expectedRef
- ),
- ]));
- sandbox.restore();
+ setUpMocks();
+ let requestParams = {
+ [DATA_PARTNER_PIXEL_ID]: DATA_PARTNER_PIXEL_ID_VALUE,
+ [SUB_ID]: SUB_ID_VALUE,
+ };
+ let expectedPid = DATA_PARTNER_PIXEL_ID_VALUE;
+ let expectedNq = [null];
+ let expectedCategory = [null];
+ let expectedSubId = SUB_ID_VALUE;
+
+ let request = nanoBidAdapter.buildRequests([getBidRequest(requestParams)]);
+
+ assert(request, expectedPid, expectedNq, expectedCategory, expectedSubId);
+ tearDownMocks();
});
it('Test buildRequest() - pid, nq, category, subId', function () {
- let mockOriginAddress = 'http://localhost';
- let mockRefAddress = 'http://some-ref.test';
- let sandbox = sinon.sandbox.create();
- sandbox.stub(utils, 'getOrigin').callsFake(() => mockOriginAddress);
- sandbox.stub(utils, 'getTopWindowReferrer').callsFake(() => mockRefAddress);
- sandbox.stub(utils, 'getParameterByName').callsFake((arg) => {
- switch (arg) {
- case CATEGORY_NAME_QUERY_PARAM:
- return CATEGORY_VALUE;
- case NQ_NAME_QUERY_PARAM:
- return NQ_VALUE;
- }
- });
- let testInput =
- {
- requestParams: {
- [DATA_PARTNER_PIXEL_ID]: DATA_PARTNER_PIXEL_ID_VALUE,
- [NQ]: NQ_VALUE,
- [CATEGORY]: CATEGORY_VALUE,
- [SUB_ID]: SUB_ID_VALUE,
- },
- expectedPid: DATA_PARTNER_PIXEL_ID_VALUE,
- expectedNq: [NQ_VALUE],
- expectedCategory: [CATEGORY_VALUE],
- expectedSubId: SUB_ID_VALUE,
- expectedCors: mockOriginAddress,
- expectedRef: mockRefAddress,
- };
- let request = nanoBidAdapter.buildRequests([
- getBidRequest(testInput.requestParams)]);
- expect(request.method).to.equal('POST');
- expect(request.url).to.equal(ENGINE_BASE_URL);
- expect(request.data).to.equal(JSON.stringify([
- getBidResponse(
- testInput.expectedPid,
- testInput.expectedNq,
- testInput.expectedCategory,
- testInput.expectedSubId,
- testInput.expectedCors,
- testInput.expectedRef
- ),
- ]));
- sandbox.restore();
+ setUpMocks();
+ let requestParams = {
+ [DATA_PARTNER_PIXEL_ID]: DATA_PARTNER_PIXEL_ID_VALUE,
+ [NQ]: NQ_VALUE,
+ [CATEGORY]: CATEGORY_VALUE,
+ [SUB_ID]: SUB_ID_VALUE,
+ };
+ let expectedPid = DATA_PARTNER_PIXEL_ID_VALUE;
+ let expectedNq = [NQ_VALUE];
+ let expectedCategory = [CATEGORY_VALUE];
+ let expectedSubId = SUB_ID_VALUE;
+
+ let request = nanoBidAdapter.buildRequests([getBidRequest(requestParams)]);
+
+ assert(request, expectedPid, expectedNq, expectedCategory, expectedSubId);
+ tearDownMocks();
});
it('Test buildRequest() - pid, nqName, categoryName, subId', function () {
- let mockOriginAddress = 'http://localhost';
- let mockRefAddress = 'http://some-ref.test';
- let sandbox = sinon.sandbox.create();
- sandbox.stub(utils, 'getOrigin').callsFake(() => mockOriginAddress);
- sandbox.stub(utils, 'getTopWindowReferrer').callsFake(() => mockRefAddress);
- sandbox.stub(utils, 'getParameterByName').callsFake((arg) => {
- switch (arg) {
- case CATEGORY_NAME_QUERY_PARAM:
- return CATEGORY_VALUE;
- case NQ_NAME_QUERY_PARAM:
- return NQ_VALUE;
- }
- });
- let testInput =
- {
- requestParams: {
- [DATA_PARTNER_PIXEL_ID]: DATA_PARTNER_PIXEL_ID_VALUE,
- [NQ_NAME]: NQ_NAME_QUERY_PARAM,
- [CATEGORY_NAME]: CATEGORY_NAME_QUERY_PARAM,
- [SUB_ID]: SUB_ID_VALUE,
- },
- expectedPid: DATA_PARTNER_PIXEL_ID_VALUE,
- expectedNq: [NQ_VALUE],
- expectedCategory: [CATEGORY_VALUE],
- expectedSubId: SUB_ID_VALUE,
- expectedCors: mockOriginAddress,
- expectedRef: mockRefAddress,
- };
- let request = nanoBidAdapter.buildRequests([
- getBidRequest(testInput.requestParams)]);
- expect(request.method).to.equal('POST');
- expect(request.url).to.equal(ENGINE_BASE_URL);
- expect(request.data).to.equal(JSON.stringify([
- getBidResponse(
- testInput.expectedPid,
- testInput.expectedNq,
- testInput.expectedCategory,
- testInput.expectedSubId,
- testInput.expectedCors,
- testInput.expectedRef
- ),
- ]));
- sandbox.restore();
+ setUpMocks();
+ let requestParams = {
+ [DATA_PARTNER_PIXEL_ID]: DATA_PARTNER_PIXEL_ID_VALUE,
+ [NQ_NAME]: NQ_NAME_QUERY_PARAM,
+ [CATEGORY_NAME]: CATEGORY_NAME_QUERY_PARAM,
+ [SUB_ID]: SUB_ID_VALUE,
+ };
+ let expectedPid = DATA_PARTNER_PIXEL_ID_VALUE;
+ let expectedNq = [NQ_VALUE];
+ let expectedCategory = [CATEGORY_VALUE];
+ let expectedSubId = SUB_ID_VALUE;
+
+ let request = nanoBidAdapter.buildRequests([getBidRequest(requestParams)]);
+
+ assert(request, expectedPid, expectedNq, expectedCategory, expectedSubId);
+ tearDownMocks();
});
it('Test buildRequest() - pid, nq, category, subId, ref (value none)', function () {
- let mockOriginAddress = 'http://localhost';
- let mockRefAddress = 'http://some-ref.test';
- let sandbox = sinon.sandbox.create();
- sandbox.stub(utils, 'getOrigin').callsFake(() => mockOriginAddress);
- sandbox.stub(utils, 'getTopWindowReferrer').callsFake(() => mockRefAddress);
- sandbox.stub(utils, 'getParameterByName').callsFake((arg) => {
- switch (arg) {
- case CATEGORY_NAME_QUERY_PARAM:
- return CATEGORY_VALUE;
- case NQ_NAME_QUERY_PARAM:
- return NQ_VALUE;
- }
- });
- let testInput =
- {
- requestParams: {
- [DATA_PARTNER_PIXEL_ID]: DATA_PARTNER_PIXEL_ID_VALUE,
- [NQ]: NQ_VALUE,
- [CATEGORY]: CATEGORY_VALUE,
- [SUB_ID]: SUB_ID_VALUE,
- [REF]: REF_NO_VALUE,
- },
- expectedPid: DATA_PARTNER_PIXEL_ID_VALUE,
- expectedNq: [NQ_VALUE],
- expectedCategory: [CATEGORY_VALUE],
- expectedSubId: SUB_ID_VALUE,
- expectedCors: mockOriginAddress,
- expectedRef: null,
- };
- let request = nanoBidAdapter.buildRequests([
- getBidRequest(testInput.requestParams)]);
- expect(request.method).to.equal('POST');
- expect(request.url).to.equal(ENGINE_BASE_URL);
- expect(request.data).to.equal(JSON.stringify([
- getBidResponse(
- testInput.expectedPid,
- testInput.expectedNq,
- testInput.expectedCategory,
- testInput.expectedSubId,
- testInput.expectedCors,
- testInput.expectedRef
- ),
- ]));
- sandbox.restore();
+ setUpMocks(null);
+ let requestParams = {
+ [DATA_PARTNER_PIXEL_ID]: DATA_PARTNER_PIXEL_ID_VALUE,
+ [NQ]: NQ_VALUE,
+ [CATEGORY]: CATEGORY_VALUE,
+ [SUB_ID]: SUB_ID_VALUE,
+ [REF]: REF_NO_VALUE,
+ };
+ let expectedPid = DATA_PARTNER_PIXEL_ID_VALUE;
+ let expectedNq = [NQ_VALUE];
+ let expectedCategory = [CATEGORY_VALUE];
+ let expectedSubId = SUB_ID_VALUE;
+
+ let request = nanoBidAdapter.buildRequests([getBidRequest(requestParams)]);
+
+ assert(request, expectedPid, expectedNq, expectedCategory, expectedSubId, null);
+ tearDownMocks();
});
it('Test buildRequest() - pid, nq, category, subId, ref (value other)', function () {
- let mockOriginAddress = 'http://localhost';
- let mockRefAddress = 'http://some-ref.test';
- let sandbox = sinon.sandbox.create();
- sandbox.stub(utils, 'getOrigin').callsFake(() => mockOriginAddress);
- sandbox.stub(utils, 'getTopWindowReferrer').callsFake(() => mockRefAddress);
- sandbox.stub(utils, 'getParameterByName').callsFake((arg) => {
- switch (arg) {
- case CATEGORY_NAME_QUERY_PARAM:
- return CATEGORY_VALUE;
- case NQ_NAME_QUERY_PARAM:
- return NQ_VALUE;
- }
- });
- let testInput =
- {
- requestParams: {
- [DATA_PARTNER_PIXEL_ID]: DATA_PARTNER_PIXEL_ID_VALUE,
- [NQ]: NQ_VALUE,
- [CATEGORY]: CATEGORY_VALUE,
- [SUB_ID]: SUB_ID_VALUE,
- [REF]: REF_OTHER_VALUE,
- },
- expectedPid: DATA_PARTNER_PIXEL_ID_VALUE,
- expectedNq: [NQ_VALUE],
- expectedCategory: [CATEGORY_VALUE],
- expectedSubId: SUB_ID_VALUE,
- expectedCors: mockOriginAddress,
- expectedRef: null,
- };
- let request = nanoBidAdapter.buildRequests([
- getBidRequest(testInput.requestParams)]);
- expect(request.method).to.equal('POST');
- expect(request.url).to.equal(ENGINE_BASE_URL);
- expect(request.data).to.equal(JSON.stringify([
- getBidResponse(
- testInput.expectedPid,
- testInput.expectedNq,
- testInput.expectedCategory,
- testInput.expectedSubId,
- testInput.expectedCors,
- testInput.expectedRef
- ),
- ]));
- sandbox.restore();
+ setUpMocks(null);
+ let requestParams = {
+ [DATA_PARTNER_PIXEL_ID]: DATA_PARTNER_PIXEL_ID_VALUE,
+ [NQ]: NQ_VALUE,
+ [CATEGORY]: CATEGORY_VALUE,
+ [SUB_ID]: SUB_ID_VALUE,
+ [REF]: REF_OTHER_VALUE,
+ };
+ let expectedPid = DATA_PARTNER_PIXEL_ID_VALUE;
+ let expectedNq = [NQ_VALUE];
+ let expectedCategory = [CATEGORY_VALUE];
+ let expectedSubId = SUB_ID_VALUE;
+
+ let request = nanoBidAdapter.buildRequests([getBidRequest(requestParams)]);
+
+ assert(request, expectedPid, expectedNq, expectedCategory, expectedSubId, null);
+ tearDownMocks();
});
it('Test interpretResponse() length', function () {
let bids = nanoBidAdapter.interpretResponse({