From 42ee8fa32376f5f8c43a54a12540440c5d9629e0 Mon Sep 17 00:00:00 2001 From: Demetrio Girardi Date: Tue, 21 Jun 2022 12:40:10 -0700 Subject: [PATCH] FPD module: fix bug with fpd enrichment / validation not running on requestBids (#8585) * FPD module: fix bug with fpd enrichment / validation not running on requestBids * Fix lint --- modules/fpdModule/index.js | 11 ++++++----- test/spec/modules/fpdModule_spec.js | 29 ++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/modules/fpdModule/index.js b/modules/fpdModule/index.js index aa658a5be4cc..bd735e215a40 100644 --- a/modules/fpdModule/index.js +++ b/modules/fpdModule/index.js @@ -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') || {}; @@ -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); } diff --git a/test/spec/modules/fpdModule_spec.js b/test/spec/modules/fpdModule_spec.js index cedfd22a5d7e..d43ae8309bd8 100644 --- a/test/spec/modules/fpdModule_spec.js +++ b/test/spec/modules/fpdModule_spec.js @@ -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'; @@ -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; @@ -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');