Skip to content

Commit

Permalink
Merge pull request #50 from Marfeel/revert-49-put1x1SizesBidCachingIf…
Browse files Browse the repository at this point in the history
…300x250

Revert "fix bidcaching for 1x1"
  • Loading branch information
pedrolopezmrf authored Mar 4, 2020
2 parents 6fe7d23 + 5db1973 commit 9224f02
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 54 deletions.
22 changes: 3 additions & 19 deletions src/marfeelTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,7 @@ export const setLastLocationFromLastAdUnit = (adUnitArr) => {
}
}

const normalizeSizes = sizesArray => sizesArray.join('x');

function is1x1Allowed(auctionSizes) {
const LARGE_SIZE_NORMALIZED = '300x250';

return (auctionSizes.map(normalizeSizes).includes(LARGE_SIZE_NORMALIZED));
}

const getCurrentAuctionSizes = () => {
export const getCurrentAuctionSizes = () => {
const lastAdUnitUsed = [...auctionManager.getAdUnits()].pop();

if (lastAdUnitUsed &&
Expand All @@ -64,19 +56,11 @@ const getCurrentAuctionSizes = () => {
return [];
}

const normalizeSizes = sizesArray => sizesArray.join('x');

export const isBidSizeAllowed = (bid, allowedSizes) => {
const allowedSizesNormalized = allowedSizes.map(normalizeSizes);
const bidSize = normalizeSizes([bid.width, bid.height]);

return allowedSizesNormalized.includes(bidSize);
}

function add1x1IfAllowed(auctionSizes) {
const SIZE_1_X_1 = [1, 1];

return is1x1Allowed(auctionSizes) ? [...auctionSizes, SIZE_1_X_1] : auctionSizes;
}

export function getAllowedSizes() {
return add1x1IfAllowed(getCurrentAuctionSizes())
}
4 changes: 2 additions & 2 deletions src/targeting.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { auctionManager } from './auctionManager';
import { sizeSupported } from './sizeMapping';
import { ADPOD } from './mediaTypes';
import includes from 'core-js/library/fn/array/includes';
import { getLastLocation, getAllowedSizes, isBidSizeAllowed } from './marfeelTools';
import { getLastLocation, getCurrentAuctionSizes, isBidSizeAllowed } from './marfeelTools';

const utils = require('./utils.js');
var CONSTANTS = require('./constants.json');
Expand Down Expand Up @@ -372,7 +372,7 @@ export function newTargeting(auctionManager) {
}));

const bidsToFilter = bidsByReferrer[lastLocation] || filterBidsByAdUnit(bidsReceived);
const allowedSizes = getAllowedSizes();
const allowedSizes = getCurrentAuctionSizes();

bidsToProcess = bidsToFilter.filter(bid => isBidSizeAllowed(bid, allowedSizes));
}
Expand Down
34 changes: 1 addition & 33 deletions test/spec/marfeelTools_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
* from Marfeel Solutions SL.
*/

import { isBidSizeAllowed, getAllowedSizes } from './marfeelTools';
import { auctionManager } from './auctionManager';
import { filterBidsBySizes } from './marfeelTools';

describe('marfeelTools', function () {
describe('isBidSizeAllowed', function() {
Expand Down Expand Up @@ -43,35 +42,4 @@ describe('marfeelTools', function () {
}])
});
});
describe('getAllowedSizes', function() {
it('adds 1x1 to allowed sizes if 300x250 is present', function() {
const currentSizes = [[100, 100], [300, 150], [300, 250]];
const fakeGetAdUnits = () => [{
mediaTypes: {
banner: {
sizes: currentSizes
}
}
}];
sinon.replace(auctionManager, 'getAdUnits', fakeGetAdUnits);
const expectedSizes = [[100, 100], [300, 150], [300, 250], [1, 1]];

assert.deepEqual(getAllowedSizes(), expectedSizes);
});

it('does not add 1x1 to allowed sizes if 300x250 is not present', function() {
const currentSizes = [[100, 100], [300, 150]];
const fakeGetAdUnits = () => [{
mediaTypes: {
banner: {
sizes: currentSizes
}
}
}];
sinon.replace(auctionManager, 'getAdUnits', fakeGetAdUnits);
const expectedSizes = [[100, 100], [300, 150]];

assert.deepEqual(getAllowedSizes(), expectedSizes);
});
});
});

0 comments on commit 9224f02

Please sign in to comment.