Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adnuntius Bid Adapter: Bug fix ordered response. #6625

Merged
merged 11 commits into from
Apr 20, 2021
50 changes: 28 additions & 22 deletions modules/adnuntiusBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

import { registerBidder } from '../src/adapters/bidderFactory.js';

const BIDDER_CODE = 'adnuntius';
const ENDPOINT_URL = 'https://delivery.adnuntius.com/i?tzo=';

export const spec = {
code: BIDDER_CODE,

isBidRequestValid: function (bid) {
return !!(bid.params.auId || (bid.params.member && bid.params.invCode));
return !!(bid.bidId || (bid.params.member && bid.params.invCode));
},

buildRequests: function (validBidRequests) {
Expand Down Expand Up @@ -42,28 +42,34 @@ export const spec = {
},

interpretResponse: function (serverResponse, bidRequest) {
const bidResponses = [];
const serverBody = serverResponse.body;

for (var k = 0; k < serverBody.adUnits.length; k++) {
const adUnit = serverBody.adUnits[k]
if (adUnit.matchedAdCount > 0) {
const adUnits = serverResponse.body.adUnits;
const bidResponsesById = adUnits.reduce((response, adUnit) => {
if (adUnit.matchedAdCount >= 1) {
const bid = adUnit.ads[0];
const effectiveCpm = (bid.cpc && bid.cpm) ? bid.bid.amount + bid.cpm.amount : (bid.cpc) ? bid.bid.amount : (bid.cpm) ? bid.cpm.amount : 0;
bidResponses.push({
requestId: bidRequest.bid[k].bidId,
cpm: effectiveCpm,
width: Number(bid.creativeWidth),
height: Number(bid.creativeHeight),
creativeId: bid.creativeId,
currency: (bid.bid) ? bid.bid.currency : 'EUR',
netRevenue: false,
ttl: 360,
ad: adUnit.html
});
}
}
return bidResponses;
return {
...response,
[adUnit.targetId]: {
requestId: adUnit.targetId,
cpm: effectiveCpm,
width: Number(bid.creativeWidth),
height: Number(bid.creativeHeight),
creativeId: bid.creativeId,
currency: (bid.bid) ? bid.bid.currency : 'EUR',
netRevenue: false,
ttl: 360,
ad: adUnit.html
}
}
} else return response
}, {});

const bidResponse = bidRequest.bid.map(bid => bid.bidId)
.reduce((request, adunitId) =>
request.concat(bidResponsesById[adunitId])
, []);

return bidResponse
},

}
Expand Down
20 changes: 14 additions & 6 deletions test/spec/modules/adnuntiusBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,33 @@ describe('adnuntiusBidAdapter', function () {
const tzo = new Date().getTimezoneOffset();
const ENDPOINT_URL = `https://delivery.adnuntius.com/i?tzo=${tzo}&format=json`;
const adapter = newBidder(spec);

const bidRequests = [
{
bidId: '123',
bidder: 'adnuntius',
params: {
auId: '8b6bc',
network: 'adnuntius',
},
bidId: '123'

}
];
]

const singleBidRequest = {
bid: [
{
bidId: '123',
}
]
}

const serverResponse = {
body: {
'adUnits': [
{
'auId': '000000000008b6bc',
'targetId': '',
'targetId': '123',
'html': '<h1>hi!</h1>',
'matchedAdCount': 1,
'responseId': 'adn-rsp-1460129238',
Expand Down Expand Up @@ -103,10 +113,8 @@ describe('adnuntiusBidAdapter', function () {

describe('interpretResponse', function () {
it('should return valid response when passed valid server response', function () {
const request = spec.buildRequests(bidRequests);
const interpretedResponse = spec.interpretResponse(serverResponse, request[0]);
const interpretedResponse = spec.interpretResponse(serverResponse, singleBidRequest);
const ad = serverResponse.body.adUnits[0].ads[0]
const cpm = (ad.cpc && ad.cpm) ? ad.bid.amount + ad.cpm.amount : (ad.cpm) ? ad.cpm.amount : 0;

expect(interpretedResponse).to.have.lengthOf(1);
expect(interpretedResponse[0].cpm).to.equal(ad.cpm.amount);
Expand Down