Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dgirardi committed Oct 23, 2024
1 parent a187978 commit 56f316a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
12 changes: 8 additions & 4 deletions modules/bidResponseFilter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,23 @@ export const BID_ATTR_REJECTION_REASON = 'Attr is not allowed';
let moduleConfig;
let enabled = false;

function init(addBidResponse = getHook('addBidResponse')) {
function init() {
config.getConfig(MODULE_NAME, (cfg) => {
moduleConfig = cfg[MODULE_NAME];
if (enabled && !moduleConfig) {
enabled = false;
addBidResponse.getHooks({hook: addBidResponseHook}).remove();
reset();
} else if (!enabled && moduleConfig) {
enabled = true;
addBidResponse.before(addBidResponseHook);
getHook('addBidResponse').before(addBidResponseHook);
}
})
}

export function reset() {
enabled = false;
getHook('addBidResponse').getHooks({hook: addBidResponseHook}).remove();
}

export function addBidResponseHook(next, adUnitCode, bid, reject, index = auctionManager.index) {
const {bcat = [], badv = []} = index.getOrtb2(bid) || {};
const battr = index.getBidRequest(bid)?.ortb2Imp[bid.mediaType]?.battr || index.getAdUnit(bid)?.ortb2Imp[bid.mediaType]?.battr || [];
Expand Down
7 changes: 3 additions & 4 deletions test/spec/modules/bidResponseFilter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
BID_CATEGORY_REJECTION_REASON,
init,
MODULE_NAME
} from '../../../modules/bidResponseFilter';
, reset} from '../../../modules/bidResponseFilter';
import {config} from '../../../src/config';
import {addBidResponse} from '../../../src/auction.js';

Expand All @@ -21,6 +21,7 @@ describe('bidResponseFilter', () => {
});
afterEach(() => {
config.resetConfig();
reset();
})

describe('enable/disable', () => {
Expand All @@ -32,9 +33,7 @@ describe('bidResponseFilter', () => {
});

it('should not run if not configured', () => {
config.setConfig({
bidResponseFilter: null
})
reset();
addBidResponse.call({dispatch}, 'au', {}, reject);
sinon.assert.notCalled(reject);
sinon.assert.called(dispatch);
Expand Down

0 comments on commit 56f316a

Please sign in to comment.