Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PBjs Core: make video cache timeout configurable #9578

Merged
merged 1 commit into from
Mar 13, 2023
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
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