Skip to content

Commit

Permalink
Make default s2s ttl configurable (#5419)
Browse files Browse the repository at this point in the history
* make default s2s ttl configurable
  • Loading branch information
patmmccann authored Jul 2, 2020
1 parent 8c87a9e commit af604da
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
4 changes: 3 additions & 1 deletion modules/prebidServerBidAdapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ config.setDefaults({
* @property {string} endpoint endpoint to contact
* === optional params below ===
* @property {number} [timeout] timeout for S2S bidders - should be lower than `pbjs.requestBids({timeout})`
* @property {number} [defaultTtl] ttl for S2S bidders when pbs does not return a ttl on the response - defaults to 60`
* @property {boolean} [cacheMarkup] whether to cache the adm result
* @property {string} [adapter] adapter code to use for S2S
* @property {string} [syncEndpoint] endpoint URL for syncing cookies
Expand Down Expand Up @@ -832,7 +833,8 @@ const OPEN_RTB_PROTOCOL = {
bidObject.currency = (response.cur) ? response.cur : DEFAULT_S2S_CURRENCY;

// TODO: Remove when prebid-server returns ttl and netRevenue
bidObject.ttl = (bid.ttl) ? bid.ttl : DEFAULT_S2S_TTL;
const configTtl = _s2sConfig.defaultTtl || DEFAULT_S2S_TTL;
bidObject.ttl = (bid.ttl) ? bid.ttl : configTtl;
bidObject.netRevenue = (bid.netRevenue) ? bid.netRevenue : DEFAULT_S2S_NETREVENUE;

bids.push({ adUnit: bid.impid, bid: bidObject });
Expand Down
27 changes: 27 additions & 0 deletions test/spec/modules/prebidServerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1702,6 +1702,24 @@ describe('S2S Adapter', function () {
expect(response).to.have.property('cpm', 0.5);
expect(response).to.not.have.property('vastUrl');
expect(response).to.not.have.property('videoCacheKey');
expect(response).to.have.property('ttl', 60);
});

it('respects defaultTtl', function () {
const s2sConfig = Object.assign({}, CONFIG, {
endpoint: 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction',
defaultTtl: 30
});
config.setConfig({ s2sConfig });

adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax);
server.requests[0].respond(200, {}, JSON.stringify(RESPONSE_OPENRTB));

sinon.assert.calledOnce(events.emit);
const event = events.emit.firstCall.args;
sinon.assert.calledOnce(addBidResponse);
const response = addBidResponse.firstCall.args[1];
expect(response).to.have.property('ttl', 30);
});

it('handles OpenRTB video responses', function () {
Expand Down Expand Up @@ -2155,6 +2173,15 @@ describe('S2S Adapter', function () {
})
});

it('should set default s2s ttl', function () {
config.setConfig({
s2sConfig: {
defaultTtl: 30
}
});
expect(config.getConfig('s2sConfig').defaultTtl).to.deep.equal(30);
});

it('should set syncUrlModifier', function () {
config.setConfig({
s2sConfig: {
Expand Down

0 comments on commit af604da

Please sign in to comment.