Skip to content

Commit

Permalink
PAAPI: fix perBuyerSignals + topicsFpdModule: fix exception (prebid#1…
Browse files Browse the repository at this point in the history
…1845)

* fix PAAPI perBuyerSignals

* fix topics exception

* improvement
  • Loading branch information
dgirardi authored Jun 20, 2024
1 parent 77303f4 commit 27a2d3b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 66 deletions.
3 changes: 2 additions & 1 deletion modules/paapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,9 @@ export function addPaapiConfigHook(next, request, paapiConfig) {
const {config, igb} = paapiConfig;
if (config) {
config.auctionSignals = setFPD(config.auctionSignals || {}, request);
const pbs = config.perBuyerSignals = config.perBuyerSignals ?? {};
(config.interestGroupBuyers || []).forEach(buyer => {
deepSetValue(config, `perBuyerSignals.${buyer}`, setFPD(config.perBuyerSignals?.[buyer] || {}, request));
pbs[buyer] = setFPD(pbs[buyer] ?? {}, request);
})
storePendingData(pendingConfigsForAuction, config);
}
Expand Down
2 changes: 1 addition & 1 deletion modules/topicsFpdModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export function processFpd(config, {global}, {data = topicsData} = {}) {
export function getCachedTopics() {
let cachedTopicData = [];
const topics = config.getConfig('userSync.topics');
const bidderList = topics.bidders || [];
const bidderList = topics?.bidders || [];
let storedSegments = new Map(safeJSONParse(coreStorage.getDataFromLocalStorage(topicStorageName)));
storedSegments && storedSegments.forEach((value, cachedBidder) => {
// Check bidder exist in config for cached bidder data and then only retrieve the cached data
Expand Down
10 changes: 5 additions & 5 deletions test/spec/modules/paapi_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ describe('paapi module', () => {
let igb1, igb2, buyerAuctionConfig;
beforeEach(() => {
igb1 = {
origin: 'buyer1'
origin: 'buyer.1'
};
igb2 = {
origin: 'buyer2'
origin: 'buyer.2'
};
buyerAuctionConfig = {
seller: 'seller',
Expand Down Expand Up @@ -263,11 +263,11 @@ describe('paapi module', () => {
});

it('should be added to perBuyerSignals', () => {
auctionConfig.interestGroupBuyers = ['buyer1', 'buyer2'];
auctionConfig.interestGroupBuyers = ['buyer.1', 'buyer.2'];
const pbs = getComponentAuctionConfig().perBuyerSignals;
sinon.assert.match(pbs, {
buyer1: {prebid: {ortb2, ortb2Imp}},
buyer2: {prebid: {ortb2, ortb2Imp}}
'buyer.1': {prebid: {ortb2, ortb2Imp}},
'buyer.2': {prebid: {ortb2, ortb2Imp}}
});
});

Expand Down
102 changes: 43 additions & 59 deletions test/spec/modules/topicsFpdModule_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,33 +308,6 @@ describe('topics', () => {
}],
name: 'ads.pubmatic.com'
}];
const consentString = 'CPi8wgAPi8wgAADABBENCrCsAP_AAH_AAAAAISNB7D==';
const consentConfig = {
consentString: consentString,
gdprApplies: true,
vendorData: {
metadata: consentString,
gdprApplies: true,
purpose: {
consents: {
1: true,
2: true,
3: true,
4: true
}
}
}
};
const mockData = [
{
name: 'domain',
segment: [{id: 123}]
},
{
name: 'domain',
segment: [{id: 321}],
}
];

const evt = {
data: '{"segment":{"domain":"ads.pubmatic.com","topics":[{"configVersion":"chrome.1","modelVersion":"2206021246","taxonomyVersion":"1","topic":165,"version":"chrome.1:1:2206021246"}],"bidder":"pubmatic"},"date":1669743901858}',
Expand All @@ -345,49 +318,60 @@ describe('topics', () => {
storage.removeDataFromLocalStorage(topicStorageName);
});

describe('when cached data is available and not expired', () => {
describe('caching', () => {
let sandbox;
beforeEach(() => {
sandbox = sinon.sandbox.create();
const storedSegments = JSON.stringify(
[['pubmatic', {
'2206021246': {
'ext': {'segtax': 600, 'segclass': '2206021246'},
'segment': [{'id': '243'}, {'id': '265'}],
'name': 'ads.pubmatic.com'
},
'lastUpdated': new Date().getTime()
}]]
);
storage.setDataInLocalStorage(topicStorageName, storedSegments);
config.setConfig({
userSync: {
topics: {
maxTopicCaller: 4,
bidders: [{
bidder: 'pubmatic',
iframeURL: 'https://ads.pubmatic.com/AdServer/js/topics/topics_frame.html'
}]
}
}
})
});
})

afterEach(() => {
sandbox.restore();
config.resetConfig();
});

it('should return segments for bidder if transmitUfpd is allowed', () => {
assert.deepEqual(getCachedTopics(), expected);
});
it('should return no segments when not configured', () => {
config.setConfig({userSync: {}});
expect(getCachedTopics()).to.eql([]);
})

describe('when cached data is available and not expired', () => {
beforeEach(() => {
const storedSegments = JSON.stringify(
[['pubmatic', {
'2206021246': {
'ext': {'segtax': 600, 'segclass': '2206021246'},
'segment': [{'id': '243'}, {'id': '265'}],
'name': 'ads.pubmatic.com'
},
'lastUpdated': new Date().getTime()
}]]
);
storage.setDataInLocalStorage(topicStorageName, storedSegments);
config.setConfig({
userSync: {
topics: {
maxTopicCaller: 4,
bidders: [{
bidder: 'pubmatic',
iframeURL: 'https://ads.pubmatic.com/AdServer/js/topics/topics_frame.html'
}]
}
}
})
});

it('should NOT return segments for bidder if enrichUfpd is NOT allowed', () => {
sandbox.stub(activities, 'isActivityAllowed').callsFake((activity, params) => {
return !(activity === ACTIVITY_ENRICH_UFPD && params.component === 'bidder.pubmatic');
it('should return segments for bidder if transmitUfpd is allowed', () => {
assert.deepEqual(getCachedTopics(), expected);
});

it('should NOT return segments for bidder if enrichUfpd is NOT allowed', () => {
sandbox.stub(activities, 'isActivityAllowed').callsFake((activity, params) => {
return !(activity === ACTIVITY_ENRICH_UFPD && params.component === 'bidder.pubmatic');
});
expect(getCachedTopics()).to.eql([]);
});
expect(getCachedTopics()).to.eql([]);
});
})
});

it('should return empty segments for bidder if there is cached segments stored which is expired', () => {
let storedSegments = '[["pubmatic",{"2206021246":{"ext":{"segtax":600,"segclass":"2206021246"},"segment":[{"id":"243"},{"id":"265"}],"name":"ads.pubmatic.com"},"lastUpdated":10}]]';
Expand Down

0 comments on commit 27a2d3b

Please sign in to comment.