From 5db8c692e729dfcfeb6e319502603b8ecedf6e66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20GRAND?= Date: Mon, 5 Jul 2021 17:25:42 +0200 Subject: [PATCH 1/8] Update timeout value with onTimeout data --- modules/sublimeBidAdapter.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/modules/sublimeBidAdapter.js b/modules/sublimeBidAdapter.js index 5849547a835..1d375478c86 100644 --- a/modules/sublimeBidAdapter.js +++ b/modules/sublimeBidAdapter.js @@ -40,7 +40,8 @@ export function log(msg, obj) { export const state = { zoneId: '', transactionId: '', - notifyId: '' + notifyId: '', + timeout: config.getConfig('bidderTimeout'), }; /** @@ -68,7 +69,7 @@ export function sendEvent(eventName, sspName) { puid: state.transactionId || state.notifyId, notid: state.notifyId || '', pbav: SUBLIME_VERSION, - pubtimeout: config.getConfig('bidderTimeout'), + pubtimeout: state.timeout, pubpbv: '$prebid.version$', device: detectDevice(), }; @@ -234,6 +235,8 @@ function onBidWon(bid) { */ function onTimeout(timeoutData) { log('Timeout from adapter', timeoutData); + // Set timeout to the one we got from the bid + setState({timeout: timeoutData.timeout}); sendEvent('bidtimeout'); } From f4424aacd9bd71cf6b7e195ff36c9237f7b6d298 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20GRAND?= Date: Tue, 6 Jul 2021 10:25:29 +0200 Subject: [PATCH 2/8] Add test for onTimeout --- modules/sublimeBidAdapter.js | 5 +++- test/spec/modules/sublimeBidAdapter_spec.js | 27 +++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/modules/sublimeBidAdapter.js b/modules/sublimeBidAdapter.js index 1d375478c86..821723fb948 100644 --- a/modules/sublimeBidAdapter.js +++ b/modules/sublimeBidAdapter.js @@ -244,12 +244,15 @@ export const spec = { code: BIDDER_CODE, gvlid: BIDDER_GVLID, aliases: [], - sendEvent: sendEvent, isBidRequestValid: isBidRequestValid, buildRequests: buildRequests, interpretResponse: interpretResponse, onBidWon: onBidWon, onTimeout: onTimeout, + // Exposed for test purpose + sendEvent: sendEvent, + setState: setState, + state: state, }; registerBidder(spec); diff --git a/test/spec/modules/sublimeBidAdapter_spec.js b/test/spec/modules/sublimeBidAdapter_spec.js index b00b5a46160..45e5a3f83fc 100644 --- a/test/spec/modules/sublimeBidAdapter_spec.js +++ b/test/spec/modules/sublimeBidAdapter_spec.js @@ -334,6 +334,33 @@ describe('Sublime Adapter', function() { expect(params.e).to.equal('bidwon'); }); + afterEach(function () { + sandbox.restore(); + }); + }); + + describe('onTimeout', function() { + let sandbox; + const timeoutData = { + timeout: 1234 + }; + + beforeEach(function() { + sandbox = sinon.sandbox.create(); + }); + + it('should trigger "bidtimeout" pixel', function () { + sandbox.spy(utils, 'triggerPixel'); + spec.onTimeout(timeoutData); + const params = utils.parseUrl(utils.triggerPixel.args[0][0]).search; + expect(params.e).to.equal('bidtimeout'); + }); + + it('should set timeout value in state', function () { + spec.onTimeout(timeoutData); + assert.deepStrictEqual(spec.state, { timeout: 1234, debug: false, notifyId: undefined, transactionId: undefined, zoneId: 123 }) + }); + afterEach(function () { sandbox.restore(); }); From 67caea42d99dc408e3e48aae7259fe18335fad8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20GRAND?= Date: Wed, 7 Jul 2021 17:41:49 +0200 Subject: [PATCH 3/8] Use timeoutData as an array of bid --- modules/sublimeBidAdapter.js | 10 +++++++--- test/spec/modules/sublimeBidAdapter_spec.js | 5 +++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/modules/sublimeBidAdapter.js b/modules/sublimeBidAdapter.js index 821723fb948..feaeb4df316 100644 --- a/modules/sublimeBidAdapter.js +++ b/modules/sublimeBidAdapter.js @@ -222,7 +222,7 @@ function interpretResponse(serverResponse, bidRequest) { /** * Send pixel when bidWon event is triggered - * @param {Object} timeoutData + * @param {Object} bid */ function onBidWon(bid) { log('Bid won', bid); @@ -231,12 +231,16 @@ function onBidWon(bid) { /** * Send debug when we timeout - * @param {Object} timeoutData + * @param {Array[{}]} timeoutData */ function onTimeout(timeoutData) { log('Timeout from adapter', timeoutData); + + const timeout = utils.deepAccess(timeoutData, '0.timeout'); + if (timeout) { + setState({ timeout }); + } // Set timeout to the one we got from the bid - setState({timeout: timeoutData.timeout}); sendEvent('bidtimeout'); } diff --git a/test/spec/modules/sublimeBidAdapter_spec.js b/test/spec/modules/sublimeBidAdapter_spec.js index 45e5a3f83fc..bdedd46b698 100644 --- a/test/spec/modules/sublimeBidAdapter_spec.js +++ b/test/spec/modules/sublimeBidAdapter_spec.js @@ -341,9 +341,10 @@ describe('Sublime Adapter', function() { describe('onTimeout', function() { let sandbox; - const timeoutData = { + // Array of bids that timed out + const timeoutData = [{ timeout: 1234 - }; + }]; beforeEach(function() { sandbox = sinon.sandbox.create(); From 9db7198834fb2332fcceee0f85a88115880d76f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20GRAND?= Date: Wed, 7 Jul 2021 18:07:19 +0200 Subject: [PATCH 4/8] Moved comment --- modules/sublimeBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/sublimeBidAdapter.js b/modules/sublimeBidAdapter.js index feaeb4df316..ae34de7151f 100644 --- a/modules/sublimeBidAdapter.js +++ b/modules/sublimeBidAdapter.js @@ -238,9 +238,9 @@ function onTimeout(timeoutData) { const timeout = utils.deepAccess(timeoutData, '0.timeout'); if (timeout) { + // Set timeout to the one we got from the bid setState({ timeout }); } - // Set timeout to the one we got from the bid sendEvent('bidtimeout'); } From cbae7fbf3ce29f282ebde8ccad323a629bff011c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20GRAND?= Date: Thu, 8 Jul 2021 10:26:05 +0200 Subject: [PATCH 5/8] Lint and use expect --- test/spec/modules/sublimeBidAdapter_spec.js | 48 ++++++++++----------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/test/spec/modules/sublimeBidAdapter_spec.js b/test/spec/modules/sublimeBidAdapter_spec.js index bdedd46b698..24e0a449a0b 100644 --- a/test/spec/modules/sublimeBidAdapter_spec.js +++ b/test/spec/modules/sublimeBidAdapter_spec.js @@ -4,10 +4,10 @@ import { newBidder } from 'src/adapters/bidderFactory.js'; let utils = require('src/utils'); -describe('Sublime Adapter', function() { +describe('Sublime Adapter', function () { const adapter = newBidder(spec); - describe('sendEvent', function() { + describe('sendEvent', function () { let sandbox; const triggeredPixelProperties = [ 't', @@ -40,13 +40,13 @@ describe('Sublime Adapter', function() { }); }) - describe('inherited functions', function() { - it('exists and is a function', function() { + describe('inherited functions', function () { + it('exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }); - describe('isBidRequestValid', function() { + describe('isBidRequestValid', function () { const bid = { bidder: 'sublime', params: { @@ -55,18 +55,18 @@ describe('Sublime Adapter', function() { }, }; - it('should return true when required params found', function() { + it('should return true when required params found', function () { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return false when required params are not passed', function() { + it('should return false when required params are not passed', function () { const bid = Object.assign({}, bid); bid.params = {}; expect(spec.isBidRequestValid(bid)).to.equal(false); }); }); - describe('buildRequests', function() { + describe('buildRequests', function () { const bidRequests = [ { bidder: 'sublime', @@ -103,24 +103,24 @@ describe('Sublime Adapter', function() { const request = spec.buildRequests(bidRequests, bidderRequest); - it('should have a post method', function() { + it('should have a post method', function () { expect(request[0].method).to.equal('POST'); expect(request[1].method).to.equal('POST'); }); - it('should contains a request id equals to the bid id', function() { + it('should contains a request id equals to the bid id', function () { for (let i = 0; i < request.length; i = i + 1) { expect(JSON.parse(request[i].data).requestId).to.equal(bidRequests[i].bidId); } }); - it('should have an url that contains bid keyword', function() { + it('should have an url that contains bid keyword', function () { expect(request[0].url).to.match(/bid/); expect(request[1].url).to.match(/bid/); }); }); - describe('buildRequests: default arguments', function() { + describe('buildRequests: default arguments', function () { const bidRequests = [{ bidder: 'sublime', adUnitCode: 'sublime_code', @@ -134,12 +134,12 @@ describe('Sublime Adapter', function() { const request = spec.buildRequests(bidRequests); - it('should have an url that match the default endpoint', function() { + it('should have an url that match the default endpoint', function () { expect(request[0].url).to.equal('https://pbjs.sskzlabs.com/bid'); }); }); - describe('interpretResponse', function() { + describe('interpretResponse', function () { const serverResponse = { 'request_id': '3db3773286ee59', 'sspname': 'foo', @@ -147,11 +147,11 @@ describe('Sublime Adapter', function() { 'ad': '', }; - it('should get correct bid response', function() { + it('should get correct bid response', function () { // Mock the fire method top.window.sublime = { analytics: { - fire: function() {} + fire: function () { } } }; @@ -171,11 +171,11 @@ describe('Sublime Adapter', function() { ad: '', }, ]; - const result = spec.interpretResponse({body: serverResponse}); + const result = spec.interpretResponse({ body: serverResponse }); expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); }); - it('should get correct default size for 1x1', function() { + it('should get correct default size for 1x1', function () { const serverResponse = { 'requestId': 'xyz654_2', 'sspname': 'sublime', @@ -197,7 +197,7 @@ describe('Sublime Adapter', function() { } }; - const result = spec.interpretResponse({body: serverResponse}, bidRequest); + const result = spec.interpretResponse({ body: serverResponse }, bidRequest); const expectedResponse = { requestId: 'xyz654_2', @@ -301,7 +301,7 @@ describe('Sublime Adapter', function() { }); }); - it('should add advertiserDomains', function() { + it('should add advertiserDomains', function () { const responseWithAdvertiserDomains = utils.deepClone(serverResponse); responseWithAdvertiserDomains.advertiserDomains = ['a_sublime_adomain']; @@ -319,7 +319,7 @@ describe('Sublime Adapter', function() { }); }); - describe('onBidWon', function() { + describe('onBidWon', function () { let sandbox; const bid = { foo: 'bar' }; @@ -339,14 +339,14 @@ describe('Sublime Adapter', function() { }); }); - describe('onTimeout', function() { + describe('onTimeout', function () { let sandbox; // Array of bids that timed out const timeoutData = [{ timeout: 1234 }]; - beforeEach(function() { + beforeEach(function () { sandbox = sinon.sandbox.create(); }); @@ -359,7 +359,7 @@ describe('Sublime Adapter', function() { it('should set timeout value in state', function () { spec.onTimeout(timeoutData); - assert.deepStrictEqual(spec.state, { timeout: 1234, debug: false, notifyId: undefined, transactionId: undefined, zoneId: 123 }) + expect(spec.state).to.equal({ timeout: 1234, debug: false, notifyId: undefined, transactionId: undefined, zoneId: 123 }); }); afterEach(function () { From a9059ec7a61874e9460ace53cdb655411fb1b2d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20GRAND?= Date: Thu, 8 Jul 2021 10:56:24 +0200 Subject: [PATCH 6/8] Use firstCall and deep.equal --- test/spec/modules/sublimeBidAdapter_spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/spec/modules/sublimeBidAdapter_spec.js b/test/spec/modules/sublimeBidAdapter_spec.js index 24e0a449a0b..a42efaf25d2 100644 --- a/test/spec/modules/sublimeBidAdapter_spec.js +++ b/test/spec/modules/sublimeBidAdapter_spec.js @@ -353,13 +353,13 @@ describe('Sublime Adapter', function () { it('should trigger "bidtimeout" pixel', function () { sandbox.spy(utils, 'triggerPixel'); spec.onTimeout(timeoutData); - const params = utils.parseUrl(utils.triggerPixel.args[0][0]).search; + const params = utils.parseUrl(utils.triggerPixel.firstCall.firstArg).search; expect(params.e).to.equal('bidtimeout'); }); it('should set timeout value in state', function () { spec.onTimeout(timeoutData); - expect(spec.state).to.equal({ timeout: 1234, debug: false, notifyId: undefined, transactionId: undefined, zoneId: 123 }); + expect(spec.state).to.deep.equal({ timeout: 1234, debug: false, notifyId: undefined, transactionId: undefined, zoneId: 123 }); }); afterEach(function () { From 88a4ea50a637c254a1ec22475335b2e7a9b216ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20GRAND?= Date: Thu, 8 Jul 2021 10:57:35 +0200 Subject: [PATCH 7/8] Update state with timeout asap --- modules/sublimeBidAdapter.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/sublimeBidAdapter.js b/modules/sublimeBidAdapter.js index ae34de7151f..462665202a5 100644 --- a/modules/sublimeBidAdapter.js +++ b/modules/sublimeBidAdapter.js @@ -110,6 +110,8 @@ function buildRequests(validBidRequests, bidderRequest) { timeout: (typeof bidderRequest === 'object' && !!bidderRequest) ? bidderRequest.timeout : config.getConfig('bidderTimeout'), }; + setState({ timeout: commonPayload.timeout }); + // RefererInfo if (bidderRequest && bidderRequest.refererInfo) { commonPayload.referer = bidderRequest.refererInfo.referer; From 1c882d00f6ac86ec7868fff2ad3bcd66ce8be0dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20GRAND?= Date: Thu, 8 Jul 2021 14:09:54 +0200 Subject: [PATCH 8/8] Use args instead of firstCall --- test/spec/modules/sublimeBidAdapter_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/spec/modules/sublimeBidAdapter_spec.js b/test/spec/modules/sublimeBidAdapter_spec.js index a42efaf25d2..5c72c6c4dc5 100644 --- a/test/spec/modules/sublimeBidAdapter_spec.js +++ b/test/spec/modules/sublimeBidAdapter_spec.js @@ -353,7 +353,7 @@ describe('Sublime Adapter', function () { it('should trigger "bidtimeout" pixel', function () { sandbox.spy(utils, 'triggerPixel'); spec.onTimeout(timeoutData); - const params = utils.parseUrl(utils.triggerPixel.firstCall.firstArg).search; + const params = utils.parseUrl(utils.triggerPixel.args[0][0]).search; expect(params.e).to.equal('bidtimeout'); });