Skip to content

Commit

Permalink
add stringified schain
Browse files Browse the repository at this point in the history
  • Loading branch information
Melody Li committed Oct 15, 2019
1 parent 32c1c68 commit 4fd8634
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 121 deletions.
5 changes: 5 additions & 0 deletions modules/yieldmoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export const spec = {
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function(bidRequests) {
console.log('bid requests');
console.log(bidRequests);
let serverRequest = {
p: [],
page_url: utils.getTopWindowUrl(),
Expand Down Expand Up @@ -55,6 +57,9 @@ export const spec = {
if (tdid) {
serverRequest.tdid = tdid;
}
if (request.schain) {
serverRequest.schain = JSON.stringify(request.schain);
}
});
serverRequest.p = '[' + serverRequest.p.toString() + ']';
return {
Expand Down
242 changes: 121 additions & 121 deletions test/spec/AnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,175 +20,175 @@ describe(`
FEATURE: Analytics Adapters API
SCENARIO: A publisher enables analytics
AND an \`example\` instance of \`AnalyticsAdapter\`\n`, () => {
let xhr;
let requests;
let adapter;

beforeEach(function () {
xhr = sinon.useFakeXMLHttpRequest();
requests = [];
xhr.onCreate = (request) => requests.push(request);
adapter = new AnalyticsAdapter(config);
});

afterEach(function () {
xhr.restore();
adapter.disableAnalytics();
});

it(`SHOULD call the endpoint WHEN an event occurs that is to be tracked`, function () {
const eventType = BID_REQUESTED;
const args = { some: 'data' };

adapter.track({ eventType, args });

let result = JSON.parse(requests[0].requestBody);
expect(result).to.deep.equal({args: {some: 'data'}, eventType: 'bidRequested'});
});

it(`SHOULD queue the event first and then track it WHEN an event occurs before tracking library is available`, function () {
const eventType = BID_RESPONSE;
const args = { wat: 'wot' };

events.emit(eventType, args);
adapter.enableAnalytics();

let result = JSON.parse(requests[0].requestBody);
expect(result).to.deep.equal({args: {wat: 'wot'}, eventType: 'bidResponse'});
});
let xhr;
let requests;
let adapter;

describe(`WHEN an event occurs after enable analytics\n`, function () {
beforeEach(function () {
sinon.stub(events, 'getEvents').returns([]); // these tests shouldn't be affected by previous tests
xhr = sinon.useFakeXMLHttpRequest();
requests = [];
xhr.onCreate = (request) => requests.push(request);
adapter = new AnalyticsAdapter(config);
});

afterEach(function () {
events.getEvents.restore();
xhr.restore();
adapter.disableAnalytics();
});

it('SHOULD call global when a bidWon event occurs', function () {
const eventType = BID_WON;
const args = { more: 'info' };
it(`SHOULD call the endpoint WHEN an event occurs that is to be tracked`, function () {
const eventType = BID_REQUESTED;
const args = { some: 'data' };

adapter.enableAnalytics();
events.emit(eventType, args);
adapter.track({ eventType, args });

let result = JSON.parse(requests[0].requestBody);
expect(result).to.deep.equal({args: {more: 'info'}, eventType: 'bidWon'});
expect(result).to.deep.equal({args: {some: 'data'}, eventType: 'bidRequested'});
});

it('SHOULD call global when a adRenderFailed event occurs', function () {
const eventType = AD_RENDER_FAILED;
const args = { call: 'adRenderFailed' };
it(`SHOULD queue the event first and then track it WHEN an event occurs before tracking library is available`, function () {
const eventType = BID_RESPONSE;
const args = { wat: 'wot' };

adapter.enableAnalytics();
events.emit(eventType, args);
adapter.enableAnalytics();

let result = JSON.parse(requests[0].requestBody);
expect(result).to.deep.equal({args: {call: 'adRenderFailed'}, eventType: 'adRenderFailed'});
expect(result).to.deep.equal({args: {wat: 'wot'}, eventType: 'bidResponse'});
});

it('SHOULD call global when an addAdUnits event occurs', function () {
const eventType = ADD_AD_UNITS;
const args = { call: 'addAdUnits' };
describe(`WHEN an event occurs after enable analytics\n`, function () {
beforeEach(function () {
sinon.stub(events, 'getEvents').returns([]); // these tests shouldn't be affected by previous tests
});

adapter.enableAnalytics();
events.emit(eventType, args);
afterEach(function () {
events.getEvents.restore();
});

let result = JSON.parse(requests[0].requestBody);
expect(result).to.deep.equal({args: {call: 'addAdUnits'}, eventType: 'addAdUnits'});
});
it('SHOULD call global when a bidWon event occurs', function () {
const eventType = BID_WON;
const args = { more: 'info' };

it('SHOULD call global when a requestBids event occurs', function () {
const eventType = REQUEST_BIDS;
const args = { call: 'request' };
adapter.enableAnalytics();
events.emit(eventType, args);

adapter.enableAnalytics();
events.emit(eventType, args);
let result = JSON.parse(requests[0].requestBody);
expect(result).to.deep.equal({args: {more: 'info'}, eventType: 'bidWon'});
});

let result = JSON.parse(requests[0].requestBody);
expect(result).to.deep.equal({args: {call: 'request'}, eventType: 'requestBids'});
});
it('SHOULD call global when a adRenderFailed event occurs', function () {
const eventType = AD_RENDER_FAILED;
const args = { call: 'adRenderFailed' };

it('SHOULD call global when a bidRequest event occurs', function () {
const eventType = BID_REQUESTED;
const args = { call: 'request' };
adapter.enableAnalytics();
events.emit(eventType, args);

adapter.enableAnalytics();
events.emit(eventType, args);
let result = JSON.parse(requests[0].requestBody);
expect(result).to.deep.equal({args: {call: 'adRenderFailed'}, eventType: 'adRenderFailed'});
});

let result = JSON.parse(requests[0].requestBody);
expect(result).to.deep.equal({args: {call: 'request'}, eventType: 'bidRequested'});
});
it('SHOULD call global when an addAdUnits event occurs', function () {
const eventType = ADD_AD_UNITS;
const args = { call: 'addAdUnits' };

it('SHOULD call global when a bidResponse event occurs', function () {
const eventType = BID_RESPONSE;
const args = { call: 'response' };
adapter.enableAnalytics();
events.emit(eventType, args);

adapter.enableAnalytics();
events.emit(eventType, args);
let result = JSON.parse(requests[0].requestBody);
expect(result).to.deep.equal({args: {call: 'addAdUnits'}, eventType: 'addAdUnits'});
});

let result = JSON.parse(requests[0].requestBody);
expect(result).to.deep.equal({args: {call: 'response'}, eventType: 'bidResponse'});
});
it('SHOULD call global when a requestBids event occurs', function () {
const eventType = REQUEST_BIDS;
const args = { call: 'request' };

it('SHOULD call global when a bidTimeout event occurs', function () {
const eventType = BID_TIMEOUT;
const args = { call: 'timeout' };
adapter.enableAnalytics();
events.emit(eventType, args);

adapter.enableAnalytics();
events.emit(eventType, args);
let result = JSON.parse(requests[0].requestBody);
expect(result).to.deep.equal({args: {call: 'request'}, eventType: 'requestBids'});
});

let result = JSON.parse(requests[0].requestBody);
expect(result).to.deep.equal({args: {call: 'timeout'}, eventType: 'bidTimeout'});
});
it('SHOULD call global when a bidRequest event occurs', function () {
const eventType = BID_REQUESTED;
const args = { call: 'request' };

it('SHOULD NOT call global again when adapter.enableAnalytics is called with previous timeout', function () {
const eventType = BID_TIMEOUT;
const args = { call: 'timeout' };
adapter.enableAnalytics();
events.emit(eventType, args);

events.emit(eventType, args);
adapter.enableAnalytics();
events.emit(eventType, args);
let result = JSON.parse(requests[0].requestBody);
expect(result).to.deep.equal({args: {call: 'request'}, eventType: 'bidRequested'});
});

expect(requests.length).to.equal(1);
});
it('SHOULD call global when a bidResponse event occurs', function () {
const eventType = BID_RESPONSE;
const args = { call: 'response' };

describe(`AND sampling is enabled\n`, function () {
const eventType = BID_WON;
const args = { more: 'info' };
adapter.enableAnalytics();
events.emit(eventType, args);

beforeEach(function () {
sinon.stub(Math, 'random').returns(0.5);
let result = JSON.parse(requests[0].requestBody);
expect(result).to.deep.equal({args: {call: 'response'}, eventType: 'bidResponse'});
});

afterEach(function () {
Math.random.restore();
it('SHOULD call global when a bidTimeout event occurs', function () {
const eventType = BID_TIMEOUT;
const args = { call: 'timeout' };

adapter.enableAnalytics();
events.emit(eventType, args);

let result = JSON.parse(requests[0].requestBody);
expect(result).to.deep.equal({args: {call: 'timeout'}, eventType: 'bidTimeout'});
});

it(`THEN should enable analytics when random number is in sample range`, function () {
adapter.enableAnalytics({
options: {
sampling: 0.75
}
});
it('SHOULD NOT call global again when adapter.enableAnalytics is called with previous timeout', function () {
const eventType = BID_TIMEOUT;
const args = { call: 'timeout' };

events.emit(eventType, args);
adapter.enableAnalytics();
events.emit(eventType, args);

expect(requests.length).to.equal(1);
let result = JSON.parse(requests[0].requestBody);
expect(result).to.deep.equal({args: {more: 'info'}, eventType: 'bidWon'});
});

it(`THEN should disable analytics when random number is outside sample range`, function () {
adapter.enableAnalytics({
options: {
sampling: 0.25
}
describe(`AND sampling is enabled\n`, function () {
const eventType = BID_WON;
const args = { more: 'info' };

beforeEach(function () {
sinon.stub(Math, 'random').returns(0.5);
});

afterEach(function () {
Math.random.restore();
});

it(`THEN should enable analytics when random number is in sample range`, function () {
adapter.enableAnalytics({
options: {
sampling: 0.75
}
});
events.emit(eventType, args);

expect(requests.length).to.equal(1);
let result = JSON.parse(requests[0].requestBody);
expect(result).to.deep.equal({args: {more: 'info'}, eventType: 'bidWon'});
});
events.emit(eventType, args);

expect(requests.length).to.equal(0);
it(`THEN should disable analytics when random number is outside sample range`, function () {
adapter.enableAnalytics({
options: {
sampling: 0.25
}
});
events.emit(eventType, args);

expect(requests.length).to.equal(0);
});
});
});
});
});
7 changes: 7 additions & 0 deletions test/spec/modules/yieldmoBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ describe('YieldmoAdapter', function () {
const data = spec.buildRequests([unifiedIdBid]).data;
expect(data.tdid).to.deep.equal(tdid);
});

it('should add schain if it is in the bidRequest', () => {
const schain = {'ver': '1.0', 'complete': 1, 'nodes': [{'asi': 'indirectseller.com', 'sid': '00001', 'hp': 1}]};
bidArray[0].schain = schain;
const request = spec.buildRequests([bidArray[0]]);
expect(request.data.schain).equal(JSON.stringify(schain));
})
});

describe('interpretResponse', function () {
Expand Down

0 comments on commit 4fd8634

Please sign in to comment.