From 0005e2dfda57787305609d1f1b395af044fa3faa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20S=C5=82owiena?= Date: Tue, 30 Oct 2018 15:30:23 +0100 Subject: [PATCH] Change site getting method --- modules/rtbhouseBidAdapter.js | 7 +-- test/spec/modules/rtbhouseBidAdapter_spec.js | 47 ++++++++++++++------ 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/modules/rtbhouseBidAdapter.js b/modules/rtbhouseBidAdapter.js index f4036255722..406bae7b5e8 100644 --- a/modules/rtbhouseBidAdapter.js +++ b/modules/rtbhouseBidAdapter.js @@ -43,7 +43,7 @@ export const spec = { const request = { id: validBidRequests[0].auctionId, imp: validBidRequests.map(slot => mapImpression(slot)), - site: mapSite(validBidRequests), + site: mapSite(validBidRequests, bidderRequest), cur: DEFAULT_CURRENCY_ARR, test: validBidRequests[0].params.test || 0, source: { @@ -121,9 +121,10 @@ function mapBanner(slot) { /** * @param {object} slot Ad Unit Params by Prebid + * @param {object} bidderRequest by Prebid * @returns {object} Site by OpenRTB 2.5 ยง3.2.13 */ -function mapSite(slot) { +function mapSite(slot, bidderRequest) { const pubId = slot && slot.length > 0 ? slot[0].params.publisherId : 'unknown'; @@ -131,7 +132,7 @@ function mapSite(slot) { publisher: { id: pubId.toString(), }, - page: utils.getTopWindowUrl(), + page: bidderRequest.refererInfo.referer, name: utils.getOrigin() } } diff --git a/test/spec/modules/rtbhouseBidAdapter_spec.js b/test/spec/modules/rtbhouseBidAdapter_spec.js index b684c9a6eca..1834ab909cc 100644 --- a/test/spec/modules/rtbhouseBidAdapter_spec.js +++ b/test/spec/modules/rtbhouseBidAdapter_spec.js @@ -56,14 +56,22 @@ describe('RTBHouseAdapter', () => { 'transactionId': 'example-transaction-id', } ]; + const bidderRequest = { + 'refererInfo': { + 'numIframes': 0, + 'reachedTop': true, + 'referer': 'http://example.com', + 'stack': ['http://example.com'] + } + }; it('should build test param into the request', () => { - let builtTestRequest = spec.buildRequests(bidRequests).data; + let builtTestRequest = spec.buildRequests(bidRequests, bidderRequest).data; expect(JSON.parse(builtTestRequest).test).to.equal(1); }); it('should build valid OpenRTB banner object', () => { - const request = JSON.parse(spec.buildRequests((bidRequests)).data); + const request = JSON.parse(spec.buildRequests(bidRequests, bidderRequest).data); const imp = request.imp[0]; expect(imp.banner).to.deep.equal({ w: 300, @@ -81,7 +89,7 @@ describe('RTBHouseAdapter', () => { it('sends bid request to ENDPOINT via POST', function () { let bidRequest = Object.assign([], bidRequests); delete bidRequest[0].params.test; - const request = spec.buildRequests(bidRequest); + const request = spec.buildRequests(bidRequest, bidderRequest); expect(request.url).to.equal('https://prebid-eu.creativecdn.com/bidder/prebid/bids'); expect(request.method).to.equal('POST'); }); @@ -89,7 +97,7 @@ describe('RTBHouseAdapter', () => { it('should not populate GDPR if for non-EEA users', function () { let bidRequest = Object.assign([], bidRequests); delete bidRequest[0].params.test; - const request = spec.buildRequests(bidRequest); + const request = spec.buildRequests(bidRequest, bidderRequest); let data = JSON.parse(request.data); expect(data).to.not.have.property('regs'); expect(data).to.not.have.property('user'); @@ -98,12 +106,15 @@ describe('RTBHouseAdapter', () => { it('should populate GDPR and consent string if available for EEA users', function () { let bidRequest = Object.assign([], bidRequests); delete bidRequest[0].params.test; - const request = spec.buildRequests(bidRequest, { - gdprConsent: { - gdprApplies: true, - consentString: 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A==' - } - }); + const request = spec.buildRequests( + bidRequest, + Object.assign({}, bidderRequest, { + gdprConsent: { + gdprApplies: true, + consentString: 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A==' + } + }) + ); let data = JSON.parse(request.data); expect(data.regs.ext.gdpr).to.equal(1); expect(data.user.ext.consent).to.equal('BOJ8RZsOJ8RZsABAB8AAAAAZ-A'); @@ -112,7 +123,14 @@ describe('RTBHouseAdapter', () => { it('should populate GDPR and empty consent string if available for EEA users without consent string but with consent', function () { let bidRequest = Object.assign([], bidRequests); delete bidRequest[0].params.test; - const request = spec.buildRequests(bidRequest, {gdprConsent: {gdprApplies: true}}); + const request = spec.buildRequests( + bidRequest, + Object.assign({}, bidderRequest, { + gdprConsent: { + gdprApplies: true + } + }) + ); let data = JSON.parse(request.data); expect(data.regs.ext.gdpr).to.equal(1); expect(data.user.ext.consent).to.equal(''); @@ -120,14 +138,14 @@ describe('RTBHouseAdapter', () => { it('should include banner imp in request', () => { const bidRequest = Object.assign([], bidRequests); - const request = spec.buildRequests(bidRequest); + const request = spec.buildRequests(bidRequest, bidderRequest); const data = JSON.parse(request.data); expect(data.imp[0].banner).to.not.be.empty; }); it('should include source.tid in request', () => { const bidRequest = Object.assign([], bidRequests); - const request = spec.buildRequests(bidRequest); + const request = spec.buildRequests(bidRequest, bidderRequest); const data = JSON.parse(request.data); expect(data.source.tid).to.equal('example-transaction-id'); }); @@ -147,7 +165,8 @@ describe('RTBHouseAdapter', () => { } function buildImp(request) { - return JSON.parse(spec.buildRequests([request]).data).imp[0]; + const resultRequest = spec.buildRequests([request], bidderRequest); + return JSON.parse(resultRequest.data).imp[0]; } it('should extract native params when single mediaType', () => {