From 134ec2027db7ddf809395410a3b72ddda9203e0e Mon Sep 17 00:00:00 2001 From: Ankit Prakash Date: Wed, 2 Oct 2019 16:56:28 -0600 Subject: [PATCH 1/7] schain and digitrust --- modules/sovrnBidAdapter.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/modules/sovrnBidAdapter.js b/modules/sovrnBidAdapter.js index 8b08b3ad6be..a7084ca7b5f 100644 --- a/modules/sovrnBidAdapter.js +++ b/modules/sovrnBidAdapter.js @@ -27,7 +27,11 @@ export const spec = { const loc = utils.getTopWindowLocation(); let sovrnImps = []; let iv; + let schain; utils._each(bidReqs, function (bid) { + if(bid.schain) { + schain = schain || bid.schain; + } iv = iv || utils.getBidIdParameter('iv', bid.params); bid.sizes = ((utils.isArray(bid.sizes) && utils.isArray(bid.sizes[0])) ? bid.sizes : [bid.sizes]) bid.sizes = bid.sizes.filter(size => utils.isArray(size)) @@ -52,6 +56,14 @@ export const spec = { } }; + if(schain) { + sovrnBidReq.source = { + ext: { + schain + } + }; + } + if (bidderRequest && bidderRequest.gdprConsent) { sovrnBidReq.regs = { ext: { @@ -63,6 +75,16 @@ export const spec = { }}; } + const bidRequestDigitrust = utils.deepAccess(bidRequest, 'userId.digitrustid.data'); + if (bidRequestDigitrust && !bidRequestDigitrust.privacy.optout) { + sovrnBidReq.user = sovrnBidReq.user || {}; + sovrnBidReq.user.ext = sovrnBidReq.user.ext || {} + sovrnBidReq.user.ext.digitrust = { + id: bidRequestDigitrust.id, + keyv: bidRequestDigitrust.keyv + } + } + let url = `//ap.lijit.com/rtb/bid?` + `src=$$REPO_AND_VERSION$$`; if (iv) url += `&iv=${iv}`; From 1db50a92950eb2449ee08c6ef0c85b7d5eb49981 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 7 Oct 2019 14:09:44 -0600 Subject: [PATCH 2/7] pixel beacons --- modules/sovrnBidAdapter.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/modules/sovrnBidAdapter.js b/modules/sovrnBidAdapter.js index a7084ca7b5f..dc240bfd0ce 100644 --- a/modules/sovrnBidAdapter.js +++ b/modules/sovrnBidAdapter.js @@ -139,8 +139,8 @@ export const spec = { try { let tracks = [] if (serverResponses && serverResponses.length !== 0 && syncOptions.iframeEnabled) { - let iidArr = serverResponses.filter(rsp => rsp.body && rsp.body.ext && rsp.body.ext.iid) - .map(rsp => { return rsp.body.ext.iid }); + let iidArr = serverResponses.filter(resp => resp.body && resp.body.ext && resp.body.ext.iid) + .map(resp => resp.body.ext.iid); let consentString = ''; if (gdprConsent && gdprConsent.gdprApplies && typeof gdprConsent.consentString === 'string') { consentString = gdprConsent.consentString @@ -152,9 +152,17 @@ export const spec = { }); } } - if (errorpxls.length && syncOptions.pixelEnabled) { - tracks = tracks.concat(errorpxls) + if(syncOptions.pixelEnabled) { + if (serverResponses && serverResponses.length !== 0) { + serverResponses.filter(resp => resp.body && resp.body.ext && resp.body.ext.sync && resp.body.ext.sync.pixels) + .map(resp => resp.body.ext.sync.pixels.url) + .forEach(url => tracks.push({ type: 'image', url})) + } + if (errorpxls.length) { + tracks = tracks.concat(errorpxls) + } } + return tracks } catch (e) { if (syncOptions.pixelEnabled) { From 340303a8a64b20abf1fb99665cf1725738804d68 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 8 Oct 2019 13:28:16 -0600 Subject: [PATCH 3/7] unit tests and fixes from testing --- modules/sovrnBidAdapter.js | 65 ++++++----- test/spec/modules/sovrnBidAdapter_spec.js | 128 ++++++++++++++++++---- 2 files changed, 143 insertions(+), 50 deletions(-) diff --git a/modules/sovrnBidAdapter.js b/modules/sovrnBidAdapter.js index dc240bfd0ce..fed3958cf16 100644 --- a/modules/sovrnBidAdapter.js +++ b/modules/sovrnBidAdapter.js @@ -28,8 +28,19 @@ export const spec = { let sovrnImps = []; let iv; let schain; + let digitrust; + utils._each(bidReqs, function (bid) { - if(bid.schain) { + if (!digitrust) { + const bidRequestDigitrust = utils.deepAccess(bid, 'userId.digitrustid.data'); + if (bidRequestDigitrust && (!bidRequestDigitrust.privacy || !bidRequestDigitrust.privacy.optout)) { + digitrust = { + id: bidRequestDigitrust.id, + keyv: bidRequestDigitrust.keyv + } + } + } + if (bid.schain) { schain = schain || bid.schain; } iv = iv || utils.getBidIdParameter('iv', bid.params); @@ -56,7 +67,7 @@ export const spec = { } }; - if(schain) { + if (schain) { sovrnBidReq.source = { ext: { schain @@ -75,13 +86,12 @@ export const spec = { }}; } - const bidRequestDigitrust = utils.deepAccess(bidRequest, 'userId.digitrustid.data'); - if (bidRequestDigitrust && !bidRequestDigitrust.privacy.optout) { + if (digitrust) { sovrnBidReq.user = sovrnBidReq.user || {}; sovrnBidReq.user.ext = sovrnBidReq.user.ext || {} sovrnBidReq.user.ext.digitrust = { - id: bidRequestDigitrust.id, - keyv: bidRequestDigitrust.keyv + id: digitrust.id, + keyv: digitrust.keyv } } @@ -138,28 +148,31 @@ export const spec = { getUserSyncs: function(syncOptions, serverResponses, gdprConsent) { try { let tracks = [] - if (serverResponses && serverResponses.length !== 0 && syncOptions.iframeEnabled) { - let iidArr = serverResponses.filter(resp => resp.body && resp.body.ext && resp.body.ext.iid) - .map(resp => resp.body.ext.iid); - let consentString = ''; - if (gdprConsent && gdprConsent.gdprApplies && typeof gdprConsent.consentString === 'string') { - consentString = gdprConsent.consentString - } - if (iidArr[0]) { - tracks.push({ - type: 'iframe', - url: '//ap.lijit.com/beacon?informer=' + iidArr[0] + '&gdpr_consent=' + consentString, - }); + if (serverResponses && serverResponses.length !== 0) { + if (syncOptions.iframeEnabled) { + let iidArr = serverResponses.filter(resp => resp.body && resp.body.ext && resp.body.ext.iid) + .map(resp => resp.body.ext.iid); + let consentString = ''; + if (gdprConsent && gdprConsent.gdprApplies && typeof gdprConsent.consentString === 'string') { + consentString = gdprConsent.consentString + } + if (iidArr[0]) { + tracks.push({ + type: 'iframe', + url: '//ap.lijit.com/beacon?informer=' + iidArr[0] + '&gdpr_consent=' + consentString, + }); + } } - } - if(syncOptions.pixelEnabled) { - if (serverResponses && serverResponses.length !== 0) { + + if (syncOptions.pixelEnabled) { serverResponses.filter(resp => resp.body && resp.body.ext && resp.body.ext.sync && resp.body.ext.sync.pixels) - .map(resp => resp.body.ext.sync.pixels.url) - .forEach(url => tracks.push({ type: 'image', url})) - } - if (errorpxls.length) { - tracks = tracks.concat(errorpxls) + .flatMap(resp => resp.body.ext.sync.pixels) + .map(pixel => pixel.url) + .forEach(url => tracks.push({ type: 'image', url })) + + if (errorpxls.length) { + tracks = tracks.concat(errorpxls) + } } } diff --git a/test/spec/modules/sovrnBidAdapter_spec.js b/test/spec/modules/sovrnBidAdapter_spec.js index 7179ec00bc3..5f385008f54 100644 --- a/test/spec/modules/sovrnBidAdapter_spec.js +++ b/test/spec/modules/sovrnBidAdapter_spec.js @@ -1,7 +1,6 @@ -import { expect } from 'chai'; -import { spec, LogError } from 'modules/sovrnBidAdapter'; -import { newBidder } from 'src/adapters/bidderFactory'; -import { SSL_OP_SINGLE_ECDH_USE } from 'constants'; +import {expect} from 'chai'; +import {LogError, spec} from 'modules/sovrnBidAdapter'; +import {newBidder} from 'src/adapters/bidderFactory'; const ENDPOINT = `//ap.lijit.com/rtb/bid?src=$$REPO_AND_VERSION$$`; @@ -128,13 +127,12 @@ describe('sovrnBidAdapter', function() { }; bidderRequest.bids = bidRequests; - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); + const data = JSON.parse(spec.buildRequests(bidRequests, bidderRequest).data); - expect(payload.regs.ext.gdpr).to.exist.and.to.be.a('number'); - expect(payload.regs.ext.gdpr).to.equal(1); - expect(payload.user.ext.consent).to.exist.and.to.be.a('string'); - expect(payload.user.ext.consent).to.equal(consentString); + expect(data.regs.ext.gdpr).to.exist.and.to.be.a('number'); + expect(data.regs.ext.gdpr).to.equal(1); + expect(data.user.ext.consent).to.exist.and.to.be.a('string'); + expect(data.user.ext.consent).to.equal(consentString); }); it('converts tagid to string', function () { @@ -156,7 +154,68 @@ describe('sovrnBidAdapter', function() { const request = spec.buildRequests(ivBidRequests); expect(request.data).to.contain('"tagid":"403370"') - }) + }); + + it('should add schain if present', () => { + const schainRequests = [{ + 'bidder': 'sovrn', + 'params': { + 'tagid': 403370 + }, + 'adUnitCode': 'adunit-code', + 'sizes': [ + [300, 250], + [300, 600] + ], + 'bidId': '30b31c1838de1e', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475', + 'schain': { + 'ver': '1.0', + 'complete': 1, + 'nodes': [ + { + 'asi': 'directseller.com', + 'sid': '00001', + 'rid': 'BidRequest1', + 'hp': 1 + } + ] + } + }].concat(bidRequests); + const data = JSON.parse(spec.buildRequests(schainRequests).data); + + expect(data.source.ext.schain.nodes.length).to.equal(1) + }); + + it('should add digitrust data if present', () => { + const digitrustRequests = [{ + 'bidder': 'sovrn', + 'params': { + 'tagid': 403370 + }, + 'adUnitCode': 'adunit-code', + 'sizes': [ + [300, 250], + [300, 600] + ], + 'bidId': '30b31c1838de1e', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475', + 'userId': { + 'digitrustid': { + 'data': { + 'id': 'digitrust-id-123', + 'keyv': 4 + } + } + } + }].concat(bidRequests); + const data = JSON.parse(spec.buildRequests(digitrustRequests).data); + + expect(data.user.ext.digitrust.id).to.equal('digitrust-id-123'); + expect(data.user.ext.digitrust.keyv).to.equal(4); + }); }); describe('interpretResponse', function () { @@ -254,8 +313,8 @@ describe('sovrnBidAdapter', function() { }); describe('getUserSyncs ', () => { - let syncOptions = {iframeEnabled: true, pixelEnabled: true}; - let iframeDisabledSyncOptions = {iframeEnabled: false, pixelEnabled: true}; + let syncOptions = { iframeEnabled: true, pixelEnabled: false }; + let iframeDisabledSyncOptions = { iframeEnabled: false, pixelEnabled: false }; let serverResponse = [ { 'body': { @@ -287,33 +346,54 @@ describe('sovrnBidAdapter', function() { } ], 'ext': { - 'iid': 13487408 + 'iid': 13487408, + sync: { + pixels: [ + { + url: 'http://idprovider1.com' + }, + { + url: 'http://idprovider2.com' + } + ] + } } }, 'headers': {} } ]; + it('should return if iid present on server response & iframe syncs enabled', () => { - let expectedReturnStatement = [ + const expectedReturnStatement = [ { 'type': 'iframe', 'url': '//ap.lijit.com/beacon?informer=13487408&gdpr_consent=', } - ] - let returnStatement = spec.getUserSyncs(syncOptions, serverResponse); + ]; + const returnStatement = spec.getUserSyncs(syncOptions, serverResponse); expect(returnStatement[0]).to.deep.equal(expectedReturnStatement[0]); - }) + }); it('should not return if iid missing on server response', () => { - let returnStatement = spec.getUserSyncs(syncOptions, []) + const returnStatement = spec.getUserSyncs(syncOptions, []); expect(returnStatement).to.be.empty; - }) + }); it('should not return if iframe syncs disabled', () => { - let returnStatement = spec.getUserSyncs(iframeDisabledSyncOptions, serverResponse) - expect(returnStatement).to.be.empty - }) - }) + const returnStatement = spec.getUserSyncs(iframeDisabledSyncOptions, serverResponse); + expect(returnStatement).to.be.empty; + }); + + it('should include pixel syncs', () => { + let pixelEnabledOptions = { iframeEnabled: false, pixelEnabled: true }; + const returnStatement = spec.getUserSyncs(pixelEnabledOptions, serverResponse); + console.log(returnStatement) + expect(returnStatement.length).to.equal(2); + expect(returnStatement).to.deep.include.members([{ type: 'image', url: 'http://idprovider1.com' }, + { type: 'image', url: 'http://idprovider2.com' }]); + }); + }); + describe('LogError', () => { it('should build and append an error object', () => { const thrown = { From 2de4d6b15f4d107af693cfec72af6825fcca328a Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 16 Oct 2019 14:17:00 -0600 Subject: [PATCH 4/7] Prebid 3.0 updates --- modules/sovrnBidAdapter.js | 73 +++------- test/spec/modules/sovrnBidAdapter_spec.js | 162 ++++++++++------------ 2 files changed, 95 insertions(+), 140 deletions(-) diff --git a/modules/sovrnBidAdapter.js b/modules/sovrnBidAdapter.js index fed3958cf16..b953f3bc19f 100644 --- a/modules/sovrnBidAdapter.js +++ b/modules/sovrnBidAdapter.js @@ -1,8 +1,6 @@ import * as utils from '../src/utils' import { registerBidder } from '../src/adapters/bidderFactory' import { BANNER } from '../src/mediaTypes' -const errorUrl = 'https://pcb.aws.lijit.com/c' -let errorpxls = [] export const spec = { code: 'sovrn', @@ -24,7 +22,6 @@ export const spec = { */ buildRequests: function(bidReqs, bidderRequest) { try { - const loc = utils.getTopWindowLocation(); let sovrnImps = []; let iv; let schain; @@ -44,9 +41,11 @@ export const spec = { schain = schain || bid.schain; } iv = iv || utils.getBidIdParameter('iv', bid.params); - bid.sizes = ((utils.isArray(bid.sizes) && utils.isArray(bid.sizes[0])) ? bid.sizes : [bid.sizes]) - bid.sizes = bid.sizes.filter(size => utils.isArray(size)) - const processedSizes = bid.sizes.map(size => ({w: parseInt(size[0], 10), h: parseInt(size[1], 10)})) + + let bidSizes = (bid.mediaTypes && bid.mediaTypes.banner && bid.mediaTypes.banner.sizes) || bid.sizes; + bidSizes = ((utils.isArray(bidSizes) && utils.isArray(bidSizes[0])) ? bidSizes : [bidSizes]) + bidSizes = bidSizes.filter(size => utils.isArray(size)) + const processedSizes = bidSizes.map(size => ({w: parseInt(size[0], 10), h: parseInt(size[1], 10)})) sovrnImps.push({ id: bid.bidId, banner: { @@ -58,12 +57,19 @@ export const spec = { bidfloor: utils.getBidIdParameter('bidfloor', bid.params) }); }); + + const page = bidderRequest.refererInfo.referer + // clever trick to get the domain + const el = document.createElement('a'); + el.href = page; + const domain = el.hostname; + const sovrnBidReq = { id: utils.getUniqueIdentifierStr(), imp: sovrnImps, site: { - domain: loc.host, - page: loc.host + loc.pathname + loc.search + loc.hash + page, + domain } }; @@ -95,7 +101,7 @@ export const spec = { } } - let url = `//ap.lijit.com/rtb/bid?` + + let url = `https://ap.lijit.com/rtb/bid?` + `src=$$REPO_AND_VERSION$$`; if (iv) url += `&iv=${iv}`; @@ -106,7 +112,8 @@ export const spec = { options: {contentType: 'text/plain'} } } catch (e) { - new LogError(e, {bidReqs, bidderRequest}).append() + console.log('error in build:') + console.log(e) } }, @@ -141,7 +148,8 @@ export const spec = { } return sovrnBidResponses } catch (e) { - new LogError(e, {id, seatbid}).append() + console.log('error in interpret:') + console.log(e) } }, @@ -169,57 +177,14 @@ export const spec = { .flatMap(resp => resp.body.ext.sync.pixels) .map(pixel => pixel.url) .forEach(url => tracks.push({ type: 'image', url })) - - if (errorpxls.length) { - tracks = tracks.concat(errorpxls) - } } } return tracks } catch (e) { - if (syncOptions.pixelEnabled) { - return errorpxls - } return [] } }, } -export class LogError { - constructor(e, data) { - utils.logError(e) - this.error = {} - this.error.t = utils.timestamp() - this.error.m = e.message - this.error.s = e.stack - this.error.d = data - this.error.v = $$REPO_AND_VERSION$$ - this.error.u = utils.getTopWindowLocation().href - this.error.ua = navigator.userAgent - } - buildErrorString(obj) { - return errorUrl + '?b=' + btoa(JSON.stringify(obj)) - } - append() { - let errstr = this.buildErrorString(this.error) - if (errstr.length > 2083) { - delete this.error.d - errstr = this.buildErrorString(this.error) - if (errstr.length > 2083) { - delete this.error.s - errstr = this.buildErrorString(this.error) - if (errstr.length > 2083) { - errstr = this.buildErrorString({m: 'unknown error message', t: this.error.t, u: this.error.u}) - } - } - } - let obj = {type: 'image', url: errstr} - errorpxls.push(obj) - } - static getErrPxls() { - return errorpxls - } -} - registerBidder(spec); diff --git a/test/spec/modules/sovrnBidAdapter_spec.js b/test/spec/modules/sovrnBidAdapter_spec.js index 5f385008f54..af27e6e74a6 100644 --- a/test/spec/modules/sovrnBidAdapter_spec.js +++ b/test/spec/modules/sovrnBidAdapter_spec.js @@ -2,7 +2,7 @@ import {expect} from 'chai'; import {LogError, spec} from 'modules/sovrnBidAdapter'; import {newBidder} from 'src/adapters/bidderFactory'; -const ENDPOINT = `//ap.lijit.com/rtb/bid?src=$$REPO_AND_VERSION$$`; +const ENDPOINT = `https://ap.lijit.com/rtb/bid?src=$$REPO_AND_VERSION$$`; describe('sovrnBidAdapter', function() { const adapter = newBidder(spec); @@ -54,8 +54,12 @@ describe('sovrnBidAdapter', function() { 'bidderRequestId': '22edbae2733bf6', 'auctionId': '1d1a030790a475' }]; - - const request = spec.buildRequests(bidRequests); + const bidderRequest = { + refererInfo: { + referer: 'http://example.com/page.html', + } + }; + const request = spec.buildRequests(bidRequests, bidderRequest); it('sends bid request to our endpoint via POST', function () { expect(request.method).to.equal('POST'); @@ -72,7 +76,7 @@ describe('sovrnBidAdapter', function() { expect(payload.imp[0].banner.h).to.equal(1) }) - it('accepts a single array as a size', function() { + it('accepts a single array as a size', () => { const singleSize = [{ 'bidder': 'sovrn', 'params': { @@ -84,8 +88,13 @@ describe('sovrnBidAdapter', function() { 'bidId': '30b31c1838de1e', 'bidderRequestId': '22edbae2733bf6', 'auctionId': '1d1a030790a475' - }]; - const request = spec.buildRequests(singleSize) + }] + const bidderRequest = { + refererInfo: { + referer: 'http://example.com/page.html', + } + } + const request = spec.buildRequests(singleSize, bidderRequest) const payload = JSON.parse(request.data) expect(payload.imp[0].banner.format).to.deep.equal([{w: 300, h: 250}]) expect(payload.imp[0].banner.w).to.equal(1) @@ -108,7 +117,12 @@ describe('sovrnBidAdapter', function() { 'bidderRequestId': '22edbae2733bf6', 'auctionId': '1d1a030790a475' }]; - const request = spec.buildRequests(ivBidRequests); + const bidderRequest = { + refererInfo: { + referer: 'http://example.com/page.html', + } + }; + const request = spec.buildRequests(ivBidRequests, bidderRequest); expect(request.url).to.contain('iv=vet') }); @@ -120,9 +134,12 @@ describe('sovrnBidAdapter', function() { 'auctionId': '1d1a030790a475', 'bidderRequestId': '22edbae2733bf6', 'timeout': 3000, - 'gdprConsent': { + gdprConsent: { consentString: consentString, gdprApplies: true + }, + refererInfo: { + referer: 'http://example.com/page.html', } }; bidderRequest.bids = bidRequests; @@ -151,7 +168,12 @@ describe('sovrnBidAdapter', function() { 'bidderRequestId': '22edbae2733bf6', 'auctionId': '1d1a030790a475' }]; - const request = spec.buildRequests(ivBidRequests); + const bidderRequest = { + refererInfo: { + referer: 'http://example.com/page.html', + } + }; + const request = spec.buildRequests(ivBidRequests, bidderRequest); expect(request.data).to.contain('"tagid":"403370"') }); @@ -183,7 +205,12 @@ describe('sovrnBidAdapter', function() { ] } }].concat(bidRequests); - const data = JSON.parse(spec.buildRequests(schainRequests).data); + const bidderRequest = { + refererInfo: { + referer: 'http://example.com/page.html', + } + }; + const data = JSON.parse(spec.buildRequests(schainRequests, bidderRequest).data); expect(data.source.ext.schain.nodes.length).to.equal(1) }); @@ -211,7 +238,12 @@ describe('sovrnBidAdapter', function() { } } }].concat(bidRequests); - const data = JSON.parse(spec.buildRequests(digitrustRequests).data); + const bidderRequest = { + refererInfo: { + referer: 'http://example.com/page.html', + } + }; + const data = JSON.parse(spec.buildRequests(digitrustRequests, bidderRequest).data); expect(data.user.ext.digitrust.id).to.equal('digitrust-id-123'); expect(data.user.ext.digitrust.keyv).to.equal(4); @@ -394,84 +426,42 @@ describe('sovrnBidAdapter', function() { }); }); - describe('LogError', () => { - it('should build and append an error object', () => { - const thrown = { - message: 'message', - stack: 'stack' - } - const data = {name: 'Oscar Hathenswiotch'} - const err = new LogError(thrown, data) - err.append() - const errList = LogError.getErrPxls() - expect(errList.length).to.equal(1) - const errdata = JSON.parse(atob(errList[0].url.split('=')[1])) - expect(errdata.d.name).to.equal('Oscar Hathenswiotch') - }) - it('should drop data when there is too much', () => { - const thrown = { - message: 'message', - stack: 'stack' - } - const tooLong = () => { - let str = '' - for (let i = 0; i < 10000; i++) { - str = str + String.fromCharCode(i % 100) - } - return str - } - const data = {name: 'Oscar Hathenswiotch', tooLong: tooLong()} - const err = new LogError(thrown, data) - err.append() - const errList = LogError.getErrPxls() - expect(errList.length).to.equal(2) - const errdata = JSON.parse(atob(errList[1].url.split('=')[1])) - expect(errdata.d).to.be.an('undefined') - }) - it('should drop data and stack when there is too much', () => { - const thrown = { - message: 'message', - stack: 'stack' - } - const tooLong = () => { - let str = '' - for (let i = 0; i < 10000; i++) { - str = str + String.fromCharCode(i % 100) + describe('prebid 3 upgrade', () => { + const bidRequests = [{ + 'bidder': 'sovrn', + 'params': { + 'tagid': '403370' + }, + 'adUnitCode': 'adunit-code', + mediaTypes: { + banner: { + sizes: [ + [300, 250], + [300, 600] + ] } - return str + }, + 'bidId': '30b31c1838de1e', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475' + }]; + const bidderRequest = { + refererInfo: { + referer: 'http://example.com/page.html', } - const data = {name: 'Oscar Hathenswiotch'} - thrown.stack = tooLong() - const err = new LogError(thrown, data) - err.append() - const errList = LogError.getErrPxls() - expect(errList.length).to.equal(3) - const errdata = JSON.parse(atob(errList[2].url.split('=')[1])) - expect(errdata.d).to.be.an('undefined') - expect(errdata.s).to.be.an('undefined') + }; + const request = spec.buildRequests(bidRequests, bidderRequest); + const payload = JSON.parse(request.data); + + it('gets sizes from mediaTypes.banner', () => { + expect(payload.imp[0].banner.format).to.deep.equal([{w: 300, h: 250}, {w: 300, h: 600}]) + expect(payload.imp[0].banner.w).to.equal(1) + expect(payload.imp[0].banner.h).to.equal(1) }) - it('should drop send a reduced message when other reduction methods fail', () => { - const thrown = { - message: 'message', - stack: 'stack' - } - const tooLong = () => { - let str = '' - for (let i = 0; i < 10000; i++) { - str = str + String.fromCharCode(i % 100) - } - return str - } - const data = {name: 'Oscar Hathenswiotch'} - thrown.message = tooLong() - const err = new LogError(thrown, data) - err.append() - const errList = LogError.getErrPxls() - expect(errList.length).to.equal(4) - const errdata = JSON.parse(atob(errList[3].url.split('=')[1])) - expect(errdata.d).to.be.an('undefined') - expect(errdata.s).to.be.an('undefined') - expect(errdata.m).to.equal('unknown error message') + + it('gets correct site info', () => { + expect(payload.site.page).to.equal('http://example.com/page.html'); + expect(payload.site.domain).to.equal('example.com'); }) }) }) From af083d148073d7c812cc4b3675a49c02d106a56f Mon Sep 17 00:00:00 2001 From: Ankit Prakash Date: Wed, 23 Oct 2019 12:00:46 -0600 Subject: [PATCH 5/7] review fix --- modules/sovrnBidAdapter.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/modules/sovrnBidAdapter.js b/modules/sovrnBidAdapter.js index b953f3bc19f..935bbad79a7 100644 --- a/modules/sovrnBidAdapter.js +++ b/modules/sovrnBidAdapter.js @@ -93,12 +93,10 @@ export const spec = { } if (digitrust) { - sovrnBidReq.user = sovrnBidReq.user || {}; - sovrnBidReq.user.ext = sovrnBidReq.user.ext || {} - sovrnBidReq.user.ext.digitrust = { + utils.deepSetValue(sovrnBidReq, 'user.ext.digitrust', { id: digitrust.id, keyv: digitrust.keyv - } + }) } let url = `https://ap.lijit.com/rtb/bid?` + @@ -158,7 +156,7 @@ export const spec = { let tracks = [] if (serverResponses && serverResponses.length !== 0) { if (syncOptions.iframeEnabled) { - let iidArr = serverResponses.filter(resp => resp.body && resp.body.ext && resp.body.ext.iid) + let iidArr = serverResponses.filter(resp => utils.deepAccess(resp, 'body.ext.iid')) .map(resp => resp.body.ext.iid); let consentString = ''; if (gdprConsent && gdprConsent.gdprApplies && typeof gdprConsent.consentString === 'string') { @@ -173,7 +171,7 @@ export const spec = { } if (syncOptions.pixelEnabled) { - serverResponses.filter(resp => resp.body && resp.body.ext && resp.body.ext.sync && resp.body.ext.sync.pixels) + serverResponses.filter(resp => utils.deepAccess(resp, 'body.ext.sync.pixels')) .flatMap(resp => resp.body.ext.sync.pixels) .map(pixel => pixel.url) .forEach(url => tracks.push({ type: 'image', url })) From f13eb86b0ff9c44423cd7dbeeba2602c691b27e5 Mon Sep 17 00:00:00 2001 From: Ankit Prakash Date: Mon, 28 Oct 2019 10:37:11 -0600 Subject: [PATCH 6/7] use backwards compatible flatMap impl --- modules/sovrnBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/sovrnBidAdapter.js b/modules/sovrnBidAdapter.js index 935bbad79a7..af12322271b 100644 --- a/modules/sovrnBidAdapter.js +++ b/modules/sovrnBidAdapter.js @@ -172,7 +172,7 @@ export const spec = { if (syncOptions.pixelEnabled) { serverResponses.filter(resp => utils.deepAccess(resp, 'body.ext.sync.pixels')) - .flatMap(resp => resp.body.ext.sync.pixels) + .reduce((acc, resp) => acc.concat(resp.body.ext.sync.pixels), []) .map(pixel => pixel.url) .forEach(url => tracks.push({ type: 'image', url })) } From 997caf008c433e501251ffebe7fbba06cca6719a Mon Sep 17 00:00:00 2001 From: Ankit Prakash Date: Mon, 28 Oct 2019 10:55:29 -0600 Subject: [PATCH 7/7] update pixel tests --- test/spec/modules/sovrnBidAdapter_spec.js | 60 ++++++++++++++++++++--- 1 file changed, 54 insertions(+), 6 deletions(-) diff --git a/test/spec/modules/sovrnBidAdapter_spec.js b/test/spec/modules/sovrnBidAdapter_spec.js index af27e6e74a6..4020d117bb7 100644 --- a/test/spec/modules/sovrnBidAdapter_spec.js +++ b/test/spec/modules/sovrnBidAdapter_spec.js @@ -416,13 +416,61 @@ describe('sovrnBidAdapter', function() { expect(returnStatement).to.be.empty; }); - it('should include pixel syncs', () => { + it.only('should include pixel syncs', () => { let pixelEnabledOptions = { iframeEnabled: false, pixelEnabled: true }; - const returnStatement = spec.getUserSyncs(pixelEnabledOptions, serverResponse); - console.log(returnStatement) - expect(returnStatement.length).to.equal(2); - expect(returnStatement).to.deep.include.members([{ type: 'image', url: 'http://idprovider1.com' }, - { type: 'image', url: 'http://idprovider2.com' }]); + const resp2 = { + 'body': { + 'id': '546956d68c757f-2', + 'seatbid': [ + { + 'bid': [ + { + 'id': 'a_448326_16c2ada014224bee815a90d2248322f5-2', + 'impid': '2a3826aae345f4', + 'price': 1.0099999904632568, + 'nurl': 'http://localhost/rtb/impression?bannerid=220958&campaignid=3890&rtb_tid=15588614-75d2-40ab-b27e-13d2127b3c2e&rpid=1295&seatid=seat1&zoneid=448326&cb=26900712&tid=a_448326_16c2ada014224bee815a90d2248322f5', + 'adm': 'yo a creative', + 'crid': 'cridprebidrtb', + 'w': 160, + 'h': 600 + }, + { + 'id': 'a_430392_beac4c1515da4576acf6cb9c5340b40c-2', + 'impid': '3cf96fd26ed4c5', + 'price': 1.0099999904632568, + 'nurl': 'http://localhost/rtb/impression?bannerid=220957&campaignid=3890&rtb_tid=5bc0e68b-3492-448d-a6f9-26fa3fd0b646&rpid=1295&seatid=seat1&zoneid=430392&cb=62735099&tid=a_430392_beac4c1515da4576acf6cb9c5340b40c', + 'adm': 'yo a creative', + 'crid': 'cridprebidrtb', + 'w': 300, + 'h': 250 + }, + ] + } + ], + 'ext': { + 'iid': 13487408, + sync: { + pixels: [ + { + url: 'http://idprovider3.com' + }, + { + url: 'http://idprovider4.com' + } + ] + } + } + }, + 'headers': {} + } + const returnStatement = spec.getUserSyncs(pixelEnabledOptions, [...serverResponse, resp2]); + expect(returnStatement.length).to.equal(4); + expect(returnStatement).to.deep.include.members([ + { type: 'image', url: 'http://idprovider1.com' }, + { type: 'image', url: 'http://idprovider2.com' }, + { type: 'image', url: 'http://idprovider3.com' }, + { type: 'image', url: 'http://idprovider4.com' } + ]); }); });