Skip to content

Commit

Permalink
PubMatic to support passing content object set in pbjs.setConfig (#5592)
Browse files Browse the repository at this point in the history
* added support for pubcommon, digitrust, id5id

* added support for IdentityLink

* changed the source for id5

* added unit test cases

* changed source param for identityLink

* read content object from config and send it in site.content and app.content

* do not use content object from config if content object is present in app as app.content

* fixed the test-cases

* app.content related test cases
  • Loading branch information
pm-harshad-mane authored Aug 14, 2020
1 parent 22a59bd commit 7ede93b
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
10 changes: 10 additions & 0 deletions modules/pubmaticBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,11 @@ export const spec = {
payload.site.page = conf.kadpageurl.trim() || payload.site.page.trim();
payload.site.domain = _getDomainFromURL(payload.site.page);

// add the content object from config in request
if (typeof config.getConfig('content') === 'object') {
payload.site.content = config.getConfig('content');
}

// merge the device from config.getConfig('device')
if (typeof config.getConfig('device') === 'object') {
payload.device = Object.assign(payload.device, config.getConfig('device'));
Expand Down Expand Up @@ -910,6 +915,11 @@ export const spec = {
// not copying domain from site as it is a derived value from page
payload.app.publisher = payload.site.publisher;
payload.app.ext = payload.site.ext || UNDEFINED;
// We will also need to pass content object in app.content if app object is also set into the config;
// BUT do not use content object from config if content object is present in app as app.content
if (typeof payload.app.content !== 'object') {
payload.app.content = payload.site.content || UNDEFINED;
}
delete payload.site;
}

Expand Down
73 changes: 73 additions & 0 deletions test/spec/modules/pubmaticBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,23 @@ describe('PubMatic adapter', function () {
expect(data.source.ext.schain).to.deep.equal(bidRequests[0].schain);
});

it('Set content from config, set site.content', function() {
let sandbox = sinon.sandbox.create();
const content = {
'id': 'alpha-numeric-id'
};
sandbox.stub(config, 'getConfig').callsFake((key) => {
var config = {
content: content
};
return config[key];
});
let request = spec.buildRequests(bidRequests);
let data = JSON.parse(request.data);
expect(data.site.content).to.deep.equal(content);
sandbox.restore();
});

it('Merge the device info from config', function() {
let sandbox = sinon.sandbox.create();
sandbox.stub(config, 'getConfig').callsFake((key) => {
Expand Down Expand Up @@ -840,6 +857,62 @@ describe('PubMatic adapter', function () {
sandbox.restore();
});

it('Set app, content from config, copy publisher and ext from site, unset site, config.content in app.content', function() {
let sandbox = sinon.sandbox.create();
const content = {
'id': 'alpha-numeric-id'
};
sandbox.stub(config, 'getConfig').callsFake((key) => {
var config = {
content: content,
app: {
bundle: 'org.prebid.mobile.demoapp',
domain: 'prebid.org'
}
};
return config[key];
});
let request = spec.buildRequests(bidRequests);
let data = JSON.parse(request.data);
expect(data.app.bundle).to.equal('org.prebid.mobile.demoapp');
expect(data.app.domain).to.equal('prebid.org');
expect(data.app.publisher.id).to.equal(bidRequests[0].params.publisherId);
expect(data.app.ext.key_val).to.exist.and.to.equal(bidRequests[0].params.dctr);
expect(data.app.content).to.deep.equal(content);
expect(data.site).to.not.exist;
sandbox.restore();
});

it('Set app.content, content from config, copy publisher and ext from site, unset site, config.app.content in app.content', function() {
let sandbox = sinon.sandbox.create();
const content = {
'id': 'alpha-numeric-id'
};
const appContent = {
id: 'app-content-id-2'
};
sandbox.stub(config, 'getConfig').callsFake((key) => {
var config = {
content: content,
app: {
bundle: 'org.prebid.mobile.demoapp',
domain: 'prebid.org',
content: appContent
}
};
return config[key];
});
let request = spec.buildRequests(bidRequests);
let data = JSON.parse(request.data);
expect(data.app.bundle).to.equal('org.prebid.mobile.demoapp');
expect(data.app.domain).to.equal('prebid.org');
expect(data.app.publisher.id).to.equal(bidRequests[0].params.publisherId);
expect(data.app.ext.key_val).to.exist.and.to.equal(bidRequests[0].params.dctr);
expect(data.app.content).to.deep.equal(appContent);
expect(data.site).to.not.exist;
sandbox.restore();
});

it('Request params check: without adSlot', function () {
delete bidRequests[0].params.adSlot;
let request = spec.buildRequests(bidRequests);
Expand Down

0 comments on commit 7ede93b

Please sign in to comment.