Skip to content

Commit 13886b5

Browse files
dgirardimcallari
authored and
Chris Pabst
committed
RTD module: set targeting on onAuctionEnd event (prebid#7877)
* Adding getAdUnitTargeting to the auctionEnd event. (prebid#7871) * Add test for RTD getAdUnitTargeting Co-authored-by: mcallari <[email protected]>
1 parent 6191728 commit 13886b5

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

modules/rtdModule/index.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,13 @@ const setEventsListeners = (function () {
197197
return function setEventsListeners() {
198198
if (!registered) {
199199
Object.entries({
200-
[CONSTANTS.EVENTS.AUCTION_INIT]: 'onAuctionInitEvent',
201-
[CONSTANTS.EVENTS.AUCTION_END]: 'onAuctionEndEvent',
202-
[CONSTANTS.EVENTS.BID_RESPONSE]: 'onBidResponseEvent',
203-
[CONSTANTS.EVENTS.BID_REQUESTED]: 'onBidRequestEvent'
204-
}).forEach(([ev, handler]) => {
200+
[CONSTANTS.EVENTS.AUCTION_INIT]: ['onAuctionInitEvent'],
201+
[CONSTANTS.EVENTS.AUCTION_END]: ['onAuctionEndEvent', getAdUnitTargeting],
202+
[CONSTANTS.EVENTS.BID_RESPONSE]: ['onBidResponseEvent'],
203+
[CONSTANTS.EVENTS.BID_REQUESTED]: ['onBidRequestEvent']
204+
}).forEach(([ev, [handler, preprocess]]) => {
205205
events.on(ev, (args) => {
206+
preprocess && preprocess(args);
206207
subModules.forEach(sm => {
207208
try {
208209
sm[handler] && sm[handler](args, sm.config, _userConsent)

test/spec/modules/realTimeDataModule_spec.js

+16-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {config} from 'src/config.js';
33
import * as sinon from 'sinon';
44
import {default as CONSTANTS} from '../../../src/constants.json';
55
import {default as events} from '../../../src/events.js';
6+
import 'src/prebid.js';
67

78
const getBidRequestDataSpy = sinon.spy();
89

@@ -195,7 +196,7 @@ describe('Real time module', function () {
195196
'name': 'tp1',
196197
},
197198
{
198-
'name': 'tp2'
199+
'name': 'tp2',
199200
}
200201
]
201202
}
@@ -206,7 +207,7 @@ describe('Real time module', function () {
206207
function eventHandlingProvider(name) {
207208
const provider = {
208209
name: name,
209-
init: () => true
210+
init: () => true,
210211
}
211212
Object.values(EVENTS).forEach((ev) => provider[ev] = sinon.spy());
212213
return provider;
@@ -222,7 +223,19 @@ describe('Real time module', function () {
222223
afterEach(() => {
223224
_detachers.forEach((d) => d())
224225
config.resetConfig();
225-
})
226+
});
227+
228+
it('should set targeting for auctionEnd', () => {
229+
providers.forEach(p => p.getTargetingData = sinon.spy());
230+
const auction = {
231+
adUnitCodes: ['a1'],
232+
adUnits: [{code: 'a1'}]
233+
};
234+
mockEmitEvent(CONSTANTS.EVENTS.AUCTION_END, auction);
235+
providers.forEach(p => {
236+
expect(p.getTargetingData.calledWith(auction.adUnitCodes)).to.be.true;
237+
});
238+
});
226239

227240
Object.entries(EVENTS).forEach(([event, hook]) => {
228241
it(`'${event}' should be propagated to providers through '${hook}'`, () => {

0 commit comments

Comments
 (0)