From 1dd1f25629d980c34b21a7f37c4ac21b1787659d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20GRAND?= Date: Tue, 16 Jul 2019 11:27:08 +0200 Subject: [PATCH] Remove callback and fix tests --- modules/sublimeBidAdapter.js | 35 ++++---------- test/spec/modules/sublimeBidAdapter_spec.js | 52 +-------------------- 2 files changed, 11 insertions(+), 76 deletions(-) diff --git a/modules/sublimeBidAdapter.js b/modules/sublimeBidAdapter.js index b36ee8cc330..6d3ace52885 100644 --- a/modules/sublimeBidAdapter.js +++ b/modules/sublimeBidAdapter.js @@ -5,9 +5,8 @@ import * as utils from '../src/utils'; const BIDDER_CODE = 'sublime'; const DEFAULT_BID_HOST = 'pbjs.sskzlabs.com'; const DEFAULT_SAC_HOST = 'sac.ayads.co'; -const DEFAULT_CALLBACK_NAME = 'sublime_prebid_callback'; const DEFAULT_PROTOCOL = 'https'; -const SUBLIME_VERSION = '0.3.4'; +const SUBLIME_VERSION = '0.3.5'; let SUBLIME_ZONE = null; /** @@ -66,12 +65,6 @@ export const spec = { }; } - window.sublime.pbjs = (typeof window.sublime.pbjs !== 'undefined') ? window.sublime.pbjs : {}; - window.sublime.pbjs.injected = { - bt: config.getConfig('bidderTimeout'), - ts: Date.now() - }; - // Grab only the first `validBidRequest` let bid = validBidRequests[0]; @@ -85,29 +78,19 @@ export const spec = { let sacHost = params.sacHost || DEFAULT_SAC_HOST; let bidHost = params.bidHost || DEFAULT_BID_HOST; let protocol = params.protocol || DEFAULT_PROTOCOL; - let callbackName = (params.callbackName || DEFAULT_CALLBACK_NAME) + '_' + params.zoneId; SUBLIME_ZONE = params.zoneId; - window[callbackName] = (response) => { - var requestIdEncoded = encodeURIComponent(requestId); - var hasAd = response.ad ? '1' : '0'; - var xhr = new XMLHttpRequest(); - var url = protocol + '://' + bidHost + '/notify?request_id=' + requestIdEncoded + '&a=' + hasAd + '&z=' + SUBLIME_ZONE; - xhr.open('POST', url, true); - xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); - xhr.send( - 'notify=1' + - '&request_id=' + requestIdEncoded + - '&ad=' + encodeURIComponent(response.ad || '') + - '&cpm=' + encodeURIComponent(response.cpm || 0) + - '¤cy=' + encodeURIComponent(response.currency || 'USD') + - '&v=' + SUBLIME_VERSION - ); - return xhr; + window.sublime.pbjs = (typeof window.sublime.pbjs !== 'undefined') ? window.sublime.pbjs : {}; + window.sublime.pbjs.injected = { + bt: config.getConfig('bidderTimeout'), + ts: Date.now(), + version: SUBLIME_VERSION, + requestId }; + let script = document.createElement('script'); script.type = 'application/javascript'; - script.src = 'https://' + sacHost + '/sublime/' + SUBLIME_ZONE + '/prebid?callback=' + callbackName; + script.src = 'https://' + sacHost + '/sublime/' + SUBLIME_ZONE + '/prebid?callback=false'; document.body.appendChild(script); // Initial size object diff --git a/test/spec/modules/sublimeBidAdapter_spec.js b/test/spec/modules/sublimeBidAdapter_spec.js index 9046f3a037c..faa841786c9 100644 --- a/test/spec/modules/sublimeBidAdapter_spec.js +++ b/test/spec/modules/sublimeBidAdapter_spec.js @@ -42,7 +42,7 @@ describe('Sublime Adapter', function() { requestId: 'xyz654', params: { zoneId: 23651, - callbackName: 'myCallback' + callbackName: 'false' } }, { bidder: 'sublime', @@ -52,7 +52,7 @@ describe('Sublime Adapter', function() { requestId: 'xyz654_2', params: { zoneId: 23651, - callbackName: 'myCallback' + callbackName: 'false' } } ]; @@ -86,11 +86,6 @@ describe('Sublime Adapter', function() { it('should have an url that contains bid keyword', function() { expect(request.url).to.match(/bid/); }); - - it('should create a callback function', function() { - const params = bidRequests[0].params; - expect(window[params.callbackName + '_' + params.zoneId]).to.be.an('function'); - }); }); describe('buildRequests: default arguments', function() { @@ -110,49 +105,6 @@ describe('Sublime Adapter', function() { it('should have an url that match the default endpoint', function() { expect(request.url).to.equal('https://pbjs.sskzlabs.com/bid'); }); - - it('should create a default callback function', function() { - expect(window['sublime_prebid_callback_23651']).to.be.an('function'); - }); - }); - - describe('buildRequests: test callback', function() { - let XMLHttpRequest = sinon.useFakeXMLHttpRequest(); - - let bidRequests = [{ - bidder: 'sublime', - adUnitCode: 'sublime_code', - bidId: 'abc1234', - sizes: [[1800, 1000], [640, 300]], - requestId: 'xyz654', - params: { - zoneId: 23651 - } - }]; - - spec.buildRequests(bidRequests); - - it('should execute a default callback function', function() { - let response = { - ad: '

oh

', - cpm: 2 - }; - let actual = window['sublime_prebid_callback_23651'](response); - - it('should query the notify url', function() { - expect(actual.url).to.equal('https://pbjs.sskzlabs.com/notify'); - }); - - it('should send the correct headers', function() { - expect(actual.requestHeaders).to.equal({ - 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' - }); - }); - - it('should send the correct body', function() { - expect(actual.requestBody).to.equal('notify=1&request_id=abc1234&ad=%3Ch1%3Eoh%3C%2Fh1%3E&cpm=2'); - }); - }); }); describe('interpretResponse', function() {