Skip to content

Commit

Permalink
add transaction ids to adyoulike adapter (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbAdyoulike committed Sep 22, 2017
1 parent 74e5f9f commit ddf45f8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
9 changes: 6 additions & 3 deletions modules/adyoulikeBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { STATUS } from 'src/constants';
import adaptermanager from 'src/adaptermanager';

var AdyoulikeAdapter = function AdyoulikeAdapter() {
const _VERSION = '0.1';
const _VERSION = '0.2';

const baseAdapter = new Adapter('adyoulike');

Expand All @@ -21,7 +21,7 @@ var AdyoulikeAdapter = function AdyoulikeAdapter() {

const placements = validBids.map(bid => bid.params.placement);
if (!utils.isEmpty(placements)) {
const body = createBody(placements);
const body = createBody(bidRequests, placements);
const endpoint = createEndpoint();
ajax(endpoint,
(response) => {
Expand Down Expand Up @@ -61,10 +61,11 @@ var AdyoulikeAdapter = function AdyoulikeAdapter() {
}

/* Create request body */
function createBody(placements) {
function createBody(bidRequests, placements) {
const body = {
Version: _VERSION,
Placements: placements,
TransactionIds: {}
};

// performance isn't supported by mobile safari iOS7. window.performance works, but
Expand All @@ -80,6 +81,8 @@ var AdyoulikeAdapter = function AdyoulikeAdapter() {
body.PageRefreshed = false;
}

placements.forEach(placement => { body.TransactionIds[placement] = bidRequests[placement].transactionId; });

return JSON.stringify(body);
}

Expand Down
27 changes: 18 additions & 9 deletions test/spec/modules/adyoulikeBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ describe('Adyoulike Adapter', () => {
'placementCode': 'adunit/hb-0',
'params': {
'placement': 'placement_0'
}
},
'transactionId': 'bid_id_0_transaction_id'
}
],
};
Expand All @@ -43,7 +44,8 @@ describe('Adyoulike Adapter', () => {
'params': {
'placement': 'placement_0'
},
'sizes': '300x250'
'sizes': '300x250',
'transactionId': 'bid_id_0_transaction_id'
}
],
};
Expand All @@ -57,7 +59,8 @@ describe('Adyoulike Adapter', () => {
'params': {
'placement': 'placement_0'
},
'sizes': '300x250'
'sizes': '300x250',
'transactionId': 'bid_id_0_transaction_id'
},
{
'bidId': 'bid_id_1',
Expand All @@ -66,22 +69,25 @@ describe('Adyoulike Adapter', () => {
'params': {
'placement': 'placement_1'
},
'sizes': [[300, 600]]
'sizes': [[300, 600]],
'transactionId': 'bid_id_1_transaction_id'
},
{
'bidId': 'bid_id_2',
'bidder': 'adyoulike',
'placementCode': 'adunit/hb-2',
'params': {},
'sizes': '300x400'
'sizes': '300x400',
'transactionId': 'bid_id_3_transaction_id'
},
{
'bidId': 'bid_id_3',
'bidder': 'adyoulike',
'placementCode': 'adunit/hb-3',
'params': {
'placement': 'placement_3'
}
},
'transactionId': 'bid_id_3_transaction_id'
}
],
};
Expand Down Expand Up @@ -175,9 +181,10 @@ describe('Adyoulike Adapter', () => {
expect(requests[0].url).to.contains('CanonicalUrl=' + encodeURIComponent(canonicalUrl));

let body = JSON.parse(requests[0].requestBody);
expect(body.Version).to.equal('0.1');
expect(body.Version).to.equal('0.2');
expect(body.Placements).deep.equal(['placement_0']);
expect(body.PageRefreshed).to.equal(false);
expect(body.TransactionIds).deep.equal({'placement_0': 'bid_id_0_transaction_id'});
});

it('sends bid request to endpoint with single placement without canonical', () => {
Expand All @@ -190,9 +197,10 @@ describe('Adyoulike Adapter', () => {
expect(requests[0].url).to.not.contains('CanonicalUrl=' + encodeURIComponent(canonicalUrl));

let body = JSON.parse(requests[0].requestBody);
expect(body.Version).to.equal('0.1');
expect(body.Version).to.equal('0.2');
expect(body.Placements).deep.equal(['placement_0']);
expect(body.PageRefreshed).to.equal(false);
expect(body.TransactionIds).deep.equal({'placement_0': 'bid_id_0_transaction_id'});
});

it('sends bid request to endpoint with multiple placements', () => {
Expand All @@ -203,9 +211,10 @@ describe('Adyoulike Adapter', () => {
expect(requests[0].url).to.contains('CanonicalUrl=' + encodeURIComponent(canonicalUrl));

let body = JSON.parse(requests[0].requestBody);
expect(body.Version).to.equal('0.1');
expect(body.Version).to.equal('0.2');
expect(body.Placements).deep.equal(['placement_0', 'placement_1']);
expect(body.PageRefreshed).to.equal(false);
expect(body.TransactionIds).deep.equal({'placement_0': 'bid_id_0_transaction_id', 'placement_1': 'bid_id_1_transaction_id'});
});
});

Expand Down

0 comments on commit ddf45f8

Please sign in to comment.