Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions modules/sublimeBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export function log(msg, obj) {
export const state = {
zoneId: '',
transactionId: '',
notifyId: ''
notifyId: '',
timeout: config.getConfig('bidderTimeout'),
};

/**
Expand Down Expand Up @@ -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(),
};
Expand Down Expand Up @@ -109,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;
Expand Down Expand Up @@ -221,7 +224,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);
Expand All @@ -230,23 +233,32 @@ 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) {
// Set timeout to the one we got from the bid
setState({ timeout });
}
sendEvent('bidtimeout');
}

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);
70 changes: 49 additions & 21 deletions test/spec/modules/sublimeBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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: {
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -134,24 +134,24 @@ 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',
'cpm': 0.5,
'ad': '<!-- Creative -->',
};

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 () { }
}
};

Expand All @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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'];

Expand All @@ -319,7 +319,7 @@ describe('Sublime Adapter', function() {
});
});

describe('onBidWon', function() {
describe('onBidWon', function () {
let sandbox;
const bid = { foo: 'bar' };

Expand All @@ -334,6 +334,34 @@ describe('Sublime Adapter', function() {
expect(params.e).to.equal('bidwon');
});

afterEach(function () {
sandbox.restore();
});
});

describe('onTimeout', function () {
let sandbox;
// Array of bids that timed out
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);
expect(spec.state).to.deep.equal({ timeout: 1234, debug: false, notifyId: undefined, transactionId: undefined, zoneId: 123 });
});

afterEach(function () {
sandbox.restore();
});
Expand Down