prebid.js 6.7.0 → 6.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. package/.eslintrc.js +8 -1
  2. package/integrationExamples/gpt/{haloRtdProvider_example.html → hadronRtdProvider_example.html} +9 -9
  3. package/integrationExamples/gpt/idImportLibrary_example.html +2 -2
  4. package/integrationExamples/gpt/userId_example.html +2 -2
  5. package/integrationExamples/gpt/weboramaRtdProvider_example.html +154 -115
  6. package/integrationExamples/gpt/x-domain/creative.html +63 -29
  7. package/modules/.submodules.json +3 -0
  8. package/modules/adagioBidAdapter.js +0 -8
  9. package/modules/adagioBidAdapter.md +1 -1
  10. package/modules/adkernelBidAdapter.js +2 -1
  11. package/modules/adnuntiusRtdProvider.js +96 -0
  12. package/modules/adnuntiusRtdProvider.md +41 -0
  13. package/modules/adotBidAdapter.js +516 -567
  14. package/modules/adotBidAdapter.md +6 -44
  15. package/modules/adpod.js +12 -14
  16. package/modules/adyoulikeBidAdapter.js +2 -0
  17. package/modules/appnexusBidAdapter.js +14 -2
  18. package/modules/asealBidAdapter.js +58 -0
  19. package/modules/asealBidAdapter.md +52 -0
  20. package/modules/brandmetricsRtdProvider.js +168 -0
  21. package/modules/brandmetricsRtdProvider.md +40 -0
  22. package/modules/conversantBidAdapter.js +7 -0
  23. package/modules/criteoBidAdapter.js +9 -0
  24. package/modules/currency.js +27 -5
  25. package/modules/displayioBidAdapter.js +157 -0
  26. package/modules/displayioBidAdapter.md +148 -0
  27. package/modules/dspxBidAdapter.js +69 -29
  28. package/modules/dspxBidAdapter.md +2 -1
  29. package/modules/e_volutionBidAdapter.js +158 -0
  30. package/modules/gridBidAdapter.js +15 -1
  31. package/modules/gumgumBidAdapter.js +52 -38
  32. package/modules/hadronIdSystem.js +96 -0
  33. package/modules/hadronIdSystem.md +35 -0
  34. package/modules/hadronRtdProvider.js +254 -0
  35. package/modules/hadronRtdProvider.md +126 -0
  36. package/modules/haloIdSystem.md +4 -35
  37. package/modules/haloRtdProvider.md +3 -126
  38. package/modules/imRtdProvider.js +10 -0
  39. package/modules/improvedigitalBidAdapter.js +5 -0
  40. package/modules/interactiveOffersBidAdapter.js +9 -6
  41. package/modules/iqzoneBidAdapter.js +10 -3
  42. package/modules/iqzoneBidAdapter.md +16 -0
  43. package/modules/ixBidAdapter.js +2 -6
  44. package/modules/kubientBidAdapter.js +50 -19
  45. package/modules/lunamediahbBidAdapter.js +32 -4
  46. package/modules/malltvBidAdapter.js +7 -3
  47. package/modules/malltvBidAdapter.md +64 -51
  48. package/modules/mass.js +3 -5
  49. package/modules/mediakeysBidAdapter.js +0 -5
  50. package/modules/medianetAnalyticsAdapter.js +1 -1
  51. package/modules/mediasquareBidAdapter.js +9 -1
  52. package/modules/nextMillenniumBidAdapter.js +1 -0
  53. package/modules/oguryBidAdapter.js +7 -14
  54. package/modules/prebidServerBidAdapter/index.js +61 -39
  55. package/modules/priceFloors.js +20 -12
  56. package/modules/pubmaticBidAdapter.js +1 -1
  57. package/modules/richaudienceBidAdapter.js +8 -3
  58. package/modules/riseBidAdapter.js +17 -6
  59. package/modules/rtbhouseBidAdapter.js +2 -0
  60. package/modules/rubiconAnalyticsAdapter.js +5 -0
  61. package/modules/rubiconBidAdapter.js +2 -2
  62. package/modules/sizeMappingV2.js +1 -8
  63. package/modules/sortableAnalyticsAdapter.js +5 -4
  64. package/modules/sovrnBidAdapter.js +93 -18
  65. package/modules/sovrnBidAdapter.md +80 -2
  66. package/modules/sspBCBidAdapter.js +53 -20
  67. package/modules/telariaBidAdapter.js +22 -29
  68. package/modules/trustpidSystem.js +197 -0
  69. package/modules/trustpidSystem.md +45 -0
  70. package/modules/undertoneBidAdapter.js +17 -1
  71. package/modules/userId/eids.js +16 -1
  72. package/modules/userId/eids.md +10 -2
  73. package/modules/userId/userId.md +17 -2
  74. package/modules/vibrantmediaBidAdapter.js +220 -0
  75. package/modules/vibrantmediaBidAdapter.md +92 -0
  76. package/modules/vidoomyBidAdapter.js +8 -0
  77. package/modules/vidoomyBidAdapter.md +4 -2
  78. package/modules/weboramaRtdProvider.js +264 -34
  79. package/modules/weboramaRtdProvider.md +110 -40
  80. package/modules/yahoosspBidAdapter.js +3 -1
  81. package/modules/yieldoneBidAdapter.js +6 -0
  82. package/package.json +2 -1
  83. package/src/adRendering.js +38 -0
  84. package/src/adapterManager.js +24 -19
  85. package/src/adapters/bidderFactory.js +14 -11
  86. package/src/adloader.js +2 -1
  87. package/src/auction.js +138 -115
  88. package/src/auctionIndex.js +85 -0
  89. package/src/auctionManager.js +3 -0
  90. package/src/bidderSettings.js +69 -0
  91. package/src/bidfactory.js +18 -6
  92. package/src/native.js +29 -21
  93. package/src/prebid.js +3 -19
  94. package/src/secureCreatives.js +128 -45
  95. package/src/targeting.js +11 -2
  96. package/src/utils.js +14 -17
  97. package/src/video.js +10 -11
  98. package/src/videoCache.js +10 -9
  99. package/test/fixtures/fixtures.js +2 -1
  100. package/test/helpers/indexStub.js +28 -0
  101. package/test/helpers/syncPromise.js +71 -0
  102. package/test/spec/auctionmanager_spec.js +268 -89
  103. package/test/spec/config_spec.js +24 -1
  104. package/test/spec/modules/adagioBidAdapter_spec.js +0 -10
  105. package/test/spec/modules/adnuntiusRtdProvider_spec.js +145 -0
  106. package/test/spec/modules/adotBidAdapter_spec.js +294 -3124
  107. package/test/spec/modules/adpod_spec.js +91 -156
  108. package/test/spec/modules/adyoulikeBidAdapter_spec.js +4 -0
  109. package/test/spec/modules/appnexusBidAdapter_spec.js +27 -0
  110. package/test/spec/modules/asealBidAdapter_spec.js +144 -0
  111. package/test/spec/modules/brandmetricsRtdProvider_spec.js +191 -0
  112. package/test/spec/modules/conversantBidAdapter_spec.js +54 -2
  113. package/test/spec/modules/criteoBidAdapter_spec.js +21 -0
  114. package/test/spec/modules/currency_spec.js +36 -15
  115. package/test/spec/modules/displayioBidAdapter_spec.js +239 -0
  116. package/test/spec/modules/dspxBidAdapter_spec.js +20 -15
  117. package/test/spec/modules/e_volutionBidAdapter_spec.js +242 -0
  118. package/test/spec/modules/eids_spec.js +2 -2
  119. package/test/spec/modules/gridBidAdapter_spec.js +18 -0
  120. package/test/spec/modules/gumgumBidAdapter_spec.js +49 -3
  121. package/test/spec/modules/hadronIdSystem_spec.js +57 -0
  122. package/test/spec/modules/hadronRtdProvider_spec.js +762 -0
  123. package/test/spec/modules/imRtdProvider_spec.js +30 -1
  124. package/test/spec/modules/improvedigitalBidAdapter_spec.js +19 -0
  125. package/test/spec/modules/iqzoneBidAdapter_spec.js +1 -0
  126. package/test/spec/modules/ixBidAdapter_spec.js +1 -1
  127. package/test/spec/modules/kubientBidAdapter_spec.js +182 -84
  128. package/test/spec/modules/lunamediahbBidAdapter_spec.js +27 -1
  129. package/test/spec/modules/mass_spec.js +2 -14
  130. package/test/spec/modules/mediakeysBidAdapter_spec.js +9 -5
  131. package/test/spec/modules/mediasquareBidAdapter_spec.js +25 -1
  132. package/test/spec/modules/oguryBidAdapter_spec.js +63 -5
  133. package/test/spec/modules/prebidServerBidAdapter_spec.js +43 -6
  134. package/test/spec/modules/priceFloors_spec.js +83 -24
  135. package/test/spec/modules/pubmaticBidAdapter_spec.js +40 -0
  136. package/test/spec/modules/riseBidAdapter_spec.js +30 -4
  137. package/test/spec/modules/rubiconAnalyticsAdapter_spec.js +31 -1
  138. package/test/spec/modules/rubiconBidAdapter_spec.js +1 -1
  139. package/test/spec/modules/sortableAnalyticsAdapter_spec.js +2 -3
  140. package/test/spec/modules/sovrnBidAdapter_spec.js +413 -333
  141. package/test/spec/modules/sspBCBidAdapter_spec.js +7 -7
  142. package/test/spec/modules/telariaBidAdapter_spec.js +1 -3
  143. package/test/spec/modules/trustpidSystem_spec.js +232 -0
  144. package/test/spec/modules/undertoneBidAdapter_spec.js +55 -2
  145. package/test/spec/modules/userId_spec.js +39 -39
  146. package/test/spec/modules/vibrantmediaBidAdapter_spec.js +1237 -0
  147. package/test/spec/modules/vidoomyBidAdapter_spec.js +7 -1
  148. package/test/spec/modules/weboramaRtdProvider_spec.js +536 -20
  149. package/test/spec/modules/yahoosspBidAdapter_spec.js +10 -0
  150. package/test/spec/modules/yieldoneBidAdapter_spec.js +33 -0
  151. package/test/spec/native_spec.js +62 -40
  152. package/test/spec/unit/core/adapterManager_spec.js +22 -0
  153. package/test/spec/unit/core/auctionIndex_spec.js +129 -0
  154. package/test/spec/unit/core/bidderFactory_spec.js +65 -12
  155. package/test/spec/unit/core/bidderSettings_spec.js +123 -0
  156. package/test/spec/unit/core/targeting_spec.js +93 -0
  157. package/test/spec/unit/pbjs_api_spec.js +80 -42
  158. package/test/spec/unit/secureCreatives_spec.js +143 -24
  159. package/test/spec/videoCache_spec.js +18 -19
  160. package/test/spec/video_spec.js +51 -61
