From f80878a970b89afd61f7b044c8608ce7d481a192 Mon Sep 17 00:00:00 2001 From: Mikhalovich Date: Tue, 14 Sep 2021 14:17:37 +0300 Subject: [PATCH 1/7] EX-2588 Refactor tests for sovrn bid adapter --- test/spec/modules/sovrnBidAdapter_spec.js | 555 ++++++++++------------ 1 file changed, 241 insertions(+), 314 deletions(-) diff --git a/test/spec/modules/sovrnBidAdapter_spec.js b/test/spec/modules/sovrnBidAdapter_spec.js index 729c48c28f4..ac8cc9fbadc 100644 --- a/test/spec/modules/sovrnBidAdapter_spec.js +++ b/test/spec/modules/sovrnBidAdapter_spec.js @@ -5,7 +5,7 @@ import * as utils from 'src/utils.js' const ENDPOINT = `https://ap.lijit.com/rtb/bid?src=$$REPO_AND_VERSION$$`; -const adUnitBidRequest = { +const baseBidRequest = { 'bidder': 'sovrn', 'params': { 'tagid': 403370 @@ -19,7 +19,7 @@ const adUnitBidRequest = { 'bidderRequestId': '22edbae2733bf6', 'auctionId': '1d1a030790a475', } -const bidderRequest = { +const baseBidderRequest = { refererInfo: { referer: 'http://example.com/page.html', } @@ -28,28 +28,35 @@ const bidderRequest = { describe('sovrnBidAdapter', function() { describe('isBidRequestValid', function () { it('should return true when required params found', function () { - expect(spec.isBidRequestValid(adUnitBidRequest)).to.equal(true); + expect(spec.isBidRequestValid(baseBidRequest)).to.equal(true); }); it('should return false when tagid not passed correctly', function () { - const bid = {...adUnitBidRequest} - const params = adUnitBidRequest.params - bid.params = {...params} - bid.params.tagid = 'ABCD' - expect(spec.isBidRequestValid(bid)).to.equal(false) + const bidRequest = { + ...baseBidRequest, + 'params': { + ...baseBidRequest.params, + 'tagid': 'ABCD' + }, + }; + + expect(spec.isBidRequestValid(bidRequest)).to.equal(false); }); it('should return false when require params are not passed', function () { - const bid = {...adUnitBidRequest} - bid.params = {}; - expect(spec.isBidRequestValid(bid)).to.equal(false); + const bidRequest = { + ...baseBidRequest, + 'params': {} + } + + expect(spec.isBidRequestValid(bidRequest)).to.equal(false); }); }); describe('buildRequests', function () { describe('basic bid parameters', function() { - const bidRequests = [adUnitBidRequest]; - const request = spec.buildRequests(bidRequests, bidderRequest); + const request = spec.buildRequests([baseBidRequest], baseBidderRequest); + const payload = JSON.parse(request.data); it('sends bid request to our endpoint via POST', function () { expect(request.method).to.equal('POST'); @@ -60,15 +67,21 @@ describe('sovrnBidAdapter', function() { }); it('sets the proper banner object', function() { - const payload = JSON.parse(request.data) - 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) + const impression = payload.imp[0] + + expect(impression.banner.format).to.deep.equal([{w: 300, h: 250}, {w: 300, h: 600}]) + expect(impression.banner.w).to.equal(1) + expect(impression.banner.h).to.equal(1) }) - it('includes the ad unit code int the request', function() { - const payload = JSON.parse(request.data); - expect(payload.imp[0].adunitcode).to.equal('adunit-code') + it('gets correct site info', function() { + expect(payload.site.page).to.equal('http://example.com/page.html'); + expect(payload.site.domain).to.equal('example.com'); + }); + + it('includes the ad unit code in the request', function() { + const impression = payload.imp[0] + expect(impression.adunitcode).to.equal('adunit-code') }) it('converts tagid to string', function () { @@ -77,109 +90,76 @@ describe('sovrnBidAdapter', function() { }) it('accepts a single array as a size', function() { - const singleSize = [{ - 'bidder': 'sovrn', + const singleSizeBidRequest = { + ...baseBidRequest, 'params': { - 'tagid': '403370', 'iv': 'vet' }, - 'adUnitCode': 'adunit-code', - 'sizes': [300, 250], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475' - }] - const request = spec.buildRequests(singleSize, bidderRequest) + 'sizes': [300, 250] + } + const request = spec.buildRequests([singleSizeBidRequest], baseBidderRequest) + 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) - expect(payload.imp[0].banner.h).to.equal(1) + const impression = payload.imp[0] + + expect(impression.banner.format).to.deep.equal([{w: 300, h: 250}]) + expect(impression.banner.w).to.equal(1) + expect(impression.banner.h).to.equal(1) }) it('sends \'iv\' as query param if present', function () { - const ivBidRequests = [{ - 'bidder': 'sovrn', - 'params': { - 'tagid': '403370', - 'iv': 'vet' - }, - 'adUnitCode': 'adunit-code', - 'sizes': [ - [300, 250], - [300, 600] - ], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475' - }]; - const bidderRequest = { - refererInfo: { - referer: 'http://example.com/page.html', + const ivBidRequest = { + ...baseBidRequest, + params: { + iv: 'vet' } - }; - const request = spec.buildRequests(ivBidRequests, bidderRequest); + } + const request = spec.buildRequests([ivBidRequest], baseBidderRequest) expect(request.url).to.contain('iv=vet') }); it('sends gdpr info if exists', function () { - let consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; const bidderRequest = { + ...baseBidderRequest, 'bidderCode': 'sovrn', 'auctionId': '1d1a030790a475', 'bidderRequestId': '22edbae2733bf6', 'timeout': 3000, - gdprConsent: { - consentString: consentString, - gdprApplies: true + 'gdprConsent': { + 'consentString': 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A==', + 'gdprApplies': true }, - refererInfo: { - referer: 'http://example.com/page.html', - } + 'bids': [baseBidRequest] }; - bidderRequest.bids = [adUnitBidRequest]; - const data = JSON.parse(spec.buildRequests([adUnitBidRequest], bidderRequest).data); + const { regs, user } = JSON.parse(spec.buildRequests([baseBidRequest], bidderRequest).data) - 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); - }); + expect(regs.ext.gdpr).to.exist.and.to.be.a('number') + expect(regs.ext.gdpr).to.equal(1) + expect(user.ext.consent).to.exist.and.to.be.a('string') + expect(user.ext.consent).to.equal(bidderRequest.gdprConsent.consentString) + }) it('should send us_privacy if bidderRequest has a value for uspConsent', function () { - const uspString = '1NYN'; const bidderRequest = { + ...baseBidderRequest, 'bidderCode': 'sovrn', 'auctionId': '1d1a030790a475', 'bidderRequestId': '22edbae2733bf6', 'timeout': 3000, - uspConsent: uspString, - refererInfo: { - referer: 'http://example.com/page.html', - } - }; - bidderRequest.bids = [adUnitBidRequest]; + 'uspConsent': '1NYN', + 'bids': [baseBidRequest] + } - const data = JSON.parse(spec.buildRequests([adUnitBidRequest], bidderRequest).data); + const data = JSON.parse(spec.buildRequests([baseBidRequest], bidderRequest).data) - expect(data.regs.ext['us_privacy']).to.equal(uspString); - }); + expect(data.regs.ext['us_privacy']).to.equal(bidderRequest.uspConsent) + }) it('should add schain if present', function() { - const schainRequests = [{ - 'bidder': 'sovrn', - 'params': { - 'tagid': 403370 - }, - 'adUnitCode': 'adunit-code', - 'sizes': [ - [300, 250], - [300, 600] - ], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', + const schainRequest = { + ...baseBidRequest, 'schain': { 'ver': '1.0', 'complete': 1, @@ -192,100 +172,89 @@ describe('sovrnBidAdapter', function() { } ] } - }].concat(adUnitBidRequest); - const bidderRequest = { - refererInfo: { - referer: 'http://example.com/page.html', - } - }; - const data = JSON.parse(spec.buildRequests(schainRequests, bidderRequest).data); + } + const schainRequests = [schainRequest, baseBidRequest] + + const data = JSON.parse(spec.buildRequests(schainRequests, baseBidderRequest).data) expect(data.source.ext.schain.nodes.length).to.equal(1) - }); + }) - it('should add ids to the bid request', function() { - const criteoIdRequest = [{ - 'bidder': 'sovrn', - 'params': { - 'tagid': 403370 - }, - 'adUnitCode': 'adunit-code', - 'sizes': [ - [300, 250], - [300, 600] - ], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - 'userId': { - 'criteoId': 'A_CRITEO_ID', - 'tdid': 'SOMESORTOFID', + it('should add eds to the bid request', function() { + const criteoIdRequest = { + ...baseBidRequest, + userId: { + criteoId: 'A_CRITEO_ID', + tdid: 'SOMESORTOFID', } - }].concat(adUnitBidRequest); - const bidderRequest = { - refererInfo: { - referer: 'http://example.com/page.html', - } - }; - - const data = JSON.parse(spec.buildRequests(criteoIdRequest, bidderRequest).data); - expect(data.user.ext.eids[0].source).to.equal('criteo.com') - expect(data.user.ext.eids[0].uids[0].id).to.equal('A_CRITEO_ID') - expect(data.user.ext.eids[0].uids[0].atype).to.equal(1) - expect(data.user.ext.eids[1].source).to.equal('adserver.org') - expect(data.user.ext.eids[1].uids[0].id).to.equal('SOMESORTOFID') - expect(data.user.ext.eids[1].uids[0].ext.rtiPartner).to.equal('TDID') - expect(data.user.ext.eids[1].uids[0].atype).to.equal(1) - expect(data.user.ext.tpid[0].source).to.equal('criteo.com') - expect(data.user.ext.tpid[0].uid).to.equal('A_CRITEO_ID') - expect(data.user.ext.prebid_criteoid).to.equal('A_CRITEO_ID') - }); + } + const criteoIdRequests = [criteoIdRequest, baseBidRequest] + + const ext = JSON.parse(spec.buildRequests(criteoIdRequests, baseBidderRequest).data).user.ext + const firstEID = ext.eids[0] + const secondEID = ext.eids[1] + + expect(firstEID.source).to.equal('criteo.com') + expect(firstEID.uids[0].id).to.equal('A_CRITEO_ID') + expect(firstEID.uids[0].atype).to.equal(1) + expect(secondEID.source).to.equal('adserver.org') + expect(secondEID.uids[0].id).to.equal('SOMESORTOFID') + expect(secondEID.uids[0].ext.rtiPartner).to.equal('TDID') + expect(secondEID.uids[0].atype).to.equal(1) + expect(ext.tpid[0].source).to.equal('criteo.com') + expect(ext.tpid[0].uid).to.equal('A_CRITEO_ID') + expect(ext.prebid_criteoid).to.equal('A_CRITEO_ID') + }) it('should ignore empty segments', function() { - const request = spec.buildRequests([adUnitBidRequest], bidderRequest) + const request = spec.buildRequests([baseBidRequest], baseBidderRequest) const payload = JSON.parse(request.data) + expect(payload.imp[0].ext).to.be.undefined }) it('should pass the segments param value as trimmed deal ids array', function() { - const segmentsRequests = [{ - 'bidder': 'sovrn', - 'params': { - 'segments': ' test1,test2 ' - }, - 'adUnitCode': 'adunit-code', - 'sizes': [ - [300, 250], - [300, 600] - ], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475' - }] - const request = spec.buildRequests(segmentsRequests, bidderRequest) - const payload = JSON.parse(request.data) - expect(payload.imp[0].ext.deals[0]).to.equal('test1') - expect(payload.imp[0].ext.deals[1]).to.equal('test2') + const segmentsRequest = { + ...baseBidRequest, + params: { + segments: ' test1,test2 ' + } + } + const request = spec.buildRequests([segmentsRequest], baseBidderRequest) + const deals = JSON.parse(request.data).imp[0].ext.deals + + expect(deals[0]).to.equal('test1') + expect(deals[1]).to.equal('test2') }) it('should use the floor provided from the floor module if present', function() { - const floorBid = {...adUnitBidRequest, getFloor: () => ({currency: 'USD', floor: 1.10})} - floorBid.params = { - tagid: 1234, - bidfloor: 2.00 + const floorBid = { + ...baseBidRequest, + getFloor: () => ({currency: 'USD', floor: 1.10}), + params: { + tagid: 1234, + bidfloor: 2.00 + } } - const request = spec.buildRequests([floorBid], bidderRequest) + + const request = spec.buildRequests([floorBid], baseBidderRequest) const payload = JSON.parse(request.data) + expect(payload.imp[0].bidfloor).to.equal(1.10) }) it('should use the floor from the param if there is no floor from the floor module', function() { - const floorBid = {...adUnitBidRequest, getFloor: () => ({})} + const floorBid = { + ...baseBidRequest, + getFloor: () => ({}) + } floorBid.params = { tagid: 1234, bidfloor: 2.00 } - const request = spec.buildRequests([floorBid], bidderRequest) - const payload = JSON.parse(request.data) - expect(payload.imp[0].bidfloor).to.equal(2.00) + + const request = spec.buildRequests([floorBid], baseBidderRequest) + const impression = JSON.parse(request.data).imp[0] + + expect(impression.bidfloor).to.equal(2.00) }) describe('First Party Data', function () { let sandbox @@ -307,48 +276,59 @@ describe('sovrnBidAdapter', function() { data: 'some user data' } } - }; - return utils.deepAccess(cfg, key); - }); - const request = spec.buildRequests([adUnitBidRequest], bidderRequest) - const payload = JSON.parse(request.data) - expect(payload.user.data).to.equal('some user data') - expect(payload.site.keywords).to.equal('test keyword') - expect(payload.site.page).to.equal('http://example.com/page.html') - expect(payload.site.domain).to.equal('example.com') + } + return utils.deepAccess(cfg, key) + }) + + const request = spec.buildRequests([baseBidRequest], baseBidderRequest) + const { user, site } = JSON.parse(request.data) + + expect(user.data).to.equal('some user data') + expect(site.keywords).to.equal('test keyword') + expect(site.page).to.equal('http://example.com/page.html') + expect(site.domain).to.equal('example.com') }) it('should append impression first party data', function () { - const fpdBid = {...adUnitBidRequest} - fpdBid.ortb2Imp = { - ext: { - data: { - pbadslot: 'homepage-top-rect', - adUnitSpecificAttribute: '123' + const fpdBidRequest = { + ...baseBidRequest, + ortb2Imp: { + ext: { + data: { + pbadslot: 'homepage-top-rect', + adUnitSpecificAttribute: '123' + } } } } - const request = spec.buildRequests([fpdBid], bidderRequest) + + const request = spec.buildRequests([fpdBidRequest], baseBidderRequest) const payload = JSON.parse(request.data) + expect(payload.imp[0].ext.data.pbadslot).to.equal('homepage-top-rect') expect(payload.imp[0].ext.data.adUnitSpecificAttribute).to.equal('123') }) it('should not overwrite deals when impression fpd is present', function() { - const fpdBid = {...adUnitBidRequest} - fpdBid.params = {...adUnitBidRequest.params} - fpdBid.params.segments = 'seg1, seg2' - fpdBid.ortb2Imp = { - ext: { - data: { - pbadslot: 'homepage-top-rect', - adUnitSpecificAttribute: '123' + const fpdBid = { + ...baseBidRequest, + params: { + segments: 'seg1, seg2' + }, + ortb2Imp: { + ext: { + data: { + pbadslot: 'homepage-top-rect', + adUnitSpecificAttribute: '123' + } } } } - const request = spec.buildRequests([fpdBid], bidderRequest) - const payload = JSON.parse(request.data) - expect(payload.imp[0].ext.data.pbadslot).to.equal('homepage-top-rect') - expect(payload.imp[0].ext.data.adUnitSpecificAttribute).to.equal('123') - expect(payload.imp[0].ext.deals).to.deep.equal(['seg1', 'seg2']) + + const request = spec.buildRequests([fpdBid], baseBidderRequest) + const impression = JSON.parse(request.data).imp[0] + + expect(impression.ext.data.pbadslot).to.equal('homepage-top-rect') + expect(impression.ext.data.adUnitSpecificAttribute).to.equal('123') + expect(impression.ext.deals).to.deep.equal(['seg1', 'seg2']) }) }) }); @@ -376,7 +356,7 @@ describe('sovrnBidAdapter', function() { }); it('should get the correct bid response', function () { - let expectedResponse = [{ + const expectedResponse = { 'requestId': '263c448586f5a1', 'cpm': 0.45882675, 'width': 728, @@ -389,15 +369,17 @@ describe('sovrnBidAdapter', function() { 'ad': decodeURIComponent(`>`), 'ttl': 60000, 'meta': { advertiserDomains: [] } - }]; + }; - let result = spec.interpretResponse(response); - expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0])); + const result = spec.interpretResponse(response); + + expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse)) }); it('crid should default to the bid id if not on the response', function () { delete response.body.seatbid[0].bid[0].crid; - let expectedResponse = [{ + + const expectedResponse = { 'requestId': '263c448586f5a1', 'cpm': 0.45882675, 'width': 728, @@ -410,16 +392,17 @@ describe('sovrnBidAdapter', function() { 'ad': decodeURIComponent(``), 'ttl': 90, 'meta': { advertiserDomains: [] } - }]; + } + + const result = spec.interpretResponse(response); - let result = spec.interpretResponse(response); - expect(result[0]).to.deep.equal(expectedResponse[0]); + expect(result[0]).to.deep.equal(expectedResponse); }); it('should get correct bid response when dealId is passed', function () { response.body.seatbid[0].bid[0].dealid = 'baking'; - let expectedResponse = [{ + const expectedResponse = { 'requestId': '263c448586f5a1', 'cpm': 0.45882675, 'width': 728, @@ -432,16 +415,17 @@ describe('sovrnBidAdapter', function() { 'ad': decodeURIComponent(``), 'ttl': 90, 'meta': { advertiserDomains: [] } - }]; + } - let result = spec.interpretResponse(response); - expect(result[0]).to.deep.equal(expectedResponse[0]); + const result = spec.interpretResponse(response) + + expect(result[0]).to.deep.equal(expectedResponse); }); it('should get correct bid response when ttl is set', function () { - response.body.seatbid[0].bid[0].ext = { 'ttl': 480 }; + response.body.seatbid[0].bid[0].ext = { 'ttl': 480 } - let expectedResponse = [{ + const expectedResponse = { 'requestId': '263c448586f5a1', 'cpm': 0.45882675, 'width': 728, @@ -454,28 +438,31 @@ describe('sovrnBidAdapter', function() { 'ad': decodeURIComponent(``), 'ttl': 480, 'meta': { advertiserDomains: [] } - }]; + } - let result = spec.interpretResponse(response); - expect(result[0]).to.deep.equal(expectedResponse[0]); - }); + const result = spec.interpretResponse(response) + + expect(result[0]).to.deep.equal(expectedResponse) + }) it('handles empty bid response', function () { - let response = { + const response = { body: { 'id': '37386aade21a71', 'seatbid': [] } }; - let result = spec.interpretResponse(response); + + const result = spec.interpretResponse(response) + expect(result.length).to.equal(0); }); }); describe('getUserSyncs ', function() { - let syncOptions = { iframeEnabled: true, pixelEnabled: false }; - let iframeDisabledSyncOptions = { iframeEnabled: false, pixelEnabled: false }; - let serverResponse = [ + const syncOptions = { iframeEnabled: true, pixelEnabled: false }; + const iframeDisabledSyncOptions = { iframeEnabled: false, pixelEnabled: false }; + const serverResponse = [ { 'body': { 'id': '546956d68c757f', @@ -524,14 +511,14 @@ describe('sovrnBidAdapter', function() { ]; it('should return if iid present on server response & iframe syncs enabled', function() { - const expectedReturnStatement = [ - { - 'type': 'iframe', - 'url': 'https://ap.lijit.com/beacon?informer=13487408', - } - ]; + const expectedReturnStatement = { + 'type': 'iframe', + 'url': 'https://ap.lijit.com/beacon?informer=13487408', + } + const returnStatement = spec.getUserSyncs(syncOptions, serverResponse); - expect(returnStatement[0]).to.deep.equal(expectedReturnStatement[0]); + + expect(returnStatement[0]).to.deep.equal(expectedReturnStatement); }); it('should include gdpr consent string if present', function() { @@ -539,26 +526,26 @@ describe('sovrnBidAdapter', function() { gdprApplies: 1, consentString: 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A==' } - const expectedReturnStatement = [ - { - 'type': 'iframe', - 'url': `https://ap.lijit.com/beacon?gdpr_consent=${gdprConsent.consentString}&informer=13487408`, - } - ]; + const expectedReturnStatement = { + 'type': 'iframe', + 'url': `https://ap.lijit.com/beacon?gdpr_consent=${gdprConsent.consentString}&informer=13487408`, + } + const returnStatement = spec.getUserSyncs(syncOptions, serverResponse, gdprConsent, ''); - expect(returnStatement[0]).to.deep.equal(expectedReturnStatement[0]); + + expect(returnStatement[0]).to.deep.equal(expectedReturnStatement); }); it('should include us privacy string if present', function() { const uspString = '1NYN'; - const expectedReturnStatement = [ - { - 'type': 'iframe', - 'url': `https://ap.lijit.com/beacon?us_privacy=${uspString}&informer=13487408`, - } - ]; + const expectedReturnStatement = { + 'type': 'iframe', + 'url': `https://ap.lijit.com/beacon?us_privacy=${uspString}&informer=13487408`, + } + const returnStatement = spec.getUserSyncs(syncOptions, serverResponse, null, uspString); - expect(returnStatement[0]).to.deep.equal(expectedReturnStatement[0]); + + expect(returnStatement[0]).to.deep.equal(expectedReturnStatement); }); it('should include all privacy strings if present', function() { @@ -567,57 +554,35 @@ describe('sovrnBidAdapter', function() { consentString: 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A==' } const uspString = '1NYN'; - const expectedReturnStatement = [ - { - 'type': 'iframe', - 'url': `https://ap.lijit.com/beacon?gdpr_consent=${gdprConsent.consentString}&us_privacy=${uspString}&informer=13487408`, - } - ]; - const returnStatement = spec.getUserSyncs(syncOptions, serverResponse, gdprConsent, uspString); - expect(returnStatement[0]).to.deep.equal(expectedReturnStatement[0]); + const expectedReturnStatement = { + 'type': 'iframe', + 'url': `https://ap.lijit.com/beacon?gdpr_consent=${gdprConsent.consentString}&us_privacy=${uspString}&informer=13487408`, + } + + const returnStatement = spec.getUserSyncs(syncOptions, serverResponse, gdprConsent, uspString) + + expect(returnStatement[0]).to.deep.equal(expectedReturnStatement) }); it('should not return if iid missing on server response', function() { const returnStatement = spec.getUserSyncs(syncOptions, []); + expect(returnStatement).to.be.empty; }); it('should not return if iframe syncs disabled', function() { const returnStatement = spec.getUserSyncs(iframeDisabledSyncOptions, serverResponse); + expect(returnStatement).to.be.empty; }); it('should include pixel syncs', function() { - let pixelEnabledOptions = { iframeEnabled: false, pixelEnabled: true }; - const resp2 = { + const pixelEnabledOptions = { iframeEnabled: false, pixelEnabled: true } + + const otherResponce = { + ...serverResponse, '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 - }, - ] - } - ], + ...serverResponse.body, 'ext': { 'iid': 13487408, sync: { @@ -631,10 +596,11 @@ describe('sovrnBidAdapter', function() { ] } } - }, - 'headers': {} + } } - const returnStatement = spec.getUserSyncs(pixelEnabledOptions, [...serverResponse, resp2]); + + const returnStatement = spec.getUserSyncs(pixelEnabledOptions, [...serverResponse, otherResponce]) + expect(returnStatement.length).to.equal(4); expect(returnStatement).to.deep.include.members([ { type: 'image', url: 'http://idprovider1.com' }, @@ -642,45 +608,6 @@ describe('sovrnBidAdapter', function() { { type: 'image', url: 'http://idprovider3.com' }, { type: 'image', url: 'http://idprovider4.com' } ]); - }); - }); - - describe('prebid 3 upgrade', function() { - const bidRequests = [{ - 'bidder': 'sovrn', - 'params': { - 'tagid': '403370' - }, - 'adUnitCode': 'adunit-code', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 600] - ] - } - }, - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475' - }]; - const bidderRequest = { - refererInfo: { - referer: 'http://example.com/page.html', - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - - it('gets sizes from mediaTypes.banner', function() { - 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('gets correct site info', function() { - expect(payload.site.page).to.equal('http://example.com/page.html'); - expect(payload.site.domain).to.equal('example.com'); }) }) }) From 00ca181e67404bd56553987e79a3782c235020c1 Mon Sep 17 00:00:00 2001 From: Mikhalovich Date: Tue, 14 Sep 2021 14:46:01 +0300 Subject: [PATCH 2/7] EX-2588 Remove duplicated object initialization --- test/spec/modules/sovrnBidAdapter_spec.js | 65 +++++++---------------- 1 file changed, 18 insertions(+), 47 deletions(-) diff --git a/test/spec/modules/sovrnBidAdapter_spec.js b/test/spec/modules/sovrnBidAdapter_spec.js index ac8cc9fbadc..1b2e426a0e0 100644 --- a/test/spec/modules/sovrnBidAdapter_spec.js +++ b/test/spec/modules/sovrnBidAdapter_spec.js @@ -335,6 +335,20 @@ describe('sovrnBidAdapter', function() { describe('interpretResponse', function () { let response; + const baseResponse = { + 'requestId': '263c448586f5a1', + 'cpm': 0.45882675, + 'width': 728, + 'height': 90, + 'creativeId': 'creativelycreatedcreativecreative', + 'dealId': null, + 'currency': 'USD', + 'netRevenue': true, + 'mediaType': 'banner', + 'ad': decodeURIComponent(``), + 'ttl': 90, + 'meta': { advertiserDomains: [] } + } beforeEach(function () { response = { body: { @@ -357,18 +371,9 @@ describe('sovrnBidAdapter', function() { it('should get the correct bid response', function () { const expectedResponse = { - 'requestId': '263c448586f5a1', - 'cpm': 0.45882675, - 'width': 728, - 'height': 90, - 'creativeId': 'creativelycreatedcreativecreative', - 'dealId': null, - 'currency': 'USD', - 'netRevenue': true, - 'mediaType': 'banner', + ...baseResponse, 'ad': decodeURIComponent(`>`), 'ttl': 60000, - 'meta': { advertiserDomains: [] } }; const result = spec.interpretResponse(response); @@ -380,18 +385,9 @@ describe('sovrnBidAdapter', function() { delete response.body.seatbid[0].bid[0].crid; const expectedResponse = { - 'requestId': '263c448586f5a1', - 'cpm': 0.45882675, - 'width': 728, - 'height': 90, + ...baseResponse, 'creativeId': response.body.seatbid[0].bid[0].id, - 'dealId': null, - 'currency': 'USD', - 'netRevenue': true, - 'mediaType': 'banner', 'ad': decodeURIComponent(``), - 'ttl': 90, - 'meta': { advertiserDomains: [] } } const result = spec.interpretResponse(response); @@ -402,42 +398,17 @@ describe('sovrnBidAdapter', function() { it('should get correct bid response when dealId is passed', function () { response.body.seatbid[0].bid[0].dealid = 'baking'; - const expectedResponse = { - 'requestId': '263c448586f5a1', - 'cpm': 0.45882675, - 'width': 728, - 'height': 90, - 'creativeId': 'creativelycreatedcreativecreative', - 'dealId': 'baking', - 'currency': 'USD', - 'netRevenue': true, - 'mediaType': 'banner', - 'ad': decodeURIComponent(``), - 'ttl': 90, - 'meta': { advertiserDomains: [] } - } - const result = spec.interpretResponse(response) - expect(result[0]).to.deep.equal(expectedResponse); + expect(result[0]).to.deep.equal(baseResponse); }); it('should get correct bid response when ttl is set', function () { response.body.seatbid[0].bid[0].ext = { 'ttl': 480 } const expectedResponse = { - 'requestId': '263c448586f5a1', - 'cpm': 0.45882675, - 'width': 728, - 'height': 90, - 'creativeId': 'creativelycreatedcreativecreative', - 'dealId': null, - 'currency': 'USD', - 'netRevenue': true, - 'mediaType': 'banner', - 'ad': decodeURIComponent(``), + ...baseResponse, 'ttl': 480, - 'meta': { advertiserDomains: [] } } const result = spec.interpretResponse(response) From 1fa6e10842c5e79e60bfda4468ad821e9a2638d7 Mon Sep 17 00:00:00 2001 From: Mikhalovich Date: Tue, 14 Sep 2021 17:22:11 +0300 Subject: [PATCH 3/7] EX-2588 Fix interpretResponse test --- test/spec/modules/sovrnBidAdapter_spec.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/spec/modules/sovrnBidAdapter_spec.js b/test/spec/modules/sovrnBidAdapter_spec.js index 1b2e426a0e0..3f62ec5bbc3 100644 --- a/test/spec/modules/sovrnBidAdapter_spec.js +++ b/test/spec/modules/sovrnBidAdapter_spec.js @@ -397,10 +397,14 @@ describe('sovrnBidAdapter', function() { it('should get correct bid response when dealId is passed', function () { response.body.seatbid[0].bid[0].dealid = 'baking'; + const expectedResponse = { + ...baseResponse, + 'dealId': 'baking', + } const result = spec.interpretResponse(response) - expect(result[0]).to.deep.equal(baseResponse); + expect(result[0]).to.deep.equal(expectedResponse); }); it('should get correct bid response when ttl is set', function () { From 667cab637db2aaaf81636c28e7ac6619d41b5c57 Mon Sep 17 00:00:00 2001 From: Mikhalovich Date: Tue, 14 Sep 2021 18:05:34 +0300 Subject: [PATCH 4/7] EX-3265 Format code in sovrn's tests --- test/spec/modules/sovrnBidAdapter_spec.js | 330 +++++++++++----------- 1 file changed, 165 insertions(+), 165 deletions(-) diff --git a/test/spec/modules/sovrnBidAdapter_spec.js b/test/spec/modules/sovrnBidAdapter_spec.js index 3f62ec5bbc3..f1112f24bec 100644 --- a/test/spec/modules/sovrnBidAdapter_spec.js +++ b/test/spec/modules/sovrnBidAdapter_spec.js @@ -1,70 +1,70 @@ -import {expect} from 'chai'; -import {spec} from 'modules/sovrnBidAdapter.js'; -import {config} from 'src/config.js'; +import {expect} from 'chai' +import {spec} from 'modules/sovrnBidAdapter.js' +import {config} from 'src/config.js' import * as utils from 'src/utils.js' -const ENDPOINT = `https://ap.lijit.com/rtb/bid?src=$$REPO_AND_VERSION$$`; +const ENDPOINT = `https://ap.lijit.com/rtb/bid?src=$$REPO_AND_VERSION$$` const baseBidRequest = { - 'bidder': 'sovrn', - 'params': { - 'tagid': 403370 + bidder: 'sovrn', + params: { + tagid: 403370 }, - 'adUnitCode': 'adunit-code', - 'sizes': [ + adUnitCode: 'adunit-code', + sizes: [ [300, 250], [300, 600] ], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', + bidId: '30b31c1838de1e', + bidderRequestId: '22edbae2733bf6', + auctionId: '1d1a030790a475', } const baseBidderRequest = { refererInfo: { referer: 'http://example.com/page.html', } -}; +} describe('sovrnBidAdapter', function() { describe('isBidRequestValid', function () { it('should return true when required params found', function () { - expect(spec.isBidRequestValid(baseBidRequest)).to.equal(true); - }); + expect(spec.isBidRequestValid(baseBidRequest)).to.equal(true) + }) it('should return false when tagid not passed correctly', function () { const bidRequest = { ...baseBidRequest, - 'params': { + params: { ...baseBidRequest.params, - 'tagid': 'ABCD' + tagid: 'ABCD' }, - }; + } - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); + expect(spec.isBidRequestValid(bidRequest)).to.equal(false) + }) it('should return false when require params are not passed', function () { const bidRequest = { ...baseBidRequest, - 'params': {} + params: {} } - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - }); + expect(spec.isBidRequestValid(bidRequest)).to.equal(false) + }) + }) describe('buildRequests', function () { describe('basic bid parameters', function() { - const request = spec.buildRequests([baseBidRequest], baseBidderRequest); - const payload = JSON.parse(request.data); + const request = spec.buildRequests([baseBidRequest], baseBidderRequest) + const payload = JSON.parse(request.data) it('sends bid request to our endpoint via POST', function () { - expect(request.method).to.equal('POST'); - }); + expect(request.method).to.equal('POST') + }) it('attaches source and version to endpoint URL as query params', function () { expect(request.url).to.equal(ENDPOINT) - }); + }) it('sets the proper banner object', function() { const impression = payload.imp[0] @@ -75,9 +75,9 @@ describe('sovrnBidAdapter', function() { }) it('gets correct site info', function() { - expect(payload.site.page).to.equal('http://example.com/page.html'); - expect(payload.site.domain).to.equal('example.com'); - }); + expect(payload.site.page).to.equal('http://example.com/page.html') + expect(payload.site.domain).to.equal('example.com') + }) it('includes the ad unit code in the request', function() { const impression = payload.imp[0] @@ -86,16 +86,16 @@ describe('sovrnBidAdapter', function() { it('converts tagid to string', function () { expect(request.data).to.contain('"tagid":"403370"') - }); + }) }) it('accepts a single array as a size', function() { const singleSizeBidRequest = { ...baseBidRequest, - 'params': { - 'iv': 'vet' + params: { + iv: 'vet' }, - 'sizes': [300, 250] + sizes: [300, 250] } const request = spec.buildRequests([singleSizeBidRequest], baseBidderRequest) @@ -117,21 +117,21 @@ describe('sovrnBidAdapter', function() { const request = spec.buildRequests([ivBidRequest], baseBidderRequest) expect(request.url).to.contain('iv=vet') - }); + }) it('sends gdpr info if exists', function () { const bidderRequest = { ...baseBidderRequest, - 'bidderCode': 'sovrn', - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'gdprConsent': { - 'consentString': 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A==', - 'gdprApplies': true + bidderCode: 'sovrn', + auctionId: '1d1a030790a475', + bidderRequestId: '22edbae2733bf6', + timeout: 3000, + gdprConsent: { + consentString: 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A==', + gdprApplies: true }, - 'bids': [baseBidRequest] - }; + bids: [baseBidRequest] + } const { regs, user } = JSON.parse(spec.buildRequests([baseBidRequest], bidderRequest).data) @@ -144,12 +144,12 @@ describe('sovrnBidAdapter', function() { it('should send us_privacy if bidderRequest has a value for uspConsent', function () { const bidderRequest = { ...baseBidderRequest, - 'bidderCode': 'sovrn', - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'uspConsent': '1NYN', - 'bids': [baseBidRequest] + bidderCode: 'sovrn', + auctionId: '1d1a030790a475', + bidderRequestId: '22edbae2733bf6', + timeout: 3000, + uspConsent: '1NYN', + bids: [baseBidRequest] } const data = JSON.parse(spec.buildRequests([baseBidRequest], bidderRequest).data) @@ -160,15 +160,15 @@ describe('sovrnBidAdapter', function() { it('should add schain if present', function() { const schainRequest = { ...baseBidRequest, - 'schain': { - 'ver': '1.0', - 'complete': 1, - 'nodes': [ + schain: { + ver: '1.0', + complete: 1, + nodes: [ { - 'asi': 'directseller.com', - 'sid': '00001', - 'rid': 'BidRequest1', - 'hp': 1 + asi: 'directseller.com', + sid: '00001', + rid: 'BidRequest1', + hp: 1 } ] } @@ -331,88 +331,88 @@ describe('sovrnBidAdapter', function() { expect(impression.ext.deals).to.deep.equal(['seg1', 'seg2']) }) }) - }); + }) describe('interpretResponse', function () { - let response; + let response const baseResponse = { - 'requestId': '263c448586f5a1', - 'cpm': 0.45882675, - 'width': 728, - 'height': 90, - 'creativeId': 'creativelycreatedcreativecreative', - 'dealId': null, - 'currency': 'USD', - 'netRevenue': true, - 'mediaType': 'banner', - 'ad': decodeURIComponent(``), - 'ttl': 90, - 'meta': { advertiserDomains: [] } + requestId: '263c448586f5a1', + cpm: 0.45882675, + width: 728, + height: 90, + creativeId: 'creativelycreatedcreativecreative', + dealId: null, + currency: 'USD', + netRevenue: true, + mediaType: 'banner', + ad: decodeURIComponent(``), + ttl: 90, + meta: { advertiserDomains: [] } } beforeEach(function () { response = { body: { - 'id': '37386aade21a71', - 'seatbid': [{ - 'bid': [{ - 'id': 'a_403370_332fdb9b064040ddbec05891bd13ab28', - 'crid': 'creativelycreatedcreativecreative', - 'impid': '263c448586f5a1', - 'price': 0.45882675, - 'nurl': '', - 'adm': '', - 'h': 90, - 'w': 728 + id: '37386aade21a71', + seatbid: [{ + bid: [{ + id: 'a_403370_332fdb9b064040ddbec05891bd13ab28', + crid: 'creativelycreatedcreativecreative', + impid: '263c448586f5a1', + price: 0.45882675, + nurl: '', + adm: '', + h: 90, + w: 728 }] }] } - }; - }); + } + }) it('should get the correct bid response', function () { const expectedResponse = { ...baseResponse, - 'ad': decodeURIComponent(`>`), - 'ttl': 60000, - }; + ad: decodeURIComponent(`>`), + ttl: 60000, + } - const result = spec.interpretResponse(response); + const result = spec.interpretResponse(response) expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse)) - }); + }) it('crid should default to the bid id if not on the response', function () { - delete response.body.seatbid[0].bid[0].crid; + delete response.body.seatbid[0].bid[0].crid const expectedResponse = { ...baseResponse, - 'creativeId': response.body.seatbid[0].bid[0].id, - 'ad': decodeURIComponent(``), + creativeId: response.body.seatbid[0].bid[0].id, + ad: decodeURIComponent(``), } - const result = spec.interpretResponse(response); + const result = spec.interpretResponse(response) - expect(result[0]).to.deep.equal(expectedResponse); - }); + expect(result[0]).to.deep.equal(expectedResponse) + }) it('should get correct bid response when dealId is passed', function () { response.body.seatbid[0].bid[0].dealid = 'baking'; const expectedResponse = { ...baseResponse, - 'dealId': 'baking', + dealId: 'baking', } const result = spec.interpretResponse(response) - expect(result[0]).to.deep.equal(expectedResponse); - }); + expect(result[0]).to.deep.equal(expectedResponse) + }) it('should get correct bid response when ttl is set', function () { response.body.seatbid[0].bid[0].ext = { 'ttl': 480 } const expectedResponse = { ...baseResponse, - 'ttl': 480, + ttl: 480, } const result = spec.interpretResponse(response) @@ -423,52 +423,52 @@ describe('sovrnBidAdapter', function() { it('handles empty bid response', function () { const response = { body: { - 'id': '37386aade21a71', - 'seatbid': [] + id: '37386aade21a71', + seatbid: [] } - }; + } const result = spec.interpretResponse(response) - expect(result.length).to.equal(0); - }); - }); + expect(result.length).to.equal(0) + }) + }) describe('getUserSyncs ', function() { - const syncOptions = { iframeEnabled: true, pixelEnabled: false }; - const iframeDisabledSyncOptions = { iframeEnabled: false, pixelEnabled: false }; + const syncOptions = { iframeEnabled: true, pixelEnabled: false } + const iframeDisabledSyncOptions = { iframeEnabled: false, pixelEnabled: false } const serverResponse = [ { - 'body': { - 'id': '546956d68c757f', - 'seatbid': [ + body: { + id: '546956d68c757f', + seatbid: [ { - 'bid': [ + bid: [ { - 'id': 'a_448326_16c2ada014224bee815a90d2248322f5', - '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_448326_16c2ada014224bee815a90d2248322f5', + 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', - '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 + id: 'a_430392_beac4c1515da4576acf6cb9c5340b40c', + 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, + ext: { + iid: 13487408, sync: { pixels: [ { @@ -481,20 +481,20 @@ describe('sovrnBidAdapter', function() { } } }, - 'headers': {} + headers: {} } - ]; + ] it('should return if iid present on server response & iframe syncs enabled', function() { const expectedReturnStatement = { - 'type': 'iframe', - 'url': 'https://ap.lijit.com/beacon?informer=13487408', + type: 'iframe', + url: 'https://ap.lijit.com/beacon?informer=13487408', } - const returnStatement = spec.getUserSyncs(syncOptions, serverResponse); + const returnStatement = spec.getUserSyncs(syncOptions, serverResponse) - expect(returnStatement[0]).to.deep.equal(expectedReturnStatement); - }); + expect(returnStatement[0]).to.deep.equal(expectedReturnStatement) + }) it('should include gdpr consent string if present', function() { const gdprConsent = { @@ -502,64 +502,64 @@ describe('sovrnBidAdapter', function() { consentString: 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A==' } const expectedReturnStatement = { - 'type': 'iframe', - 'url': `https://ap.lijit.com/beacon?gdpr_consent=${gdprConsent.consentString}&informer=13487408`, + type: 'iframe', + url: `https://ap.lijit.com/beacon?gdpr_consent=${gdprConsent.consentString}&informer=13487408`, } - const returnStatement = spec.getUserSyncs(syncOptions, serverResponse, gdprConsent, ''); + const returnStatement = spec.getUserSyncs(syncOptions, serverResponse, gdprConsent, '') - expect(returnStatement[0]).to.deep.equal(expectedReturnStatement); - }); + expect(returnStatement[0]).to.deep.equal(expectedReturnStatement) + }) it('should include us privacy string if present', function() { - const uspString = '1NYN'; + const uspString = '1NYN' const expectedReturnStatement = { - 'type': 'iframe', - 'url': `https://ap.lijit.com/beacon?us_privacy=${uspString}&informer=13487408`, + type: 'iframe', + url: `https://ap.lijit.com/beacon?us_privacy=${uspString}&informer=13487408`, } - const returnStatement = spec.getUserSyncs(syncOptions, serverResponse, null, uspString); + const returnStatement = spec.getUserSyncs(syncOptions, serverResponse, null, uspString) - expect(returnStatement[0]).to.deep.equal(expectedReturnStatement); - }); + expect(returnStatement[0]).to.deep.equal(expectedReturnStatement) + }) it('should include all privacy strings if present', function() { const gdprConsent = { gdprApplies: 1, consentString: 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A==' } - const uspString = '1NYN'; + const uspString = '1NYN' const expectedReturnStatement = { - 'type': 'iframe', - 'url': `https://ap.lijit.com/beacon?gdpr_consent=${gdprConsent.consentString}&us_privacy=${uspString}&informer=13487408`, + type: 'iframe', + url: `https://ap.lijit.com/beacon?gdpr_consent=${gdprConsent.consentString}&us_privacy=${uspString}&informer=13487408`, } const returnStatement = spec.getUserSyncs(syncOptions, serverResponse, gdprConsent, uspString) expect(returnStatement[0]).to.deep.equal(expectedReturnStatement) - }); + }) it('should not return if iid missing on server response', function() { - const returnStatement = spec.getUserSyncs(syncOptions, []); + const returnStatement = spec.getUserSyncs(syncOptions, []) - expect(returnStatement).to.be.empty; - }); + expect(returnStatement).to.be.empty + }) it('should not return if iframe syncs disabled', function() { - const returnStatement = spec.getUserSyncs(iframeDisabledSyncOptions, serverResponse); + const returnStatement = spec.getUserSyncs(iframeDisabledSyncOptions, serverResponse) - expect(returnStatement).to.be.empty; - }); + expect(returnStatement).to.be.empty + }) it('should include pixel syncs', function() { const pixelEnabledOptions = { iframeEnabled: false, pixelEnabled: true } const otherResponce = { ...serverResponse, - 'body': { + body: { ...serverResponse.body, - 'ext': { - 'iid': 13487408, + ext: { + iid: 13487408, sync: { pixels: [ { @@ -576,13 +576,13 @@ describe('sovrnBidAdapter', function() { const returnStatement = spec.getUserSyncs(pixelEnabledOptions, [...serverResponse, otherResponce]) - expect(returnStatement.length).to.equal(4); + 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' } - ]); + ]) }) }) }) From 54c6a7cbb8ce895882ecf9a5fbb7ddfd2428073e Mon Sep 17 00:00:00 2001 From: Mikhalovich Date: Wed, 15 Sep 2021 10:42:46 +0300 Subject: [PATCH 5/7] EX-2588 Return prebid 3 upgrage test in sovrn's tests --- test/spec/modules/sovrnBidAdapter_spec.js | 30 +++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/spec/modules/sovrnBidAdapter_spec.js b/test/spec/modules/sovrnBidAdapter_spec.js index 3f62ec5bbc3..6fd5eecfb78 100644 --- a/test/spec/modules/sovrnBidAdapter_spec.js +++ b/test/spec/modules/sovrnBidAdapter_spec.js @@ -585,4 +585,34 @@ describe('sovrnBidAdapter', function() { ]); }) }) + + describe('prebid 3 upgrade', function() { + const bidRequest = { + ...baseBidRequest, + 'params': { + 'tagid': '403370' + }, + 'mediaTypes': { + 'banner': { + 'sizes': [ + [300, 250], + [300, 600] + ] + } + }, + }; + const request = spec.buildRequests([bidRequest], baseBidderRequest); + const payload = JSON.parse(request.data); + + it('gets sizes from mediaTypes.banner', function() { + 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('gets correct site info', function() { + expect(payload.site.page).to.equal('http://example.com/page.html'); + expect(payload.site.domain).to.equal('example.com'); + }) + }) }) From f7d212daed5f0be9bc7bb2dc560237acb8216ad7 Mon Sep 17 00:00:00 2001 From: Mikhalovich Date: Wed, 15 Sep 2021 10:47:23 +0300 Subject: [PATCH 6/7] EX-3265 Format previous commit changes --- test/spec/modules/sovrnBidAdapter_spec.js | 24 +++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test/spec/modules/sovrnBidAdapter_spec.js b/test/spec/modules/sovrnBidAdapter_spec.js index 1d642c4ae90..40bab456557 100644 --- a/test/spec/modules/sovrnBidAdapter_spec.js +++ b/test/spec/modules/sovrnBidAdapter_spec.js @@ -396,7 +396,7 @@ describe('sovrnBidAdapter', function() { }) it('should get correct bid response when dealId is passed', function () { - response.body.seatbid[0].bid[0].dealid = 'baking'; + response.body.seatbid[0].bid[0].dealid = 'baking' const expectedResponse = { ...baseResponse, dealId: 'baking', @@ -408,7 +408,7 @@ describe('sovrnBidAdapter', function() { }) it('should get correct bid response when ttl is set', function () { - response.body.seatbid[0].bid[0].ext = { 'ttl': 480 } + response.body.seatbid[0].bid[0].ext = { ttl: 480 } const expectedResponse = { ...baseResponse, @@ -589,20 +589,20 @@ describe('sovrnBidAdapter', function() { describe('prebid 3 upgrade', function() { const bidRequest = { ...baseBidRequest, - 'params': { - 'tagid': '403370' + params: { + tagid: '403370' }, - 'mediaTypes': { - 'banner': { - 'sizes': [ + mediaTypes: { + banner: { + sizes: [ [300, 250], [300, 600] ] } }, - }; - const request = spec.buildRequests([bidRequest], baseBidderRequest); - const payload = JSON.parse(request.data); + } + const request = spec.buildRequests([bidRequest], baseBidderRequest) + const payload = JSON.parse(request.data) it('gets sizes from mediaTypes.banner', function() { expect(payload.imp[0].banner.format).to.deep.equal([{w: 300, h: 250}, {w: 300, h: 600}]) @@ -611,8 +611,8 @@ describe('sovrnBidAdapter', function() { }) it('gets correct site info', function() { - expect(payload.site.page).to.equal('http://example.com/page.html'); - expect(payload.site.domain).to.equal('example.com'); + expect(payload.site.page).to.equal('http://example.com/page.html') + expect(payload.site.domain).to.equal('example.com') }) }) }) From da3979c589430080a76bd50caa723bb68a6bec09 Mon Sep 17 00:00:00 2001 From: Maxim Pakhomov Date: Mon, 16 May 2022 17:04:49 +0400 Subject: [PATCH 7/7] feat: [EX-3265] fixed merge conflicts --- test/spec/modules/sovrnBidAdapter_spec.js | 222 +++++++++++++++++++--- 1 file changed, 196 insertions(+), 26 deletions(-) diff --git a/test/spec/modules/sovrnBidAdapter_spec.js b/test/spec/modules/sovrnBidAdapter_spec.js index 40bab456557..518ea1f0a70 100644 --- a/test/spec/modules/sovrnBidAdapter_spec.js +++ b/test/spec/modules/sovrnBidAdapter_spec.js @@ -67,6 +67,14 @@ describe('sovrnBidAdapter', function() { }) it('sets the proper banner object', function() { + const bannerBidRequest = { + ...baseBidRequest, + mediaTypes: { + banner: {} + } + } + const request = spec.buildRequests([bannerBidRequest], baseBidderRequest) + const payload = JSON.parse(request.data) const impression = payload.imp[0] expect(impression.banner.format).to.deep.equal([{w: 300, h: 250}, {w: 300, h: 600}]) @@ -74,6 +82,40 @@ describe('sovrnBidAdapter', function() { expect(impression.banner.h).to.equal(1) }) + it('sets the proper video object', function() { + const width = 640 + const height = 480 + const mimes = ['video/mp4', 'application/javascript'] + const protocols = [2, 5] + const minduration = 5 + const maxduration = 60 + const startdelay = 0 + const videoBidRequest = { + ...baseBidRequest, + mediaTypes: { + video: { + mimes, + protocols, + playerSize: [[width, height], [360, 240]], + minduration, + maxduration, + startdelay + } + } + } + const request = spec.buildRequests([videoBidRequest], baseBidderRequest) + const payload = JSON.parse(request.data) + const impression = payload.imp[0] + + expect(impression.video.w).to.equal(width) + expect(impression.video.h).to.equal(height) + expect(impression.video.mimes).to.have.same.members(mimes) + expect(impression.video.protocols).to.have.same.members(protocols) + expect(impression.video.minduration).to.equal(minduration) + expect(impression.video.maxduration).to.equal(maxduration) + expect(impression.video.startdelay).to.equal(startdelay) + }) + it('gets correct site info', function() { expect(payload.site.page).to.equal('http://example.com/page.html') expect(payload.site.domain).to.equal('example.com') @@ -95,10 +137,12 @@ describe('sovrnBidAdapter', function() { params: { iv: 'vet' }, - sizes: [300, 250] + sizes: [300, 250], + mediaTypes: { + banner: {} + }, } const request = spec.buildRequests([singleSizeBidRequest], baseBidderRequest) - const payload = JSON.parse(request.data) const impression = payload.imp[0] @@ -132,7 +176,6 @@ describe('sovrnBidAdapter', function() { }, bids: [baseBidRequest] } - const { regs, user } = JSON.parse(spec.buildRequests([baseBidRequest], bidderRequest).data) expect(regs.ext.gdpr).to.exist.and.to.be.a('number') @@ -151,7 +194,6 @@ describe('sovrnBidAdapter', function() { uspConsent: '1NYN', bids: [baseBidRequest] } - const data = JSON.parse(spec.buildRequests([baseBidRequest], bidderRequest).data) expect(data.regs.ext['us_privacy']).to.equal(bidderRequest.uspConsent) @@ -174,7 +216,6 @@ describe('sovrnBidAdapter', function() { } } const schainRequests = [schainRequest, baseBidRequest] - const data = JSON.parse(spec.buildRequests(schainRequests, baseBidderRequest).data) expect(data.source.ext.schain.nodes.length).to.equal(1) @@ -189,7 +230,6 @@ describe('sovrnBidAdapter', function() { } } const criteoIdRequests = [criteoIdRequest, baseBidRequest] - const ext = JSON.parse(spec.buildRequests(criteoIdRequests, baseBidderRequest).data).user.ext const firstEID = ext.eids[0] const secondEID = ext.eids[1] @@ -235,7 +275,6 @@ describe('sovrnBidAdapter', function() { bidfloor: 2.00 } } - const request = spec.buildRequests([floorBid], baseBidderRequest) const payload = JSON.parse(request.data) @@ -250,7 +289,6 @@ describe('sovrnBidAdapter', function() { tagid: 1234, bidfloor: 2.00 } - const request = spec.buildRequests([floorBid], baseBidderRequest) const impression = JSON.parse(request.data).imp[0] @@ -300,7 +338,6 @@ describe('sovrnBidAdapter', function() { } } } - const request = spec.buildRequests([fpdBidRequest], baseBidderRequest) const payload = JSON.parse(request.data) @@ -322,7 +359,6 @@ describe('sovrnBidAdapter', function() { } } } - const request = spec.buildRequests([fpdBid], baseBidderRequest) const impression = JSON.parse(request.data).imp[0] @@ -345,24 +381,38 @@ describe('sovrnBidAdapter', function() { currency: 'USD', netRevenue: true, mediaType: 'banner', - ad: decodeURIComponent(``), ttl: 90, - meta: { advertiserDomains: [] } + meta: { advertiserDomains: [] }, + ad: decodeURIComponent(``), + } + const videoBid = { + id: 'a_403370_332fdb9b064040ddbec05891bd13ab28', + crid: 'creativelycreatedcreativecreative', + impid: '263c448586f5a1', + price: 0.45882675, + nurl: '', + adm: 'key%3Dvalue', + h: 480, + w: 640 } + const bannerBid = { + id: 'a_403370_332fdb9b064040ddbec05891bd13ab28', + crid: 'creativelycreatedcreativecreative', + impid: '263c448586f5a1', + price: 0.45882675, + nurl: '', + adm: '', + h: 90, + w: 728 + } + beforeEach(function () { response = { body: { id: '37386aade21a71', seatbid: [{ bid: [{ - id: 'a_403370_332fdb9b064040ddbec05891bd13ab28', - crid: 'creativelycreatedcreativecreative', - impid: '263c448586f5a1', - price: 0.45882675, - nurl: '', - adm: '', - h: 90, - w: 728 + ...bannerBid }] }] } @@ -375,7 +425,6 @@ describe('sovrnBidAdapter', function() { ad: decodeURIComponent(`>`), ttl: 60000, } - const result = spec.interpretResponse(response) expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse)) @@ -389,7 +438,6 @@ describe('sovrnBidAdapter', function() { creativeId: response.body.seatbid[0].bid[0].id, ad: decodeURIComponent(``), } - const result = spec.interpretResponse(response) expect(result[0]).to.deep.equal(expectedResponse) @@ -401,7 +449,6 @@ describe('sovrnBidAdapter', function() { ...baseResponse, dealId: 'baking', } - const result = spec.interpretResponse(response) expect(result[0]).to.deep.equal(expectedResponse) @@ -414,7 +461,6 @@ describe('sovrnBidAdapter', function() { ...baseResponse, ttl: 480, } - const result = spec.interpretResponse(response) expect(result[0]).to.deep.equal(expectedResponse) @@ -427,7 +473,133 @@ describe('sovrnBidAdapter', function() { seatbid: [] } } + const result = spec.interpretResponse(response) + + expect(result.length).to.equal(0) + }) + + it('should get the correct bid response with 2 different bids', function () { + const expectedVideoResponse = { + ...baseResponse, + vastXml: decodeURIComponent(videoBid.adm) + } + delete expectedVideoResponse.ad + const expectedBannerResponse = { + ...baseResponse + } + + response.body.seatbid = [{ bid: [bannerBid] }, { bid: [videoBid] }] + const result = spec.interpretResponse(response) + + expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedBannerResponse)) + expect(Object.keys(result[1])).to.deep.equal(Object.keys(expectedVideoResponse)) + }) + + it('should get the correct bid response with 2 seatbid items', function () { + const expectedResponse = { + ...baseResponse + } + response.body.seatbid = [response.body.seatbid[0], response.body.seatbid[0]] + + const result = spec.interpretResponse(response) + + expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse)) + expect(Object.keys(result[1])).to.deep.equal(Object.keys(expectedResponse)) + }) + }) + + describe('interpretResponse video', function () { + let videoResponse + const bidAdm = 'key%3Dvalue' + const decodedBidAdm = decodeURIComponent(bidAdm) + const baseVideoResponse = { + requestId: '263c448586f5a1', + cpm: 0.45882675, + width: 640, + height: 480, + creativeId: 'creativelycreatedcreativecreative', + dealId: null, + currency: 'USD', + netRevenue: true, + mediaType: 'video', + ttl: 90, + meta: { advertiserDomains: [] }, + vastXml: decodedBidAdm + } + + beforeEach(function () { + videoResponse = { + body: { + id: '37386aade21a71', + seatbid: [{ + bid: [{ + id: 'a_403370_332fdb9b064040ddbec05891bd13ab28', + crid: 'creativelycreatedcreativecreative', + impid: '263c448586f5a1', + price: 0.45882675, + nurl: '', + adm: bidAdm, + h: 480, + w: 640 + }] + }] + } + } + }) + + it('should get the correct bid response', function () { + const expectedResponse = { + ...baseVideoResponse, + ttl: 60000, + } + const result = spec.interpretResponse(videoResponse) + + expect(result[0]).to.have.deep.keys(expectedResponse) + }) + + it('crid should default to the bid id if not on the response', function () { + delete videoResponse.body.seatbid[0].bid[0].crid + + const expectedResponse = { + ...baseVideoResponse, + creativeId: videoResponse.body.seatbid[0].bid[0].id, + } + const result = spec.interpretResponse(videoResponse) + + expect(result[0]).to.deep.equal(expectedResponse) + }) + + it('should get correct bid response when dealId is passed', function () { + videoResponse.body.seatbid[0].bid[0].dealid = 'baking' + const expectedResponse = { + ...baseVideoResponse, + dealId: 'baking', + } + const result = spec.interpretResponse(videoResponse) + + expect(result[0]).to.deep.equal(expectedResponse) + }) + + it('should get correct bid response when ttl is set', function () { + videoResponse.body.seatbid[0].bid[0].ext = { 'ttl': 480 } + + const expectedResponse = { + ...baseVideoResponse, + ttl: 480, + } + const result = spec.interpretResponse(videoResponse) + + expect(result[0]).to.deep.equal(expectedResponse) + }) + + it('handles empty bid response', function () { + const response = { + body: { + id: '37386aade21a71', + seatbid: [] + } + } const result = spec.interpretResponse(response) expect(result.length).to.equal(0) @@ -490,7 +662,6 @@ describe('sovrnBidAdapter', function() { type: 'iframe', url: 'https://ap.lijit.com/beacon?informer=13487408', } - const returnStatement = spec.getUserSyncs(syncOptions, serverResponse) expect(returnStatement[0]).to.deep.equal(expectedReturnStatement) @@ -553,7 +724,6 @@ describe('sovrnBidAdapter', function() { it('should include pixel syncs', function() { const pixelEnabledOptions = { iframeEnabled: false, pixelEnabled: true } - const otherResponce = { ...serverResponse, body: {