From 49de31ff0e00ef01d55e0813b3ada3be41ce38a4 Mon Sep 17 00:00:00 2001 From: Melody Li Date: Tue, 15 Oct 2019 15:05:08 -0400 Subject: [PATCH 1/2] add stringified schain --- modules/yieldmoBidAdapter.js | 3 + test/spec/AnalyticsAdapter_spec.js | 242 ++++++++++---------- test/spec/modules/yieldmoBidAdapter_spec.js | 6 + 3 files changed, 130 insertions(+), 121 deletions(-) diff --git a/modules/yieldmoBidAdapter.js b/modules/yieldmoBidAdapter.js index 725a361789b..22b20511daf 100644 --- a/modules/yieldmoBidAdapter.js +++ b/modules/yieldmoBidAdapter.js @@ -60,6 +60,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 78cddf44e38..f143caa8c1e 100644 --- a/test/spec/modules/yieldmoBidAdapter_spec.js +++ b/test/spec/modules/yieldmoBidAdapter_spec.js @@ -172,6 +172,12 @@ describe('YieldmoAdapter', function () { 'consentString': 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==' })); }); + 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 () { From 3e384c9037c0e0d78504e609a11efbb8a612a41f Mon Sep 17 00:00:00 2001 From: Melody Li Date: Tue, 15 Oct 2019 17:33:15 -0400 Subject: [PATCH 2/2] don't change other files --- test/spec/AnalyticsAdapter_spec.js | 242 ++++++++++++++--------------- 1 file changed, 121 insertions(+), 121 deletions(-) diff --git a/test/spec/AnalyticsAdapter_spec.js b/test/spec/AnalyticsAdapter_spec.js index c211cf15c6b..59138b03e61 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; + 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'}); + }); + describe(`WHEN an event occurs after enable analytics\n`, function () { beforeEach(function () { - xhr = sinon.useFakeXMLHttpRequest(); - requests = []; - xhr.onCreate = (request) => requests.push(request); - adapter = new AnalyticsAdapter(config); + sinon.stub(events, 'getEvents').returns([]); // these tests shouldn't be affected by previous tests }); afterEach(function () { - xhr.restore(); - adapter.disableAnalytics(); + events.getEvents.restore(); }); - it(`SHOULD call the endpoint WHEN an event occurs that is to be tracked`, function () { - const eventType = BID_REQUESTED; - const args = { some: 'data' }; + it('SHOULD call global when a bidWon event occurs', function () { + const eventType = BID_WON; + const args = { more: 'info' }; - adapter.track({ eventType, args }); + adapter.enableAnalytics(); + events.emit(eventType, args); let result = JSON.parse(requests[0].requestBody); - expect(result).to.deep.equal({args: {some: 'data'}, eventType: 'bidRequested'}); + expect(result).to.deep.equal({args: {more: 'info'}, eventType: 'bidWon'}); }); - 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' }; + it('SHOULD call global when a adRenderFailed event occurs', function () { + const eventType = AD_RENDER_FAILED; + const args = { call: 'adRenderFailed' }; - events.emit(eventType, args); adapter.enableAnalytics(); + events.emit(eventType, args); let result = JSON.parse(requests[0].requestBody); - expect(result).to.deep.equal({args: {wat: 'wot'}, eventType: 'bidResponse'}); + expect(result).to.deep.equal({args: {call: 'adRenderFailed'}, eventType: 'adRenderFailed'}); }); - 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 - }); + it('SHOULD call global when an addAdUnits event occurs', function () { + const eventType = ADD_AD_UNITS; + const args = { call: 'addAdUnits' }; - afterEach(function () { - events.getEvents.restore(); - }); + adapter.enableAnalytics(); + events.emit(eventType, args); - it('SHOULD call global when a bidWon event occurs', function () { - const eventType = BID_WON; - const args = { more: 'info' }; + let result = JSON.parse(requests[0].requestBody); + expect(result).to.deep.equal({args: {call: 'addAdUnits'}, eventType: 'addAdUnits'}); + }); - adapter.enableAnalytics(); - events.emit(eventType, args); + it('SHOULD call global when a requestBids event occurs', function () { + const eventType = REQUEST_BIDS; + const args = { call: 'request' }; - let result = JSON.parse(requests[0].requestBody); - expect(result).to.deep.equal({args: {more: 'info'}, eventType: 'bidWon'}); - }); + adapter.enableAnalytics(); + events.emit(eventType, args); - it('SHOULD call global when a adRenderFailed event occurs', function () { - const eventType = AD_RENDER_FAILED; - const args = { call: 'adRenderFailed' }; + let result = JSON.parse(requests[0].requestBody); + expect(result).to.deep.equal({args: {call: 'request'}, eventType: 'requestBids'}); + }); - adapter.enableAnalytics(); - events.emit(eventType, args); + it('SHOULD call global when a bidRequest event occurs', function () { + const eventType = BID_REQUESTED; + const args = { call: 'request' }; - let result = JSON.parse(requests[0].requestBody); - expect(result).to.deep.equal({args: {call: 'adRenderFailed'}, eventType: 'adRenderFailed'}); - }); + adapter.enableAnalytics(); + events.emit(eventType, args); - it('SHOULD call global when an addAdUnits event occurs', function () { - const eventType = ADD_AD_UNITS; - const args = { call: 'addAdUnits' }; + let result = JSON.parse(requests[0].requestBody); + expect(result).to.deep.equal({args: {call: 'request'}, eventType: 'bidRequested'}); + }); - adapter.enableAnalytics(); - events.emit(eventType, args); + it('SHOULD call global when a bidResponse event occurs', function () { + const eventType = BID_RESPONSE; + const args = { call: 'response' }; - let result = JSON.parse(requests[0].requestBody); - expect(result).to.deep.equal({args: {call: 'addAdUnits'}, eventType: 'addAdUnits'}); - }); + adapter.enableAnalytics(); + events.emit(eventType, args); - it('SHOULD call global when a requestBids event occurs', function () { - const eventType = REQUEST_BIDS; - const args = { call: 'request' }; + let result = JSON.parse(requests[0].requestBody); + expect(result).to.deep.equal({args: {call: 'response'}, eventType: 'bidResponse'}); + }); - adapter.enableAnalytics(); - events.emit(eventType, args); + it('SHOULD call global when a bidTimeout event occurs', function () { + const eventType = BID_TIMEOUT; + const args = { call: 'timeout' }; - let result = JSON.parse(requests[0].requestBody); - expect(result).to.deep.equal({args: {call: 'request'}, eventType: 'requestBids'}); - }); + adapter.enableAnalytics(); + events.emit(eventType, args); - it('SHOULD call global when a bidRequest event occurs', function () { - const eventType = BID_REQUESTED; - const args = { call: 'request' }; + let result = JSON.parse(requests[0].requestBody); + expect(result).to.deep.equal({args: {call: 'timeout'}, eventType: 'bidTimeout'}); + }); - adapter.enableAnalytics(); - events.emit(eventType, args); + it('SHOULD NOT call global again when adapter.enableAnalytics is called with previous timeout', function () { + const eventType = BID_TIMEOUT; + const args = { call: 'timeout' }; - let result = JSON.parse(requests[0].requestBody); - expect(result).to.deep.equal({args: {call: 'request'}, eventType: 'bidRequested'}); - }); + events.emit(eventType, args); + adapter.enableAnalytics(); + events.emit(eventType, args); - it('SHOULD call global when a bidResponse event occurs', function () { - const eventType = BID_RESPONSE; - const args = { call: 'response' }; + expect(requests.length).to.equal(1); + }); - adapter.enableAnalytics(); - events.emit(eventType, args); + describe(`AND sampling is enabled\n`, function () { + const eventType = BID_WON; + const args = { more: 'info' }; - let result = JSON.parse(requests[0].requestBody); - expect(result).to.deep.equal({args: {call: 'response'}, eventType: 'bidResponse'}); + beforeEach(function () { + sinon.stub(Math, 'random').returns(0.5); }); - 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'}); + afterEach(function () { + Math.random.restore(); }); - 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(); + 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'}); }); - 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 disable analytics when random number is outside sample range`, function () { + adapter.enableAnalytics({ + options: { + sampling: 0.25 + } }); + events.emit(eventType, args); - 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'}); - }); - - 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); - }); + expect(requests.length).to.equal(0); }); }); }); +});