Skip to content

Commit

Permalink
Core: make video cache timeout configurable (#9578)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgirardi authored Mar 13, 2023
1 parent 1e4235f commit 7a75340
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/videoCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
* This trickery helps integrate with ad servers, which set character limits on request params.
*/

import { ajax } from './ajax.js';
import { config } from './config.js';
import {ajaxBuilder} from './ajax.js';
import {config} from './config.js';
import {auctionManager} from './auctionManager.js';

/**
Expand Down Expand Up @@ -142,11 +142,11 @@ function shimStorageCallback(done) {
* @param {videoCacheStoreCallback} [done] An optional callback which should be executed after
* the data has been stored in the cache.
*/
export function store(bids, done) {
export function store(bids, done, getAjax = ajaxBuilder) {
const requestData = {
puts: bids.map(toStorageRequest)
};

const ajax = getAjax(config.getConfig('cache.timeout'));
ajax(config.getConfig('cache.url'), shimStorageCallback(done), JSON.stringify(requestData), {
contentType: 'text/plain',
withCredentials: true
Expand Down
23 changes: 23 additions & 0 deletions test/spec/videoCache_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,29 @@ describe('The video cache', function () {
config.resetConfig();
});

describe('cache.timeout', () => {
let getAjax, cb;
beforeEach(() => {
getAjax = sinon.stub().callsFake(() => sinon.stub());
cb = sinon.stub();
});

it('should be respected', () => {
config.setConfig({
cache: {
timeout: 1
}
});
store([{ vastUrl: 'my-mock-url.com' }], cb, getAjax);
sinon.assert.calledWith(getAjax, 1);
});

it('should use default when not specified', () => {
store([], cb, getAjax);
sinon.assert.calledWith(getAjax, undefined);
})
});

it('should execute the callback with a successful result when store() is called', function () {
const uuid = 'c488b101-af3e-4a99-b538-00423e5a3371';
const callback = fakeServerCall(
Expand Down

0 comments on commit 7a75340

Please sign in to comment.