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

Add support to pass custom key in Prebid cache request #3437

Merged
merged 4 commits into from
Feb 6, 2019
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
10 changes: 8 additions & 2 deletions src/videoCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,17 @@ function wrapURI(uri, impUrl) {
*/
function toStorageRequest(bid) {
const vastValue = bid.vastXml ? bid.vastXml : wrapURI(bid.vastUrl, bid.vastImpUrl);
return {
let payload = {
type: 'xml',
value: vastValue,
ttlseconds: Number(bid.ttl)
};

if (typeof bid.customCacheKey === 'string' && bid.customCacheKey !== '') {
payload.key = bid.customCacheKey;
}

return payload;
}

/**
Expand Down Expand Up @@ -114,7 +120,7 @@ function shimStorageCallback(done) {
*
* @param {CacheableBid[]} bids A list of bid objects which should be cached.
* @param {videoCacheStoreCallback} [done] An optional callback which should be executed after
* the data has been stored in the cache.
* the data has been stored in the cache.
*/
export function store(bids, done) {
const requestData = {
Expand Down
37 changes: 37 additions & 0 deletions test/spec/videoCache_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,43 @@ describe('The video cache', function () {
assertRequestMade({ vastXml: vastXml, ttl: 25 }, vastXml);
});

it('should make the expected request when store() is called while supplying a custom key param', function () {
const customKey1 = 'keyword_abc_123';
const customKey2 = 'other_xyz_789';
const vastXml1 = '<VAST version="3.0">test1</VAST>';
const vastXml2 = '<VAST version="3.0">test2</VAST>';

const bids = [{
vastXml: vastXml1,
ttl: 25,
customCacheKey: customKey1
}, {
vastXml: vastXml2,
ttl: 25,
customCacheKey: customKey2
}];

store(bids, function () { });
const request = requests[0];
request.method.should.equal('POST');
request.url.should.equal('https://prebid.adnxs.com/pbc/v1/cache');
request.requestHeaders['Content-Type'].should.equal('text/plain;charset=utf-8');
let payload = {
puts: [{
type: 'xml',
value: vastXml1,
ttlseconds: 25,
key: customKey1
}, {
type: 'xml',
value: vastXml2,
ttlseconds: 25,
key: customKey2
}]
};
JSON.parse(request.requestBody).should.deep.equal(payload);
});

function assertRequestMade(bid, expectedValue) {
store([bid], function() { });

Expand Down