Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTD module: set targeting on onAuctionEnd event #7877

Merged
merged 3 commits into from
Jan 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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