diff --git a/modules/adyoulikeBidAdapter.js b/modules/adyoulikeBidAdapter.js index a3e07b25c35..da27bee00d7 100644 --- a/modules/adyoulikeBidAdapter.js +++ b/modules/adyoulikeBidAdapter.js @@ -72,11 +72,19 @@ export const spec = { * @param {*} serverResponse A successful response from the server. * @return {Bid[]} An array of bids which were nested inside the server. */ - interpretResponse: function (serverResponse, bidRequest) { + interpretResponse: function (serverResponse, request) { const bidResponses = []; + var bidRequests = {}; + + try { + bidRequests = JSON.parse(request.data).Bids; + } catch (e) { + // json error initial request can't be read + } + // For this adapter, serverResponse is a list serverResponse.body.forEach(response => { - const bid = createBid(response); + const bid = createBid(response, bidRequests); if (bid) { bidResponses.push(bid); } @@ -98,7 +106,7 @@ function getHostname(bidderRequest) { function getReferrerUrl(bidderRequest) { let referer = ''; if (bidderRequest && bidderRequest.refererInfo) { - referer = encodeURIComponent(bidderRequest.refererInfo.referer); + referer = bidderRequest.refererInfo.referer; } return referer; } @@ -192,11 +200,22 @@ function getSize(sizesArray) { } /* Create bid from response */ -function createBid(response) { +function createBid(response, bidRequests) { if (!response || !response.Ad) { return } + // In case we don't retreive the size from the adserver, use the given one. + if (bidRequests && bidRequests[response.BidID]) { + if (!response.Width || response.Width === '0') { + response.Width = bidRequests[response.BidID].Width; + } + + if (!response.Height || response.Height === '0') { + response.Height = bidRequests[response.BidID].Height; + } + } + return { requestId: response.BidID, width: response.Width, diff --git a/test/spec/modules/adyoulikeBidAdapter_spec.js b/test/spec/modules/adyoulikeBidAdapter_spec.js index a76468671c8..9bd8ea7ec06 100644 --- a/test/spec/modules/adyoulikeBidAdapter_spec.js +++ b/test/spec/modules/adyoulikeBidAdapter_spec.js @@ -6,14 +6,31 @@ import { newBidder } from 'src/adapters/bidderFactory'; describe('Adyoulike Adapter', function () { const canonicalUrl = 'https://canonical.url/?t=%26'; + const referrerUrl = 'http://referrer.url/?param=value'; const defaultDC = 'hb-api'; + const consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; + const bidderRequest = { + 'auctionId': '1d1a030790a475', + 'bidderRequestId': '22edbae2733bf6', + 'timeout': 3000, + 'gdprConsent': { + consentString: consentString, + gdprApplies: true + }, + refererInfo: {referer: referrerUrl} + }; const bidRequestWithEmptyPlacement = [ { 'bidId': 'bid_id_0', 'bidder': 'adyoulike', 'placementCode': 'adunit/hb-0', 'params': {}, - 'sizes': '300x250' + 'sizes': '300x250', + 'mediaTypes': + { 'banner': + {'sizes': ['300x250', '300x600'] + } + } } ]; const bidRequestWithEmptySizes = { @@ -39,6 +56,11 @@ describe('Adyoulike Adapter', function () { 'placement': 'placement_0' }, 'sizes': '300x250', + 'mediaTypes': + { 'banner': + {'sizes': ['300x250'] + } + }, 'transactionId': 'bid_id_0_transaction_id' } ]; @@ -53,6 +75,11 @@ describe('Adyoulike Adapter', function () { 'DC': 'fra01' }, 'sizes': '300x250', + 'mediaTypes': + { 'banner': + {'sizes': ['300x250'] + } + }, 'transactionId': 'bid_id_0_transaction_id' } ]; @@ -66,6 +93,11 @@ describe('Adyoulike Adapter', function () { 'placement': 'placement_0' }, 'sizes': '300x250', + 'mediaTypes': + { 'banner': + {'sizes': ['300x250'] + } + }, 'transactionId': 'bid_id_0_transaction_id' }, { @@ -76,6 +108,11 @@ describe('Adyoulike Adapter', function () { 'placement': 'placement_1' }, 'sizes': [[300, 600]], + 'mediaTypes': + { 'banner': + {'sizes': ['300x600'] + } + }, 'transactionId': 'bid_id_1_transaction_id' }, { @@ -97,6 +134,33 @@ describe('Adyoulike Adapter', function () { } ]; + const requestDataOnePlacement = { + 'bid_id_0': + { 'PlacementID': 'e622af275681965d3095808561a1e510', + 'TransactionID': '1bca18cc-c0fe-439b-88c2-8247d3448f22', + 'Width': 300, + 'Height': 600, + 'AvailableSizes': '300x600' + } + } + + const requestDataMultiPlacement = { + 'bid_id_0': + { 'PlacementID': 'e622af275681965d3095808561a1e510', + 'TransactionID': '1bca18cc-c0fe-439b-88c2-8247d3448f22', + 'Width': 300, + 'Height': 600, + 'AvailableSizes': '300x600' + }, + 'bid_id_1': + { 'PlacementID': 'e622af275681965d3095808561a1e510', + 'TransactionID': 'e63b2d86-ca60-4167-9cf1-497607079634', + 'Width': 400, + 'Height': 250, + 'AvailableSizes': '300x250' + } + } + const responseWithEmptyPlacement = [ { 'Placement': 'placement_0' @@ -108,8 +172,7 @@ describe('Adyoulike Adapter', function () { 'Placement': 'placement_0', 'Ad': 'placement_0', 'Price': 0.5, - 'Height': 300, - 'Width': 300, + 'Height': 600, } ]; const responseWithMultiplePlacements = [ @@ -118,16 +181,16 @@ describe('Adyoulike Adapter', function () { 'Placement': 'placement_0', 'Ad': 'placement_0', 'Price': 0.5, - 'Height': 300, - 'Width': 300, + 'Height': 0, // test with wrong value + 'Width': 300 }, { 'BidID': 'bid_id_1', 'Placement': 'placement_1', 'Ad': 'placement_1', 'Price': 0.6, - 'Height': 300, - 'Width': 300, + 'Height': 250 + // 'Width' test with missing value } ]; const adapter = newBidder(spec); @@ -189,16 +252,6 @@ describe('Adyoulike Adapter', function () { }); it('should add gdpr consent information to the request', function () { - let consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; - let bidderRequest = { - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'gdprConsent': { - consentString: consentString, - gdprApplies: true - } - }; bidderRequest.bids = bidRequestWithSinglePlacement; const request = spec.buildRequests(bidRequestWithSinglePlacement, bidderRequest); @@ -210,12 +263,13 @@ describe('Adyoulike Adapter', function () { }); it('sends bid request to endpoint with single placement', function () { - const request = spec.buildRequests(bidRequestWithSinglePlacement); + const request = spec.buildRequests(bidRequestWithSinglePlacement, bidderRequest); const payload = JSON.parse(request.data); expect(request.url).to.contain(getEndpoint()); expect(request.method).to.equal('POST'); expect(request.url).to.contains('CanonicalUrl=' + encodeURIComponent(canonicalUrl)); + expect(request.url).to.contains('RefererUrl=' + encodeURIComponent(referrerUrl)); expect(payload.Version).to.equal('1.0'); expect(payload.Bids['bid_id_0'].PlacementID).to.be.equal('placement_0'); @@ -225,7 +279,7 @@ describe('Adyoulike Adapter', function () { it('sends bid request to endpoint with single placement without canonical', function () { canonicalQuery.restore(); - const request = spec.buildRequests(bidRequestWithSinglePlacement); + const request = spec.buildRequests(bidRequestWithSinglePlacement, bidderRequest); const payload = JSON.parse(request.data); expect(request.url).to.contain(getEndpoint()); @@ -239,12 +293,13 @@ describe('Adyoulike Adapter', function () { }); it('sends bid request to endpoint with multiple placements', function () { - const request = spec.buildRequests(bidRequestMultiPlacements); + const request = spec.buildRequests(bidRequestMultiPlacements, bidderRequest); const payload = JSON.parse(request.data); expect(request.url).to.contain(getEndpoint()); expect(request.method).to.equal('POST'); expect(request.url).to.contains('CanonicalUrl=' + encodeURIComponent(canonicalUrl)); + expect(request.url).to.contains('RefererUrl=' + encodeURIComponent(referrerUrl)); expect(payload.Version).to.equal('1.0'); @@ -259,7 +314,7 @@ describe('Adyoulike Adapter', function () { }); it('sends bid request to endpoint setted by parameters', function () { - const request = spec.buildRequests(bidRequestWithDCPlacement); + const request = spec.buildRequests(bidRequestWithDCPlacement, bidderRequest); const payload = JSON.parse(request.data); expect(request.url).to.contain(getEndpoint(`${defaultDC}-fra01`)); @@ -288,30 +343,30 @@ describe('Adyoulike Adapter', function () { it('receive reponse with single placement', function () { serverResponse.body = responseWithSinglePlacement; - let result = spec.interpretResponse(serverResponse, bidRequestWithSinglePlacement); + let result = spec.interpretResponse(serverResponse, {data: '{"Bids":' + JSON.stringify(requestDataOnePlacement) + '}'}); expect(result.length).to.equal(1); expect(result[0].cpm).to.equal(0.5); expect(result[0].ad).to.equal('placement_0'); expect(result[0].width).to.equal(300); - expect(result[0].height).to.equal(300); + expect(result[0].height).to.equal(600); }); it('receive reponse with multiple placement', function () { serverResponse.body = responseWithMultiplePlacements; - let result = spec.interpretResponse(serverResponse, bidRequestMultiPlacements); + let result = spec.interpretResponse(serverResponse, {data: '{"Bids":' + JSON.stringify(requestDataMultiPlacement) + '}'}); expect(result.length).to.equal(2); expect(result[0].cpm).to.equal(0.5); expect(result[0].ad).to.equal('placement_0'); expect(result[0].width).to.equal(300); - expect(result[0].height).to.equal(300); + expect(result[0].height).to.equal(600); expect(result[1].cpm).to.equal(0.6); expect(result[1].ad).to.equal('placement_1'); - expect(result[1].width).to.equal(300); - expect(result[1].height).to.equal(300); + expect(result[1].width).to.equal(400); + expect(result[1].height).to.equal(250); }); }); });