Skip to content

Commit

Permalink
fixed unit tests for buildRequestSite
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgeluisrocha committed Jun 28, 2022
1 parent 9aea3bc commit dc2e4db
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
8 changes: 3 additions & 5 deletions modules/jwplayerBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function buildRequest(bidRequest, bidderRequest) {
const openrtbRequest = {
id: bidRequest.bidId,
imp: buildRequestImpression(bidRequest, bidderRequest),
site: buildRequestSite(bidRequest),
site: buildRequestSite(bidderRequest),
device: buildRequestDevice()
};

Expand Down Expand Up @@ -170,15 +170,13 @@ function buildBidFloorData(bidRequest) {
return floorData;
}

function buildRequestSite(bidRequest) {
/* eslint-disable no-console */
function buildRequestSite(bidderRequest) {
const site = config.getConfig('ortb2.site') || {};
console.log(site);

site.domain = site.domain || config.publisherDomain || window.location.hostname;
site.page = site.page || config.pageUrl || window.location.href;

const referer = bidRequest.refererInfo && bidRequest.refererInfo.referer;
const referer = bidderRequest.refererInfo && bidderRequest.refererInfo.referer;
if (!site.ref && referer) {
site.ref = referer;
}
Expand Down
22 changes: 10 additions & 12 deletions test/spec/modules/jwplayerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,16 @@ describe('jwplayer adapter tests', function() {
let sandbox = sinon.sandbox.create();
sandbox.stub(config, 'getConfig').callsFake((key) => {
const config = {
'ortb2': {
site: {
domain: 'page.example.com',
page: 'https://examplepage.com'
}
'ortb2.site': {
domain: 'page.example.com',
page: 'https://examplepage.com'
}
};
return config[key];
})
});

const serverRequests = spec.buildRequests(bidRequests, this.defaultBidderRequest);

/* eslint-disable no-console */

serverRequests.forEach(serverRequest => {
expect(serverRequest.url).to.have.string('https://ib.adnxs.com/openrtb2/prebid');
expect(serverRequest.method).to.equal('POST');
Expand All @@ -87,11 +83,11 @@ describe('jwplayer adapter tests', function() {
expect(openrtbRequest.site).to.not.equal(null);
expect(openrtbRequest.site).to.be.an('object');
expect(openrtbRequest.site.domain).to.be.a('string');
expect(openrtbRequest.site.domain).to.equal('page.example.com');
expect(openrtbRequest.site.domain).to.have.string('page.example.com');
expect(openrtbRequest.site.page).to.be.a('string');
expect(openrtbRequest.site.page).to.equal('https://examplepage.com');
expect(openrtbRequest.site.page).to.have.string('https://examplepage.com');
expect(openrtbRequest.site.ref).to.be.a('string');
expect(openrtbRequest.site.ref).to.equal('https://example.com');
expect(openrtbRequest.site.ref).to.have.string('https://example.com');

expect(openrtbRequest.device).to.not.equal(null);
expect(openrtbRequest.device.ua).to.equal(navigator.userAgent);
Expand All @@ -111,7 +107,9 @@ describe('jwplayer adapter tests', function() {
expect(openrtbRequest.regs.ext).to.not.equal(null);
expect(openrtbRequest.regs.ext.gdpr).to.equal(1);
expect(openrtbRequest.regs.ext.us_privacy).to.equal(true);
})
});

sandbox.restore();
});
});

Expand Down

0 comments on commit dc2e4db

Please sign in to comment.