Skip to content

Commit

Permalink
Missena Bid Adapter: floor implementation (#10534)
Browse files Browse the repository at this point in the history
* Missena: floor implementation

* Missena: only floor, tests

* Missena: pass adServerCurrency to server

* Remove the custom calculation of the size parameter in getFloor()

---------

Co-authored-by: youssef <youssef.bsf@gmail.com>
  • Loading branch information
pdamoc and ysfbsf authored Nov 15, 2023
1 parent 2691a50 commit c027061
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 10 deletions.
42 changes: 38 additions & 4 deletions modules/missenaBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { buildUrl, formatQS, logInfo, triggerPixel } from '../src/utils.js';
import {
buildUrl,
formatQS,
isFn,
logInfo,
triggerPixel,
} from '../src/utils.js';
import { config } from '../src/config.js';
import { BANNER } from '../src/mediaTypes.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';

Expand All @@ -7,6 +14,22 @@ const ENDPOINT_URL = 'https://bid.missena.io/';
const EVENTS_DOMAIN = 'events.missena.io';
const EVENTS_DOMAIN_DEV = 'events.staging.missena.xyz';

/* Get Floor price information */
function getFloor(bidRequest) {
if (!isFn(bidRequest.getFloor)) {
return {};
}

const bidFloors = bidRequest.getFloor({
currency: 'USD',
mediaType: BANNER
});

if (!isNaN(bidFloors.floor)) {
return bidFloors;
}
}

export const spec = {
aliases: ['msna'],
code: BIDDER_CODE,
Expand Down Expand Up @@ -61,6 +84,12 @@ export const spec = {
payload.is_internal = bidRequest.params.isInternal;
}
payload.userEids = bidRequest.userIdAsEids || [];

const bidFloor = getFloor(bidRequest);
payload.floor = bidFloor?.floor;
payload.floor_currency = bidFloor?.currency;
payload.currency = config.getConfig('currency.adServerCurrency') || 'EUR';

return {
method: 'POST',
url: baseUrl + '?' + formatQS({ t: bidRequest.params.apiKey }),
Expand Down Expand Up @@ -89,7 +118,7 @@ export const spec = {
syncOptions,
serverResponses,
gdprConsent,
uspConsent
uspConsent,
) {
if (!syncOptions.iframeEnabled) {
return [];
Expand Down Expand Up @@ -128,8 +157,13 @@ export const spec = {
protocol: 'https',
hostname,
pathname: '/v1/bidsuccess',
search: { t: bid.params[0].apiKey, provider: bid.meta?.networkName, cpm: bid.cpm, currency: bid.currency },
})
search: {
t: bid.params[0].apiKey,
provider: bid.meta?.networkName,
cpm: bid.originalCpm,
currency: bid.originalCurrency,
},
}),
);
logInfo('Missena - Bid won', bid);
},
Expand Down
44 changes: 38 additions & 6 deletions test/spec/modules/missenaBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect } from 'chai';
import { spec, _getPlatform } from 'modules/missenaBidAdapter.js';
import { newBidder } from 'src/adapters/bidderFactory.js';
import { BANNER } from '../../../src/mediaTypes.js';

describe('Missena Adapter', function () {
const adapter = newBidder(spec);
Expand All @@ -11,6 +12,28 @@ describe('Missena Adapter', function () {
bidder: 'missena',
bidId: bidId,
sizes: [[1, 1]],
mediaTypes: { banner: { sizes: [[1, 1]] } },
params: {
apiKey: 'PA-34745704',
placement: 'sticky',
formats: ['sticky-banner'],
},
getFloor: (inputParams) => {
if (inputParams.mediaType === BANNER) {
return {
currency: 'EUR',
floor: 3.5,
};
} else {
return {};
}
},
};
const bidWithoutFloor = {
bidder: 'missena',
bidId: bidId,
sizes: [[1, 1]],
mediaTypes: { banner: { sizes: [[1, 1]] } },
params: {
apiKey: 'PA-34745704',
placement: 'sticky',
Expand All @@ -31,13 +54,13 @@ describe('Missena Adapter', function () {

it('should return false if the apiKey is missing', function () {
expect(
spec.isBidRequestValid(Object.assign(bid, { params: {} }))
spec.isBidRequestValid(Object.assign(bid, { params: {} })),
).to.equal(false);
});

it('should return false if the apiKey is an empty string', function () {
expect(
spec.isBidRequestValid(Object.assign(bid, { params: { apiKey: '' } }))
spec.isBidRequestValid(Object.assign(bid, { params: { apiKey: '' } })),
).to.equal(false);
});
});
Expand All @@ -56,9 +79,10 @@ describe('Missena Adapter', function () {
},
};

const requests = spec.buildRequests([bid, bid], bidderRequest);
const requests = spec.buildRequests([bid, bidWithoutFloor], bidderRequest);
const request = requests[0];
const payload = JSON.parse(request.data);
const payloadNoFloor = JSON.parse(requests[1].data);

it('should return as many server requests as bidder requests', function () {
expect(requests.length).to.equal(2);
Expand Down Expand Up @@ -89,6 +113,14 @@ describe('Missena Adapter', function () {
expect(payload.consent_string).to.equal(consentString);
expect(payload.consent_required).to.equal(true);
});
it('should send floor data', function () {
expect(payload.floor).to.equal(3.5);
expect(payload.floor_currency).to.equal('EUR');
});
it('should not send floor data if not available', function () {
expect(payloadNoFloor.floor).to.equal(undefined);
expect(payloadNoFloor.floor_currency).to.equal(undefined);
});
});

describe('interpretResponse', function () {
Expand Down Expand Up @@ -121,22 +153,22 @@ describe('Missena Adapter', function () {
expect(result.length).to.equal(1);

expect(Object.keys(result[0])).to.have.members(
Object.keys(serverResponse)
Object.keys(serverResponse),
);
});

it('should return an empty response when the server answers with a timeout', function () {
const result = spec.interpretResponse(
{ body: serverTimeoutResponse },
bid
bid,
);
expect(result).to.deep.equal([]);
});

it('should return an empty response when the server answers with an empty ad', function () {
const result = spec.interpretResponse(
{ body: serverEmptyAdResponse },
bid
bid,
);
expect(result).to.deep.equal([]);
});
Expand Down

0 comments on commit c027061

Please sign in to comment.