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

Missena Bid Adapter: add capping support #10746

Merged
merged 3 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion modules/missenaBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@ import {
formatQS,
isFn,
logInfo,
safeJSONParse,
triggerPixel,
} from '../src/utils.js';
import { config } from '../src/config.js';
import { BANNER } from '../src/mediaTypes.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { getStorageManager } from '../src/storageManager.js';

const BIDDER_CODE = 'missena';
const ENDPOINT_URL = 'https://bid.missena.io/';
const EVENTS_DOMAIN = 'events.missena.io';
const EVENTS_DOMAIN_DEV = 'events.staging.missena.xyz';

export const storage = getStorageManager({ bidderCode: BIDDER_CODE });

/* Get Floor price information */
function getFloor(bidRequest) {
if (!isFn(bidRequest.getFloor)) {
Expand All @@ -22,7 +26,7 @@ function getFloor(bidRequest) {

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

if (!isNaN(bidFloors.floor)) {
Expand Down Expand Up @@ -53,6 +57,16 @@ export const spec = {
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function (validBidRequests, bidderRequest) {
const capKey = `missena.missena.capper.remove-bubble.${validBidRequests[0]?.params.apiKey}`;
const capping = safeJSONParse(storage.getDataFromLocalStorage(capKey));
if (
typeof capping?.expiry === 'number' &&
new Date().getTime() < capping?.expiry
) {
logInfo('Missena - Capped');
return [];
}

return validBidRequests.map((bidRequest) => {
const payload = {
adunit: bidRequest.adUnitCode,
Expand Down
59 changes: 42 additions & 17 deletions test/spec/modules/missenaBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { expect } from 'chai';
import { spec, _getPlatform } from 'modules/missenaBidAdapter.js';
import { newBidder } from 'src/adapters/bidderFactory.js';
import { spec, storage } from 'modules/missenaBidAdapter.js';
import { BANNER } from '../../../src/mediaTypes.js';

describe('Missena Adapter', function () {
const adapter = newBidder(spec);
$$PREBID_GLOBAL$$.bidderSettings = {
missena: {
storageAllowed: true,
},
};

const bidId = 'abc';

const bid = {
bidder: 'missena',
bidId: bidId,
Expand Down Expand Up @@ -40,7 +42,20 @@ describe('Missena Adapter', function () {
formats: ['sticky-banner'],
},
};
const consentString = 'AAAAAAAAA==';

const bidderRequest = {
gdprConsent: {
consentString: consentString,
gdprApplies: true,
},
refererInfo: {
topmostLocation: 'https://referer',
canonicalUrl: 'https://canonical',
},
};

const bids = [bid, bidWithoutFloor];
describe('codes', function () {
it('should return a bidder code of missena', function () {
expect(spec.code).to.equal('missena');
Expand All @@ -66,20 +81,12 @@ describe('Missena Adapter', function () {
});

describe('buildRequests', function () {
const consentString = 'AAAAAAAAA==';

const bidderRequest = {
gdprConsent: {
consentString: consentString,
gdprApplies: true,
},
refererInfo: {
topmostLocation: 'https://referer',
canonicalUrl: 'https://canonical',
},
};
let getDataFromLocalStorageStub = sinon.stub(
storage,
'getDataFromLocalStorage',
);

const requests = spec.buildRequests([bid, bidWithoutFloor], bidderRequest);
const requests = spec.buildRequests(bids, bidderRequest);
const request = requests[0];
const payload = JSON.parse(request.data);
const payloadNoFloor = JSON.parse(requests[1].data);
Expand Down Expand Up @@ -121,6 +128,24 @@ describe('Missena Adapter', function () {
expect(payloadNoFloor.floor).to.equal(undefined);
expect(payloadNoFloor.floor_currency).to.equal(undefined);
});

getDataFromLocalStorageStub.restore();
getDataFromLocalStorageStub = sinon.stub(
storage,
'getDataFromLocalStorage',
);
const localStorageData = {
[`missena.missena.capper.remove-bubble.${bid.params.apiKey}`]:
JSON.stringify({
expiry: new Date().getTime() + 600_000, // 10 min into the future
}),
};
getDataFromLocalStorageStub.callsFake((key) => localStorageData[key]);
const cappedRequests = spec.buildRequests(bids, bidderRequest);

it('should not participate if capped', function () {
expect(cappedRequests.length).to.equal(0);
});
});

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