From 4fd8634f12133945ac44e9b550237321e71fc549 Mon Sep 17 00:00:00 2001 From: Melody Li Date: Tue, 15 Oct 2019 15:05:08 -0400 Subject: [PATCH] add stringified schain --- modules/yieldmoBidAdapter.js | 5 + test/spec/AnalyticsAdapter_spec.js | 242 ++++++++++---------- test/spec/modules/yieldmoBidAdapter_spec.js | 7 + 3 files changed, 133 insertions(+), 121 deletions(-) diff --git a/modules/yieldmoBidAdapter.js b/modules/yieldmoBidAdapter.js index fd09cbaa4ea..eaa053456d0 100644 --- a/modules/yieldmoBidAdapter.js +++ b/modules/yieldmoBidAdapter.js @@ -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(), @@ -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 { diff --git a/test/spec/AnalyticsAdapter_spec.js b/test/spec/AnalyticsAdapter_spec.js index 59138b03e61..c211cf15c6b 100644 --- a/test/spec/AnalyticsAdapter_spec.js +++ b/test/spec/AnalyticsAdapter_spec.js @@ -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); + }); }); }); }); -}); diff --git a/test/spec/modules/yieldmoBidAdapter_spec.js b/test/spec/modules/yieldmoBidAdapter_spec.js index 60fe25db95e..803e4b012ed 100644 --- a/test/spec/modules/yieldmoBidAdapter_spec.js +++ b/test/spec/modules/yieldmoBidAdapter_spec.js @@ -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 () {