Skip to content

Commit

Permalink
Remove callback and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Léo GRAND committed Jul 16, 2019
1 parent 0c541cd commit 480f9b4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 71 deletions.
26 changes: 5 additions & 21 deletions modules/sublimeBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -85,29 +84,14 @@ 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) +
'&currency=' + encodeURIComponent(response.currency || 'USD') +
'&v=' + SUBLIME_VERSION
);
return xhr;
};
window.sublime.pbjs.injected.requestId = requestId;
window.sublime.pbjs.injected.version = SUBLIME_VERSION;

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
Expand Down
52 changes: 2 additions & 50 deletions test/spec/modules/sublimeBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('Sublime Adapter', function() {
requestId: 'xyz654',
params: {
zoneId: 23651,
callbackName: 'myCallback'
callbackName: 'false'
}
}, {
bidder: 'sublime',
Expand All @@ -52,7 +52,7 @@ describe('Sublime Adapter', function() {
requestId: 'xyz654_2',
params: {
zoneId: 23651,
callbackName: 'myCallback'
callbackName: 'false'
}
}
];
Expand Down Expand Up @@ -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() {
Expand All @@ -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: '<h1>oh</h1>',
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() {
Expand Down

0 comments on commit 480f9b4

Please sign in to comment.