@@ -177,6 +177,16 @@ describe('YahooSSP Bid Adapter:', () => {
177
177
  expect(obj).to.be.an('object');
178
178
  });
179
179
 
180
+ describe('Validate basic properties', () => {
181
+ it('should define the correct bidder code', () => {
182
+ expect(spec.code).to.equal('yahoossp')
183
+ });
184
+
185
+ it('should define the correct vendor ID', () => {
186
+ expect(spec.gvlid).to.equal(25)
187
+ });
188
+ });
189
+
180
190
  describe('getUserSyncs()', () => {
181
191
  const IMAGE_PIXEL_URL = 'http://image-pixel.com/foo/bar?1234&baz=true';
182
192
  const IFRAME_ONE_URL = 'http://image-iframe.com/foo/bar?1234&baz=true';
@@ -366,6 +366,39 @@ describe('yieldoneBidAdapter', function() {
366
366
  expect(request[0].data.lr_env).to.equal('idl_env_sample');
367
367
  });
368
368
  });
369
+
370
+ describe('IMID', function () {
371
+ it('dont send IMID if undefined', function () {
372
+ const bidRequests = [
373
+ {
374
+ params: {placementId: '0'},
375
+ },
376
+ {
377
+ params: {placementId: '1'},
378
+ userId: {},
379
+ },
380
+ {
381
+ params: {placementId: '2'},
382
+ userId: undefined,
383
+ },
384
+ ];
385
+ const request = spec.buildRequests(bidRequests, bidderRequest);
386
+ expect(request[0].data).to.not.have.property('imuid');
387
+ expect(request[1].data).to.not.have.property('imuid');
388
+ expect(request[2].data).to.not.have.property('imuid');
389
+ });
390
+
391
+ it('should send IMID if available', function () {
392
+ const bidRequests = [
393
+ {
394
+ params: {placementId: '0'},
395
+ userId: {imuid: 'imuid_sample'},
396
+ },
397
+ ];
398
+ const request = spec.buildRequests(bidRequests, bidderRequest);
399
+ expect(request[0].data.imuid).to.equal('imuid_sample');
400
+ });
401
+ });
369
402
  });
