Skip to content

Commit

Permalink
change payload (#5105)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentproxistore authored Apr 10, 2020
1 parent b8d5e05 commit 8f8f6f8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
19 changes: 8 additions & 11 deletions modules/proxistoreBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,23 @@ const { registerBidder } = require('../src/adapters/bidderFactory.js');
const BIDDER_CODE = 'proxistore';
const PROXISTORE_VENDOR_ID = 418;

function _mapSizes(sizes) {
const flatSize = sizes.reduce((acc, val) => acc.concat(val), []); ;
return flatSize.map(array1d => { return { width: array1d[0], height: array1d[1] } });
}

function _createServerRequest(bidRequests, bidderRequest) {
const sizeIds = [];
bidRequests.forEach(bid => {
const sizeId = {id: bid.bidId, sizes: bid.sizes.map(size => { return { width: size[0], height: size[1] } })};
sizeIds.push(sizeId);
});
const payload = {
auctionId: bidRequests[0].auctionId,
transactionId: bidRequests[0].transactionId,
sizes: _mapSizes(bidRequests.map(x => x.sizes)),
transactionId: bidRequests[0].auctionId,
bids: sizeIds,
website: bidRequests[0].params.website,
language: bidRequests[0].params.language,
gdpr: {
applies: false
}
};

const bidIds = bidRequests.map(req => req.bidId);
bidIds.length === 1 ? payload.bidId = bidIds[0] : payload.bidIds = bidIds;

const options = {
contentType: 'application/json',
withCredentials: true
Expand All @@ -42,7 +39,7 @@ function _createServerRequest(bidRequests, bidderRequest) {

return {
method: 'POST',
url: bidRequests[0].params.url || 'https://abs.proxistore.com/' + payload.language + '/v3/rtb/prebid',
url: bidRequests[0].params.url || 'https://abs.proxistore.com/' + payload.language + '/v3/rtb/prebid/multi',
data: JSON.stringify(payload),
options: options
};
Expand Down
12 changes: 8 additions & 4 deletions test/spec/modules/proxistoreBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('ProxistoreBidAdapter', function () {
});

describe('buildRequests', function () {
const url = 'https://abs.proxistore.com/fr/v3/rtb/prebid';
const url = 'https://abs.proxistore.com/fr/v3/rtb/prebid/multi';
const request = spec.buildRequests([bid], bidderRequest);
it('should return a valid object', function () {
expect(request).to.be.an('object');
Expand All @@ -55,10 +55,14 @@ describe('ProxistoreBidAdapter', function () {
expect(data.gdpr.applies).to.be.true;
expect(data.gdpr.consentGiven).to.be.true;
});
it('should have a property bidId if there is only one bid', function () {
it('should have a property a length of bids equal to one if there is only one bid', function () {
const data = JSON.parse(request.data);
expect(data.hasOwnProperty('bidId')).to.be.true;
})
expect(data.hasOwnProperty('bids')).to.be.true;
expect(data.bids).to.be.an('array');
expect(data.bids.length).equal(1);
expect(data.bids[0].hasOwnProperty('id')).to.be.true;
expect(data.bids[0].sizes).to.be.an('array');
});
});

describe('interpretResponse', function () {
Expand Down

0 comments on commit 8f8f6f8

Please sign in to comment.