diff --git a/modules/rtdModule/index.js b/modules/rtdModule/index.js index 1efa89e329f..63c6a8d580d 100644 --- a/modules/rtdModule/index.js +++ b/modules/rtdModule/index.js @@ -197,12 +197,13 @@ const setEventsListeners = (function () { return function setEventsListeners() { if (!registered) { Object.entries({ - [CONSTANTS.EVENTS.AUCTION_INIT]: 'onAuctionInitEvent', - [CONSTANTS.EVENTS.AUCTION_END]: 'onAuctionEndEvent', - [CONSTANTS.EVENTS.BID_RESPONSE]: 'onBidResponseEvent', - [CONSTANTS.EVENTS.BID_REQUESTED]: 'onBidRequestEvent' - }).forEach(([ev, handler]) => { + [CONSTANTS.EVENTS.AUCTION_INIT]: ['onAuctionInitEvent'], + [CONSTANTS.EVENTS.AUCTION_END]: ['onAuctionEndEvent', getAdUnitTargeting], + [CONSTANTS.EVENTS.BID_RESPONSE]: ['onBidResponseEvent'], + [CONSTANTS.EVENTS.BID_REQUESTED]: ['onBidRequestEvent'] + }).forEach(([ev, [handler, preprocess]]) => { events.on(ev, (args) => { + preprocess && preprocess(args); subModules.forEach(sm => { try { sm[handler] && sm[handler](args, sm.config, _userConsent) diff --git a/test/spec/modules/realTimeDataModule_spec.js b/test/spec/modules/realTimeDataModule_spec.js index 45559c5bc48..6538dec37c4 100644 --- a/test/spec/modules/realTimeDataModule_spec.js +++ b/test/spec/modules/realTimeDataModule_spec.js @@ -3,6 +3,7 @@ import {config} from 'src/config.js'; import * as sinon from 'sinon'; import {default as CONSTANTS} from '../../../src/constants.json'; import {default as events} from '../../../src/events.js'; +import 'src/prebid.js'; const getBidRequestDataSpy = sinon.spy(); @@ -195,7 +196,7 @@ describe('Real time module', function () { 'name': 'tp1', }, { - 'name': 'tp2' + 'name': 'tp2', } ] } @@ -206,7 +207,7 @@ describe('Real time module', function () { function eventHandlingProvider(name) { const provider = { name: name, - init: () => true + init: () => true, } Object.values(EVENTS).forEach((ev) => provider[ev] = sinon.spy()); return provider; @@ -222,7 +223,19 @@ describe('Real time module', function () { afterEach(() => { _detachers.forEach((d) => d()) config.resetConfig(); - }) + }); + + it('should set targeting for auctionEnd', () => { + providers.forEach(p => p.getTargetingData = sinon.spy()); + const auction = { + adUnitCodes: ['a1'], + adUnits: [{code: 'a1'}] + }; + mockEmitEvent(CONSTANTS.EVENTS.AUCTION_END, auction); + providers.forEach(p => { + expect(p.getTargetingData.calledWith(auction.adUnitCodes)).to.be.true; + }); + }); Object.entries(EVENTS).forEach(([event, hook]) => { it(`'${event}' should be propagated to providers through '${hook}'`, () => {