@@ -5,9 +5,6 @@ import {processFpd, registerSubmodules, startAuctionHook, reset} from 'modules/f
5
5
import * as enrichmentModule from 'modules/enrichmentFpdModule.js' ;
6
6
import * as validationModule from 'modules/validationFpdModule/index.js' ;
7
7
8
- let enrichments = { ...enrichmentModule } ;
9
- let validations = { ...validationModule } ;
10
-
11
8
describe ( 'the first party data module' , function ( ) {
12
9
afterEach ( function ( ) {
13
10
config . resetConfig ( ) ;
@@ -18,21 +15,37 @@ describe('the first party data module', function () {
18
15
global : { key : 'value' } ,
19
16
bidder : { A : { bkey : 'bvalue' } }
20
17
}
21
- before ( ( ) => {
18
+ beforeEach ( ( ) => {
22
19
reset ( ) ;
20
+ } ) ;
21
+
22
+ it ( 'should run ortb2Fragments through fpd submodules' , ( ) => {
23
23
registerSubmodules ( {
24
24
name : 'test' ,
25
- queue : 2 ,
26
25
processFpd : function ( ) {
27
26
return mockFpd ;
28
27
}
29
28
} ) ;
30
- } )
29
+ const req = { ortb2Fragments : { } } ;
30
+ return new Promise ( ( resolve ) => startAuctionHook ( resolve , req ) )
31
+ . then ( ( ) => {
32
+ expect ( req . ortb2Fragments ) . to . eql ( mockFpd ) ;
33
+ } )
34
+ } ) ;
31
35
32
- it ( 'should run ortb2Fragments through fpd submodules' , ( ) => {
36
+ it ( 'should work with fpd submodules that return promises' , ( ) => {
37
+ registerSubmodules ( {
38
+ name : 'test' ,
39
+ processFpd : function ( ) {
40
+ return Promise . resolve ( mockFpd ) ;
41
+ }
42
+ } ) ;
33
43
const req = { ortb2Fragments : { } } ;
34
- startAuctionHook ( ( ) => null , req ) ;
35
- expect ( req . ortb2Fragments ) . to . eql ( mockFpd ) ;
44
+ return new Promise ( ( resolve ) => {
45
+ startAuctionHook ( resolve , req ) ;
46
+ } ) . then ( ( ) => {
47
+ expect ( req . ortb2Fragments ) . to . eql ( mockFpd ) ;
48
+ } ) ;
36
49
} ) ;
37
50
} ) ;
38
51
@@ -79,7 +92,6 @@ describe('the first party data module', function () {
79
92
} ) ;
80
93
81
94
it ( 'filters ortb2 data that is set' , function ( ) {
82
- let validated ;
83
95
const global = {
84
96
user : {
85
97
data : { } ,
@@ -113,42 +125,42 @@ describe('the first party data module', function () {
113
125
width = 1120 ;
114
126
height = 750 ;
115
127
116
- ( { global : validated } = processFpd ( { global} ) ) ;
117
- expect ( validated . site . ref ) . to . equal ( getRefererInfo ( ) . ref || undefined ) ;
118
- expect ( validated . site . page ) . to . equal ( 'https://www.domain.com/path?query=12345' ) ;
119
- expect ( validated . site . domain ) . to . equal ( 'domain.com' ) ;
120
- expect ( validated . site . content . data ) . to . deep . equal ( [ { segment : [ { id : 'test' } ] , name : 'bar' } ] ) ;
121
- expect ( validated . user . data ) . to . be . undefined ;
122
- expect ( validated . device ) . to . deep . to . equal ( { w : 1 , h : 1 } ) ;
123
- expect ( validated . site . keywords ) . to . be . undefined ;
128
+ return processFpd ( { global} ) . then ( ( { global : validated } ) => {
129
+ expect ( validated . site . ref ) . to . equal ( getRefererInfo ( ) . ref || undefined ) ;
130
+ expect ( validated . site . page ) . to . equal ( 'https://www.domain.com/path?query=12345' ) ;
131
+ expect ( validated . site . domain ) . to . equal ( 'domain.com' ) ;
132
+ expect ( validated . site . content . data ) . to . deep . equal ( [ { segment : [ { id : 'test' } ] , name : 'bar' } ] ) ;
133
+ expect ( validated . user . data ) . to . be . undefined ;
134
+ expect ( validated . device ) . to . deep . to . equal ( { w : 1 , h : 1 } ) ;
135
+ expect ( validated . site . keywords ) . to . be . undefined ;
136
+ } ) ;
124
137
} ) ;
125
138
126
139
it ( 'should not overwrite existing data with default settings' , function ( ) {
127
- let validated ;
128
140
const global = {
129
141
site : {
130
142
ref : 'https://referer.com'
131
143
}
132
144
} ;
133
145
134
- ( { global : validated } = processFpd ( { global} ) ) ;
135
- expect ( validated . site . ref ) . to . equal ( 'https://referer.com' ) ;
146
+ return processFpd ( { global} ) . then ( ( { global : validated } ) => {
147
+ expect ( validated . site . ref ) . to . equal ( 'https://referer.com' ) ;
148
+ } ) ;
136
149
} ) ;
137
150
138
151
it ( 'should allow overwrite default data with setConfig' , function ( ) {
139
- let validated ;
140
152
const global = {
141
153
site : {
142
154
ref : 'https://referer.com'
143
155
}
144
156
} ;
145
157
146
- ( { global : validated } = processFpd ( { global} ) ) ;
147
- expect ( validated . site . ref ) . to . equal ( 'https://referer.com' ) ;
158
+ return processFpd ( { global} ) . then ( ( { global : validated } ) => {
159
+ expect ( validated . site . ref ) . to . equal ( 'https://referer.com' ) ;
160
+ } ) ;
148
161
} ) ;
149
162
150
163
it ( 'should filter all data' , function ( ) {
151
- let validated ;
152
164
let global = {
153
165
imp : [ ] ,
154
166
site : {
@@ -179,15 +191,13 @@ describe('the first party data module', function () {
179
191
adServerCurrency : 'USD'
180
192
}
181
193
} ;
182
-
183
194
config . setConfig ( { 'firstPartyData' : { skipEnrichments : true } } ) ;
184
-
185
- ( { global : validated } = processFpd ( { global } ) ) ;
186
- expect ( validated ) . to . deep . equal ( { } ) ;
195
+ return processFpd ( { global } ) . then ( ( { global : validated } ) => {
196
+ expect ( validated ) . to . deep . equal ( { } ) ;
197
+ } ) ;
187
198
} ) ;
188
199
189
200
it ( 'should add enrichments but not alter any arbitrary ortb2 data' , function ( ) {
190
- let validated ;
191
201
let global = {
192
202
site : {
193
203
ext : {
@@ -205,12 +215,12 @@ describe('the first party data module', function () {
205
215
} ,
206
216
cur : [ 'USD' ]
207
217
} ;
208
-
209
- ( { global : validated } = processFpd ( { global } ) ) ;
210
- expect ( validated . site . ref ) . to . equal ( getRefererInfo ( ) . referer ) ;
211
- expect ( validated . site . ext . data ) . to . deep . equal ( { inventory : [ 'value1 ' ] } ) ;
212
- expect ( validated . user . ext . data ) . to . deep . equal ( { visitor : [ 'value2' ] } ) ;
213
- expect ( validated . cur ) . to . deep . equal ( [ 'USD' ] ) ;
218
+ return processFpd ( { global } ) . then ( ( { global : validated } ) => {
219
+ expect ( validated . site . ref ) . to . equal ( getRefererInfo ( ) . referer ) ;
220
+ expect ( validated . site . ext . data ) . to . deep . equal ( { inventory : [ 'value1' ] } ) ;
221
+ expect ( validated . user . ext . data ) . to . deep . equal ( { visitor : [ 'value2 ' ] } ) ;
222
+ expect ( validated . cur ) . to . deep . equal ( [ 'USD' ] ) ;
223
+ } )
214
224
} ) ;
215
225
216
226
it ( 'should filter bidderConfig data' , function ( ) {
@@ -230,12 +240,13 @@ describe('the first party data module', function () {
230
240
}
231
241
} ;
232
242
233
- const { bidder : validated } = processFpd ( { bidder} ) ;
234
- expect ( validated . bidderA ) . to . not . be . undefined ;
235
- expect ( validated . bidderA . user . data ) . to . be . undefined ;
236
- expect ( validated . bidderA . user . keywords ) . to . equal ( 'test' ) ;
237
- expect ( validated . bidderA . site . keywords ) . to . equal ( 'other' ) ;
238
- expect ( validated . bidderA . site . ref ) . to . equal ( 'https://domain.com' ) ;
243
+ return processFpd ( { bidder} ) . then ( ( { bidder : validated } ) => {
244
+ expect ( validated . bidderA ) . to . not . be . undefined ;
245
+ expect ( validated . bidderA . user . data ) . to . be . undefined ;
246
+ expect ( validated . bidderA . user . keywords ) . to . equal ( 'test' ) ;
247
+ expect ( validated . bidderA . site . keywords ) . to . equal ( 'other' ) ;
248
+ expect ( validated . bidderA . site . ref ) . to . equal ( 'https://domain.com' ) ;
249
+ } )
239
250
} ) ;
240
251
241
252
it ( 'should not filter bidderConfig data as it is valid' , function ( ) {
@@ -255,17 +266,16 @@ describe('the first party data module', function () {
255
266
}
256
267
} ;
257
268
258
- const { bidder : validated } = processFpd ( { bidder } ) ;
259
-
260
- expect ( validated . bidderA ) . to . not . be . undefined ;
261
- expect ( validated . bidderA . user . data ) . to . deep . equal ( [ { segment : [ { id : 'data1_id' } ] , name : 'data1' } ] ) ;
262
- expect ( validated . bidderA . user . keywords ) . to . equal ( 'test ' ) ;
263
- expect ( validated . bidderA . site . keywords ) . to . equal ( 'other ' ) ;
264
- expect ( validated . bidderA . site . ref ) . to . equal ( 'https://domain.com' ) ;
269
+ return processFpd ( { bidder} ) . then ( ( { bidder : validated } ) => {
270
+ expect ( validated . bidderA ) . to . not . be . undefined ;
271
+ expect ( validated . bidderA . user . data ) . to . deep . equal ( [ { segment : [ { id : 'data1_id' } ] , name : 'data1' } ] ) ;
272
+ expect ( validated . bidderA . user . keywords ) . to . equal ( 'test' ) ;
273
+ expect ( validated . bidderA . site . keywords ) . to . equal ( 'other ' ) ;
274
+ expect ( validated . bidderA . site . ref ) . to . equal ( 'https://domain.com ' ) ;
275
+ } ) ;
265
276
} ) ;
266
277
267
278
it ( 'should not set default values if skipEnrichments is turned on' , function ( ) {
268
- let validated ;
269
279
config . setConfig ( { 'firstPartyData' : { skipEnrichments : true } } ) ;
270
280
271
281
let global = {
@@ -281,15 +291,15 @@ describe('the first party data module', function () {
281
291
}
282
292
} ;
283
293
284
- ( { global : validated } = processFpd ( { global} ) ) ;
285
- expect ( validated . device ) . to . be . undefined ;
286
- expect ( validated . site . ref ) . to . be . undefined ;
287
- expect ( validated . site . page ) . to . be . undefined ;
288
- expect ( validated . site . domain ) . to . be . undefined ;
294
+ return processFpd ( { global} ) . then ( ( { global : validated } ) => {
295
+ expect ( validated . device ) . to . be . undefined ;
296
+ expect ( validated . site . ref ) . to . be . undefined ;
297
+ expect ( validated . site . page ) . to . be . undefined ;
298
+ expect ( validated . site . domain ) . to . be . undefined ;
299
+ } ) ;
289
300
} ) ;
290
301
291
302
it ( 'should not validate ortb2 data if skipValidations is turned on' , function ( ) {
292
- let validated ;
293
303
config . setConfig ( { 'firstPartyData' : { skipValidations : true } } ) ;
294
304
295
305
let global = {
@@ -304,8 +314,9 @@ describe('the first party data module', function () {
304
314
}
305
315
} ;
306
316
307
- ( { global : validated } = processFpd ( { global} ) ) ;
308
- expect ( validated . user . data ) . to . deep . equal ( [ { segment : [ { id : 'nonfiltered' } ] } ] ) ;
317
+ return processFpd ( { global} ) . then ( ( { global : validated } ) => {
318
+ expect ( validated . user . data ) . to . deep . equal ( [ { segment : [ { id : 'nonfiltered' } ] } ] ) ;
319
+ } ) ;
309
320
} ) ;
310
321
} ) ;
311
322
} ) ;
0 commit comments