Skip to content

Commit

Permalink
FPD module: fix bug with fpd enrichment / validation not running on r…
Browse files Browse the repository at this point in the history
…equestBids (prebid#8585)

* FPD module: fix bug with fpd enrichment / validation not running on requestBids

* Fix lint
  • Loading branch information
dgirardi authored and jlaso committed Jul 1, 2022
1 parent 90250c7 commit 0b421b8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
11 changes: 6 additions & 5 deletions modules/fpdModule/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import { module, getHook } from '../../src/hook.js';

let submodules = [];

/**
* enable submodule in User ID
*/
export function registerSubmodules(submodule) {
submodules.push(submodule);
}

export function reset() {
submodules.length = 0;
}

export function processFpd({global = {}, bidder = {}} = {}) {
let modConf = config.getConfig('firstPartyData') || {};

Expand All @@ -26,8 +27,8 @@ export function processFpd({global = {}, bidder = {}} = {}) {
return {global, bidder};
}

function startAuctionHook(fn, req) {
Object.assign(req, processFpd({global: req.ortb2, bidder: req.bidderOrtb2}));
export function startAuctionHook(fn, req) {
Object.assign(req.ortb2Fragments, processFpd(req.ortb2Fragments));
fn.call(this, req);
}

Expand Down
29 changes: 28 additions & 1 deletion test/spec/modules/fpdModule_spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {expect} from 'chai';
import {config} from 'src/config.js';
import {getRefererInfo} from 'src/refererDetection.js';
import {processFpd, registerSubmodules} from 'modules/fpdModule/index.js';
import {processFpd, registerSubmodules, startAuctionHook, reset} from 'modules/fpdModule/index.js';
import * as enrichmentModule from 'modules/enrichmentFpdModule.js';
import * as validationModule from 'modules/validationFpdModule/index.js';

Expand All @@ -13,6 +13,29 @@ describe('the first party data module', function () {
config.resetConfig();
});

describe('startAuctionHook', () => {
const mockFpd = {
global: {key: 'value'},
bidder: {A: {bkey: 'bvalue'}}
}
before(() => {
reset();
registerSubmodules({
name: 'test',
queue: 2,
processFpd: function () {
return mockFpd;
}
});
})

it('should run ortb2Fragments through fpd submodules', () => {
const req = {ortb2Fragments: {}};
startAuctionHook(() => null, req);
expect(req.ortb2Fragments).to.eql(mockFpd);
});
});

describe('first party data intitializing', function () {
let width;
let widthStub;
Expand All @@ -23,6 +46,10 @@ describe('the first party data module', function () {
let keywords;

before(function() {
reset();
registerSubmodules(enrichmentModule);
registerSubmodules(validationModule);

canonical = document.createElement('link');
canonical.rel = 'canonical';
keywords = document.createElement('meta');
Expand Down

0 comments on commit 0b421b8

Please sign in to comment.