370
403
 
371
404
  describe('interpretResponse', function () {
@@ -1,10 +1,19 @@
1
1
  import { expect } from 'chai';
2
- import { fireNativeTrackers, getNativeTargeting, nativeBidIsValid, getAssetMessage, getAllAssetsMessage } from 'src/native.js';
2
+ import {
3
+ fireNativeTrackers,
4
+ getNativeTargeting,
5
+ nativeBidIsValid,
6
+ getAssetMessage,
7
+ getAllAssetsMessage,
8
+ decorateAdUnitsWithNativeParams
9
+ } from 'src/native.js';
3
10
  import CONSTANTS from 'src/constants.json';
11
+ import {stubAuctionIndex} from '../helpers/indexStub.js';
4
12
  const utils = require('src/utils');
5
13
 
6
14
  const bid = {
7
15
  adId: '123',
16
+ transactionId: 'au',
8
17
  native: {
9
18
  title: 'Native Creative',
10
19
  body: 'Cool description great stuff',
@@ -32,6 +41,7 @@ const bid = {
32
41
  };
33
42
 
34
43
  const bidWithUndefinedFields = {
44
+ transactionId: 'au',
35
45
  native: {
36
46
  title: 'Native Creative',
37
47
  body: undefined,
@@ -52,6 +62,10 @@ describe('native.js', function () {
52
62
  let triggerPixelStub;
53
63
  let insertHtmlIntoIframeStub;
54
64
 
65
+ function deps(adUnit) {
66
+ return { index: stubAuctionIndex({ adUnits: [adUnit] }) };
67
+ }
68
+
55
69
  beforeEach(function () {
56
70
  triggerPixelStub = sinon.stub(utils, 'triggerPixel');
57
71
  insertHtmlIntoIframeStub = sinon.stub(utils, 'insertHtmlIntoIframe');
@@ -71,7 +85,8 @@ describe('native.js', function () {
71
85
  });
72
86
 
73
87
  it('sends placeholders for configured assets', function () {
74
- const bidRequest = {
88
+ const adUnit = {
89
+ transactionId: 'au',
75
90
  nativeParams: {
76
91
  body: { sendId: true },
77
92
  clickUrl: { sendId: true },
@@ -85,7 +100,7 @@ describe('native.js', function () {
85
100
  }
86
101
  }
87
102
  };
88
- const targeting = getNativeTargeting(bid, bidRequest);
103
+ const targeting = getNativeTargeting(bid, deps(adUnit));
89
104
 
90
105
  expect(targeting[CONSTANTS.NATIVE_KEYS.title]).to.equal(bid.native.title);
91
106
  expect(targeting[CONSTANTS.NATIVE_KEYS.body]).to.equal('hb_native_body:123');
@@ -95,7 +110,8 @@ describe('native.js', function () {
95
110
  });
96
111
 
97
112
  it('should only include native targeting keys with values', function () {
98
- const bidRequest = {
113
+ const adUnit = {
114
+ transactionId: 'au',
99
115
  nativeParams: {
100
116
  body: { sendId: true },
101
117
  clickUrl: { sendId: true },
@@ -110,7 +126,7 @@ describe('native.js', function () {
110
126
  }
111
127
  };
112
128
 
113
- const targeting = getNativeTargeting(bidWithUndefinedFields, bidRequest);
129
+ const targeting = getNativeTargeting(bidWithUndefinedFields, deps(adUnit));
114
130
 
115
131
  expect(Object.keys(targeting)).to.deep.equal([
116
132
  CONSTANTS.NATIVE_KEYS.title,
@@ -121,7 +137,8 @@ describe('native.js', function () {
121
137
  });
122
138
 
123
139
  it('should only include targeting that has sendTargetingKeys set to true', function () {
124
- const bidRequest = {
140
+ const adUnit = {
141
+ transactionId: 'au',
125
142
  nativeParams: {
126
143
  image: {
127
144
  required: true,
@@ -136,7 +153,7 @@ describe('native.js', function () {
136
153
  }
137
154
 
138
155
  };
139
- const targeting = getNativeTargeting(bid, bidRequest);
156
+ const targeting = getNativeTargeting(bid, deps(adUnit));
140
157
 
141
158
  expect(Object.keys(targeting)).to.deep.equal([
142
159
  CONSTANTS.NATIVE_KEYS.title
@@ -144,7 +161,8 @@ describe('native.js', function () {
144
161
  });
145
162
 
146
163
  it('should only include targeting if sendTargetingKeys not set to false', function () {
147
- const bidRequest = {
164
+ const adUnit = {
165
+ transactionId: 'au',
148
166
  nativeParams: {
149
167
  image: {
150
168
  required: true,
@@ -181,7 +199,7 @@ describe('native.js', function () {
181
199
  }
182
200
 
183
201
  };
184
- const targeting = getNativeTargeting(bid, bidRequest);
202
+ const targeting = getNativeTargeting(bid, deps(adUnit));
185
203
 
186
204
  expect(Object.keys(targeting)).to.deep.equal([
187
205
  CONSTANTS.NATIVE_KEYS.title,
@@ -193,7 +211,8 @@ describe('native.js', function () {
193
211
  });
194
212
 
195
213
  it('should copy over rendererUrl to bid object and include it in targeting', function () {
196
- const bidRequest = {
214
+ const adUnit = {
215
+ transactionId: 'au',
197
216
  nativeParams: {
198
217
  image: {
199
218
  required: true,
@@ -209,7 +228,7 @@ describe('native.js', function () {
209
228
  }
210
229
 
211
230
  };
212
- const targeting = getNativeTargeting(bid, bidRequest);
231
+ const targeting = getNativeTargeting(bid, deps(adUnit));
213
232
 
214
233
  expect(Object.keys(targeting)).to.deep.equal([
215
234
  CONSTANTS.NATIVE_KEYS.title,
@@ -227,7 +246,8 @@ describe('native.js', function () {
227
246
  });
228
247
 
229
248
  it('should copy over adTemplate to bid object and include it in targeting', function () {
230
- const bidRequest = {
249
+ const adUnit = {
250
+ transactionId: 'au',
231
251
  nativeParams: {
232
252
  image: {
233
253
  required: true,
@@ -241,7 +261,7 @@ describe('native.js', function () {
241
261
  }
242
262
 
243
263
  };
244
- const targeting = getNativeTargeting(bid, bidRequest);
264
+ const targeting = getNativeTargeting(bid, deps(adUnit));
245
265
 
246
266
  expect(Object.keys(targeting)).to.deep.equal([
247
267
  CONSTANTS.NATIVE_KEYS.title,
@@ -374,35 +394,33 @@ describe('native.js', function () {
374
394
  });
375
395
 
376
396
  describe('validate native', function () {
377
- let bidReq = [{
378
- bids: [{
379
- bidderCode: 'test_bidder',
380
- bidId: 'test_bid_id',
381
- mediaTypes: {
382
- native: {
383
- title: {
384
- required: true,
385
- },
386
- body: {
387
- required: true,
388
- },
389
- image: {
390
- required: true,
391
- sizes: [150, 50],
392
- aspect_ratios: [150, 50]
393
- },
394
- icon: {
395
- required: true,
396
- sizes: [50, 50]
397
- },
398
- }
397
+ const adUnit = {
398
+ transactionId: 'test_adunit',
399
+ mediaTypes: {
400
+ native: {
401
+ title: {
402
+ required: true,
403
+ },
404
+ body: {
405
+ required: true,
406
+ },
407
+ image: {
408
+ required: true,
409
+ sizes: [150, 50],
410
+ aspect_ratios: [150, 50]
411
+ },
412
+ icon: {
413
+ required: true,
414
+ sizes: [50, 50]
415
+ },
399
416
  }
400
- }]
401
- }];
417
+ }
418
+ }
402
419
 
403
420
  let validBid = {
404
421
  adId: 'abc123',
405
422
  requestId: 'test_bid_id',
423
+ transactionId: 'test_adunit',
406
424
  adUnitCode: '123/prebid_native_adunit',
407
425
  bidder: 'test_bidder',
408
426
  native: {
@@ -428,6 +446,7 @@ describe('validate native', function () {
428
446
  let noIconDimBid = {
429
447
  adId: 'abc234',
430
448
  requestId: 'test_bid_id',
449
+ transactionId: 'test_adunit',
431
450
  adUnitCode: '123/prebid_native_adunit',
432
451
  bidder: 'test_bidder',
433
452
  native: {
@@ -449,6 +468,7 @@ describe('validate native', function () {
449
468
  let noImgDimBid = {
450
469
  adId: 'abc345',
451
470
  requestId: 'test_bid_id',
471
+ transactionId: 'test_adunit',
452
472
  adUnitCode: '123/prebid_native_adunit',
453
473
  bidder: 'test_bidder',
454
474
  native: {
@@ -472,11 +492,13 @@ describe('validate native', function () {
472
492
  afterEach(function () {});
473
493
 
474
494
  it('should accept bid if no image sizes are defined', function () {
475
- let result = nativeBidIsValid(validBid, bidReq);
495
+ decorateAdUnitsWithNativeParams([adUnit]);
496
+ const index = stubAuctionIndex({adUnits: [adUnit]})
497
+ let result = nativeBidIsValid(validBid, {index});
476
498
  expect(result).to.be.true;
477
- result = nativeBidIsValid(noIconDimBid, bidReq);
499
+ result = nativeBidIsValid(noIconDimBid, {index});
478
500
  expect(result).to.be.true;
479
- result = nativeBidIsValid(noImgDimBid, bidReq);
501
+ result = nativeBidIsValid(noImgDimBid, {index});
480
502
  expect(result).to.be.true;
481
503
  });
482
504
  });
@@ -14,6 +14,7 @@ import { setSizeConfig } from 'src/sizeMapping.js';
14
14
  import find from 'core-js-pure/features/array/find.js';
15
15
  import includes from 'core-js-pure/features/array/includes.js';
16
16
  import s2sTesting from 'modules/s2sTesting.js';
17
+ import {hook} from '../../../../src/hook.js';
17
18
  var events = require('../../../../src/events');
18
19
 
19
20
  const CONFIG = {
@@ -90,6 +91,7 @@ describe('adapterManager tests', function () {
90
91
  describe('callBids', function () {
91
92
  before(function () {
92
93
  config.setConfig({s2sConfig: { enabled: false }});
94
+ hook.ready();
93
95
  });
94
96
 
95
97
  beforeEach(function () {
@@ -1668,6 +1670,26 @@ describe('adapterManager tests', function () {
1668
1670
  })
1669
1671
  });
1670
1672
 
1673
+ it('should add nativeParams to adUnits after BEFORE_REQUEST_BIDS', () => {
1674
+ function beforeReqBids(adUnits) {
1675
+ adUnits.forEach(adUnit => {
1676
+ adUnit.mediaTypes.native = {
1677
+ type: 'image',
1678
+ }
1679
+ })
1680
+ }
1681
+ events.on(CONSTANTS.EVENTS.BEFORE_REQUEST_BIDS, beforeReqBids);
1682
+ adapterManager.makeBidRequests(
1683
+ adUnits,
1684
+ Date.now(),
1685
+ utils.getUniqueIdentifierStr(),
1686
+ function callback() {},
1687
+ []
1688
+ );
1689
+ events.off(CONSTANTS.EVENTS.BEFORE_REQUEST_BIDS, beforeReqBids);
1690
+ expect(adUnits.map((u) => u.nativeParams).some(i => i == null)).to.be.false;
1691
+ });
1692
+
1671
1693
  it('should make separate bidder request objects for each bidder', () => {
1672
1694
  adUnits = [utils.deepClone(getAdUnits()[0])];
1673
1695
 
@@ -0,0 +1,129 @@
1
+ import {AuctionIndex} from '../../../../src/auctionIndex.js';
2
+
3
+ describe('auction index', () => {
4
+ let index, auctions;
5
+
6
+ function mockAuction(id, adUnits, bidderRequests) {
7
+ return {
8
+ getAuctionId() { return id },
9
+ getAdUnits() { return adUnits; },
10
+ getBidRequests() { return bidderRequests; }
11
+ }
12
+ }
13
+
14
+ beforeEach(() => {
15
+ auctions = [];
16
+ index = new AuctionIndex(() => auctions);
17
+ })
18
+
19
+ describe('getAuction', () => {
20
+ beforeEach(() => {
21
+ auctions = [mockAuction('a1'), mockAuction('a2')];
22
+ });
23
+
24
+ it('should find auctions by auctionId', () => {
25
+ expect(index.getAuction({auctionId: 'a1'})).to.equal(auctions[0]);
26
+ });
27
+
28
+ it('should return undef if auction is missing', () => {
29
+ expect(index.getAuction({auctionId: 'missing'})).to.be.undefined;
30
+ });
31
+
32
+ it('should return undef if no auctionId is provided', () => {
33
+ expect(index.getAuction({})).to.be.undefined;
34
+ });
35
+ });
36
+
37
+ describe('getAdUnit', () => {
38
+ let adUnits;
39
+
40
+ beforeEach(() => {
41
+ adUnits = [{transactionId: 'au1'}, {transactionId: 'au2'}];
42
+ auctions = [
43
+ mockAuction('a1', [adUnits[0], {}]),
44
+ mockAuction('a2', [adUnits[1]])
45
+ ];
46
+ });
47
+
48
+ it('should find adUnits by transactionId', () => {
49
+ expect(index.getAdUnit({transactionId: 'au2'})).to.equal(adUnits[1]);
50
+ });
51
+
52
+ it('should return undefined if adunit is missing', () => {
53
+ expect(index.getAdUnit({transactionId: 'missing'})).to.be.undefined;
54
+ });
55
+
56
+ it('should return undefined if no transactionId is provided', () => {
57
+ expect(index.getAdUnit({})).to.be.undefined;
58
+ });
59
+ });
60
+
61
+ describe('getBidRequest', () => {
62
+ let bidRequests;
63
+ beforeEach(() => {
64
+ bidRequests = [{bidId: 'b1'}, {bidId: 'b2'}];
65
+ auctions = [
66
+ mockAuction('a1', [], [{bids: [bidRequests[0], {}]}]),
67
+ mockAuction('a2', [], [{bids: [bidRequests[1]]}])
68
+ ]
69
+ });
70
+
71
+ it('should find bidRequests by requestId', () => {
72
+ expect(index.getBidRequest({requestId: 'b2'})).to.equal(bidRequests[1]);
73
+ });
74
+
75
+ it('should return undef if bidRequest is missing', () => {
76
+ expect(index.getBidRequest({requestId: 'missing'})).to.be.undefined;
77
+ });
78
+
79
+ it('should return undef if no requestId is provided', () => {
80
+ expect(index.getBidRequest({})).to.be.undefined;
81
+ });
82
+ });
83
+
84
+ describe('getMediaTypes', () => {
85
+ let bidderRequests, mediaTypes, adUnits;
86
+
87
+ beforeEach(() => {
88
+ mediaTypes = [{mockMT: '1'}, {mockMT: '2'}, {mockMT: '3'}, {mockMT: '4'}]
89
+ adUnits = [
90
+ {transactionId: 'au1', mediaTypes: mediaTypes[0]},
91
+ {transactionId: 'au2', mediaTypes: mediaTypes[1]}
92
+ ]
93
+ bidderRequests = [
94
+ {bidderRequestId: 'ber1', bids: [{bidId: 'b1', mediaTypes: mediaTypes[2], transactionId: 'au1'}, {}]},
95
+ {bidderRequestId: 'ber2', bids: [{bidId: 'b2', mediaTypes: mediaTypes[3], transactionId: 'au2'}]}
96
+ ]
97
+ auctions = [
98
+ mockAuction('a1', [adUnits[0]], [bidderRequests[0], {}]),
99
+ mockAuction('a2', [adUnits[1]], [bidderRequests[1]])
100
+ ]
101
+ });
102
+
103
+ it('should find mediaTypes by transactionId', () => {
104
+ expect(index.getMediaTypes({transactionId: 'au2'})).to.equal(mediaTypes[1]);
105
+ });
106
+
107
+ it('should find mediaTypes by requestId', () => {
108
+ expect(index.getMediaTypes({requestId: 'b1'})).to.equal(mediaTypes[2]);
109
+ });
110
+
111
+ it('should give precedence to request.mediaTypes over adUnit.mediaTypes', () => {
112
+ expect(index.getMediaTypes({requestId: 'b2', transactionId: 'au2'})).to.equal(mediaTypes[3]);
113
+ });
114
+
115
+ it('should return undef if requestId and transactionId do not match', () => {
116
+ expect(index.getMediaTypes({requestId: 'b1', transactionId: 'au2'})).to.be.undefined;
117
+ });
118
+
119
+ it('should return undef if no params are provided', () => {
120
+ expect(index.getMediaTypes({})).to.be.undefined;
121
+ });
122
+
123
+ ['requestId', 'transactionId'].forEach(param => {
124
+ it(`should return undef if ${param} is missing`, () => {
125
+ expect(index.getMediaTypes({[param]: 'missing'})).to.be.undefined;
126
+ });
127
+ })
128
+ });
129
+ });
@@ -8,6 +8,9 @@ import { config } from 'src/config.js';
8
8
  import { server } from 'test/mocks/xhr.js';
9
9
  import CONSTANTS from 'src/constants.json';
10
10
  import events from 'src/events.js';
11
+ import {hook} from '../../../../src/hook.js';
12
+ import {auctionManager} from '../../../../src/auctionManager.js';
13
+ import {stubAuctionIndex} from '../../../helpers/indexStub.js';
11
14
 
12
15
  const CODE = 'sampleBidder';
13
16
  const MOCK_BIDS_REQUEST = {
@@ -43,6 +46,10 @@ describe('bidders created by newBidder', function () {
43
46
  let addBidResponseStub;
44
47
  let doneStub;
45
48
 
49
+ before(() => {
50
+ hook.ready();
51
+ });
52
+
46
53
  beforeEach(function () {
47
54
  spec = {
48
55
  code: CODE,
@@ -59,17 +66,22 @@ describe('bidders created by newBidder', function () {
59
66
  describe('when the ajax response is irrelevant', function () {
60
67
  let ajaxStub;
61
68
  let getConfigSpy;
69
+ let aliasRegistryStub, aliasRegistry;
62
70
 
63
71
  beforeEach(function () {
64
72
  ajaxStub = sinon.stub(ajax, 'ajax');
65
73
  addBidResponseStub.reset();
66
74
  getConfigSpy = sinon.spy(config, 'getConfig');
67
75
  doneStub.reset();
76
+ aliasRegistry = {};
77
+ aliasRegistryStub = sinon.stub(adapterManager, 'aliasRegistry');
78
+ aliasRegistryStub.get(() => aliasRegistry);
68
79
  });
69
80
 
70
81
  afterEach(function () {
71
82
  ajaxStub.restore();
72
83
  getConfigSpy.restore();
84
+ aliasRegistryStub.restore();
73
85
  });
74
86
 
75
87
  it('should let registerSyncs run with invalid alias and aliasSync enabled', function () {
@@ -116,6 +128,7 @@ describe('bidders created by newBidder', function () {
116
128
  });
117
129
  spec.code = 'aliasBidder';
118
130
  const bidder = newBidder(spec);
131
+ aliasRegistry = {[spec.code]: CODE};
119
132
  bidder.callBids({ bids: [] }, addBidResponseStub, doneStub, ajaxStub, onTimelyResponseStub, wrappedCallback);
120
133
  expect(getConfigSpy.withArgs('userSync.filterSettings').calledOnce).to.equal(false);
121
134
  });
@@ -548,6 +561,30 @@ describe('bidders created by newBidder', function () {
548
561
 
549
562
  expect(logErrorSpy.calledOnce).to.equal(true);
550
563
  });
564
+
565
+ it('should require requestId from interpretResponse', () => {
566
+ const bidder = newBidder(spec);
567
+ const bid = {
568
+ 'ad': 'creative',
569
+ 'cpm': '1.99',
570
+ 'creativeId': 'some-id',
571
+ 'currency': 'USD',
572
+ 'netRevenue': true,
573
+ 'ttl': 360
574
+ };
575
+ spec.isBidRequestValid.returns(true);
576
+ spec.buildRequests.returns({
577
+ method: 'POST',
578
+ url: 'test.url.com',
579
+ data: {}
580
+ });
581
+ spec.getUserSyncs.returns([]);
582
+ spec.interpretResponse.returns(bid);
583
+
584
+ bidder.callBids(MOCK_BIDS_REQUEST, addBidResponseStub, doneStub, ajaxStub, onTimelyResponseStub, wrappedCallback);
585
+
586
+ expect(addBidResponseStub.called).to.be.false;
587
+ });
551
588
  });
552
589
 
553
590
  describe('when the ajax call fails', function () {
@@ -783,7 +820,7 @@ describe('registerBidder', function () {
783
820
 
784
821
  describe('validate bid response: ', function () {
785
822
  let spec;
786
- let bidder;
823
+ let indexStub, adUnits, bidderRequests;
787
824
  let addBidResponseStub;
788
825
  let doneStub;
789
826
  let ajaxStub;
@@ -824,25 +861,34 @@ describe('validate bid response: ', function () {
824
861
  callbacks.success('response body', { getResponseHeader: fakeResponse });
825
862
  });
826
863
  logErrorSpy = sinon.spy(utils, 'logError');
864
+ indexStub = sinon.stub(auctionManager, 'index');
865
+ adUnits = [];
866
+ bidderRequests = [];
867
+ indexStub.get(() => stubAuctionIndex({adUnits: adUnits, bidderRequests: bidderRequests}))
827
868
  });
828
869
 
829
870
  afterEach(function () {
830
871
  ajaxStub.restore();
831
872
  logErrorSpy.restore();
873
+ indexStub.restore;
832
874
  });
833
875
 
834
876
  it('should add native bids that do have required assets', function () {
877
+ adUnits = [{
878
+ transactionId: 'au',
879
+ nativeParams: {
880
+ title: {'required': true},
881
+ }
882
+ }]
835
883
  let bidRequest = {
836
884
  bids: [{
837
885
  bidId: '1',
838
886
  auctionId: 'first-bid-id',
839
887
  adUnitCode: 'mock/placement',
888
+ transactionId: 'au',
840
889
  params: {
841
890
  param: 5
842
891
  },
843
- nativeParams: {
844
- title: {'required': true},
845
- },
846
892
  mediaType: 'native',
847
893
  }]
848
894
  };
@@ -869,21 +915,24 @@ describe('validate bid response: ', function () {
869
915
  });
870
916
 
871
917
  it('should not add native bids that do not have required assets', function () {
918
+ adUnits = [{
919
+ transactionId: 'au',
920
+ nativeParams: {
921
+ title: {'required': true},
922
+ },
923
+ }];
872
924
  let bidRequest = {
873
925
  bids: [{
874
926
  bidId: '1',
875
927
  auctionId: 'first-bid-id',
876
928
  adUnitCode: 'mock/placement',
929
+ transactionId: 'au',
877
930
  params: {
878
931
  param: 5
879
932
  },
880
- nativeParams: {
881
- title: {'required': true},
882
- },
883
933
  mediaType: 'native',
884
934
  }]
885
935
  };
886
-
887
936
  let bids1 = Object.assign({},
888
937
  bids[0],
889
938
  {
@@ -905,17 +954,21 @@ describe('validate bid response: ', function () {
905
954
  });
906
955
 
907
956
  it('should add bid when renderer is present on outstream bids', function () {
957
+ adUnits = [{
958
+ transactionId: 'au',
959
+ mediaTypes: {
960
+ video: {context: 'outstream'}
961
+ }
962
+ }]
908
963
  let bidRequest = {
909
964
  bids: [{
910
965
  bidId: '1',
911
966
  auctionId: 'first-bid-id',
967
+ transactionId: 'au',
912
968
  adUnitCode: 'mock/placement',
913
969
  params: {
914
970
  param: 5
915
971
  },
916
- mediaTypes: {
917
- video: {context: 'outstream'}
918
- }
919
972
  }]
920
973
  };
921
974
 
@@ -951,7 +1004,7 @@ describe('validate bid response: ', function () {
951
1004
  sizes: [[300, 250]],
952
1005
  }]
953
1006
  };
954
-
1007
+ bidderRequests = [bidRequest];
955
1008
  let bids1 = Object.assign({},
956
1009
  bids[0],
957
1010
  {