Skip to content

Commit

Permalink
RTD module: set targeting on onAuctionEnd event (prebid#7877)
Browse files Browse the repository at this point in the history
* Adding getAdUnitTargeting to the auctionEnd event. (prebid#7871)

* Add test for RTD getAdUnitTargeting

Co-authored-by: mcallari <mike.callari@gmail.com>
  • Loading branch information
dgirardi and mcallari authored Jan 3, 2022
1 parent 57fc865 commit 5311e17
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
11 changes: 6 additions & 5 deletions modules/rtdModule/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 16 additions & 3 deletions test/spec/modules/realTimeDataModule_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -195,7 +196,7 @@ describe('Real time module', function () {
'name': 'tp1',
},
{
'name': 'tp2'
'name': 'tp2',
}
]
}
Expand All @@ -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;
Expand All @@ -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}'`, () => {
Expand Down

0 comments on commit 5311e17

Please sign in to comment.